• Resolved gerdw

    (@gerdw)


    Hi Community,

    i am relatively new to WP, and on my first project i have the following need:

    I have created a custom content (lets say “cevent”) type and a custom taxonomie (lets say “ceventfeature”) with CPT UI.

    A custom Role (lets say “ceventeditors”) should be able to create content of the type “cevent”.

    This works well with the exception, that ceventeditors can not assign Taxonomy Terms to the cevent they have created. Only if i also assign the right to edit standard posts to ceventeditors they can do so.

    I have googled a bit, and it seems to me, that adding

    “map_meta_cap” => true
    and perhaps
    “capability_type” => “ceventfeature”

    to the creation section of the taxonomy in functions.php might help, but as i understand i can only do either: Using CPT UI _OR_ do the creation manually.

    Can someone point me in the right direction?
    Yours,Gerd

    • This topic was modified 3 years, 1 month ago by Yui.
    • This topic was modified 3 years, 1 month ago by gerdw.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Hello,

    If you’re wanting/needing to amend the arguments for post types and taxonomies registered with CPTUI, but don’t want to ditch using our plugin completely, then the two following WordPress filters are going to be your friend.

    From what I’m reading above, especially around roles/capabilities editing, it sounds like you’re going to want to make use of either or both of these two. We know full well that roles/capabilities isn’t something we have well covered in the plugin’s UI version, but hope we can still have happy users by way of the filters below.

    The filters get passed the current arguments to be used for a given content type, as well as the name/slug for the current content type being registered for conditional editing usage, as well as a detail or two more. The arguments for each is going to be in the same structure as you’d see in the developer documentation from WordPress.

    Post Types:
    https://github.com/WebDevStudios/custom-post-type-ui/blob/1.10.2/custom-post-type-ui.php#L524-L534

    Taxonomies:
    https://github.com/WebDevStudios/custom-post-type-ui/blob/1.10.2/custom-post-type-ui.php#L754-L766

    Let us know if you need some help with making use of the filters, and we can type up a quick example or two.

    Thread Starter gerdw

    (@gerdw)

    Hi Michael !

    Thanks for your quick reply. It seems to me that that is an elegant solution, but as i am not a developer, i would be very happy if you can give me some extra hints.

    I have understood, that you have registred a hook that is able to modify the arguments before registering (which is exactly what i want).

    From the WordPress Doku i learnt that there is a function apply_filters.
    From the Code your mentioned i learned that in cpt ui your call apply_filters.

    Where do the add_filters take place or do i have to do that in main functions.php ?

    Inside the filte think i have to do the logic (this not yet php, but my personal pseudocode;-):

    if tax name is ceventfeatures, then
    get the args from function input
    add my lines at apropriat place
    return args
    fi

    Or could you give me an example how to insert an argument before tax registration?

    Thanks in Advance and Thanks for your great plugin.

    Gerd

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Where do the add_filters take place or do i have to do that in main functions.php ?

    Yes your active theme’s functions.php would be one place to save the add_action(...) + callback function. You could also create your own quick plugin if you don’t want to tie this directly to your current theme.

    Something like this would do you pretty well, I believe:

    function cptuisupport_override_ceventfeature( $args, $tax_slug, $orig_args ) {
    	// We only want to affect these for one taxonomy, so return early if its not that one
    	if ( 'ceventfeature' !== $tax_slug ) {
    		return $args;
    	}
    
    	// Add in our capabilities setting
    	$args['capabilities'] = [
    		'manage_terms' => 'manage_' . $tax_slug,
    		'edit_terms'   => 'edit_' . $tax_slug,
    		'delete_terms' => 'delete' . $tax_slug,
    		'assign_terms' => 'assign_' . $tax_slug,
    	];
        
    	return $args;
    }
    add_action( 'cptui_pre_register_taxonomy', 'cptuisupport_override_ceventfeature', 10, 3 );
    
    Thread Starter gerdw

    (@gerdw)

    That works like charm ??

    And on top: learned a lot.

    Thank you very much.

    Gerd

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Welcome

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Grant right to custom taxonomie, map_meta_cap’ is closed to new replies.