Support » Plugin: Custom Post Type UI » Want to manage the Custom taxonomy Capabilities

  • Resolved lalitavalon

    (@lalitavalon)


    Hi,
    I made the taxonomies fromm that plugin to acustom post type.
    I want to manage the capabilities for creating the terms in that taxonomy that only admin will allow the creating the terms. Not all users.
    As i can saw on codex for register taxonomy we can pass capilities array. But in the plugin i am not able to see how can we manage and pass these capabilties.

    Please help me it is very urgent.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Michael Beckwith

    (@tw2113)

    Hopefully you’re familiar with filters.

    We have the following available that’s used for each taxonomy being registered:

    https://github.com/WebDevStudios/custom-post-type-ui/blob/1.5.6/custom-post-type-ui.php#L592-L604

    You’ll be passed an array of arguments that will be used to register each taxonomy, and you can override the values provided by the UI, as well as add spots that we’re lacking, like capability details. You will want to make sure to map it the exact same way that the Codex outlines.

    Thanks for the reply,
    But I am not able to undersatnd how we wiil use it.
    And how passit in the custom taxony because now i am using create taxonmy by code that you provide in the backend and add manully cap arrry for this taxony a

    Plugin Author Michael Beckwith

    (@tw2113)

    Just as an example of how you would be able to use the filter I pointed out earlier:

    function lalitavalon_customize_taxonomy( $args, $taxonomy_slug ) {
    	// These would already be used as default value, but providing as an example.
    	// $taxonomy_slug parameter would be the slug of the taxonomy currently being registered.
    	$args['capabilities'] = array(
    		'manage_terms' => 'manage_actor',
    		'edit_terms'   => 'manage_actor',
    		'delete_terms' => 'manage_actor',
    		'assign_terms' => 'edit_posts',
    	);
    
    	return $args;
    }
    add_filter( 'cptui_pre_register_taxonomy', 'lalitavalon_customize_taxonomy', 10, 2 );
    

    Thanks for the reply.

    i add this code it is working but there was a issue suppose i have two more than two taxnomy so it only taskes the caps for all filter code and apply all caps for alll taxonomy.
    How we will add a code for two or more tax

    Plugin Author Michael Beckwith

    (@tw2113)

    You can use the taxonomy slug for that. Repeat this one as necessary:

    function lalitavalon_customize_taxonomy( $args, $taxonomy_slug ) {
    	
    	if ( 'actor' === $taxonomy_slug ) {
    		$args['capabilities'] = array(
    			'manage_terms' => 'manage_actor',
    			'edit_terms'   => 'manage_actor',
    			'delete_terms' => 'manage_actor',
    			'assign_terms' => 'edit_posts',
    		);
    	}
    
    	if ( 'genre' === $taxonomy_slug ) {
    		$args['capabilities'] = array(
    			'manage_terms' => 'manage_genre',
    			'edit_terms'   => 'manage_genre',
    			'delete_terms' => 'manage_genre',
    			'assign_terms' => 'edit_posts',
    		);
    	}
    
    	return $args;
    }
    add_filter( 'cptui_pre_register_taxonomy', 'lalitavalon_customize_taxonomy', 10, 2 );
    

    Thanks it is working fine.

    famarast

    (@famarast)

    Good morning,
    I can not understand how to apply this code to my taxonomy, where should I enter the code? In the functions.php of my child theme?

    My taxonomy is called prodotti_costanti and is associated with two Custom post type, nuovi_prodotti and prodotti_usati.

    How can I do? I tried them all 🙁

    Thank you very much for the support

    • This reply was modified 4 months ago by  famarast.
    Plugin Author Michael Beckwith

    (@tw2113)

    Yes, functions.php file would be one place to add the code samples to.

    Unless I’m mistaken, something like this should work:

    function lalitavalon_customize_taxonomy( $args, $taxonomy_slug ) {
    	
    	if ( 'prodotti_costanti' === $taxonomy_slug ) {
    		$args['capabilities'] = array(
    			'manage_terms' => 'manage_prodotti_costanti',
    			'edit_terms'   => 'manage_prodotti_costanti',
    			'delete_terms' => 'manage_prodotti_costanti',
    			'assign_terms' => 'edit_posts',
    		);
    	}
    
    	return $args;
    }
    add_filter( 'cptui_pre_register_taxonomy', 'lalitavalon_customize_taxonomy', 10, 2 );
    

    I failed to point out that the “actor” in the “manage_” lines was just an example and would need to be changed based on the taxonomy slug being acted on.

Viewing 8 replies - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.