• 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 Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    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.

    Thread Starter lalitavalon

    (@lalitavalon)

    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 Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    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 );
    
    Thread Starter lalitavalon

    (@lalitavalon)

    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 Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    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 );
    
    Thread Starter lalitavalon

    (@lalitavalon)

    Thanks it is working fine.

    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 7 years, 2 months ago by famarast.
    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    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)
  • The topic ‘Want to manage the Custom taxonomy Capabilities’ is closed to new replies.