Title: CTP capability error
Last modified: August 21, 2016

---

# CTP capability error

 *  [otta88sun](https://wordpress.org/support/users/otta88sun/)
 * (@otta88sun)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/ctp-capability-error/)
 * Hi, i added custom capability with in function.php after have created with plugin
   Types a CTP called annuncio `function add_theme_caps() {
    // gets the author 
   role $role = get_role( ‘cittadino’ ); $role2 = get_role( ‘contributor’ ); $role3
   = get_role( ‘author’ );
 *  // This only works, because it accesses the class instance.
    // would allow 
   the author to edit others’ posts for current theme only $role->add_cap( ‘delete_published_annunci’);
   $role2->add_cap( ‘delete_published_annunci’ ); $role3->add_cap( ‘delete_published_annunci’);}
   add_action( ‘admin_init’, ‘add_theme_caps’);`
 * But the author seems not can delete published post? Why?
 * [http://wordpress.org/plugins/types/](http://wordpress.org/plugins/types/)

Viewing 9 replies - 1 through 9 (of 9 total)

 *  [agnes.b](https://wordpress.org/support/users/agnesb-1/)
 * (@agnesb-1)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/ctp-capability-error/#post-4382925)
 * Hi otta88sun,
    this is Agnes from Toolset support team.
 * Authors should not be able to delete other’s posts. Editor role can do that. 
   Authors however can delete the posts they created themselves.
 * Custom posts created with Types behave exactly the same here as standard WP posts.
 * If you are satisfied with my answer, please mark this post as “resolved”. Do 
   let us know what you think in the Reviews section.
 *  Thread Starter [otta88sun](https://wordpress.org/support/users/otta88sun/)
 * (@otta88sun)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/ctp-capability-error/#post-4382945)
 * Maybe my question was not clear 🙂
 * I created with Types a CTP, its slug is “Annuncio”.
 * Now, i want that some roles likes (cittadino, contributor and author) can delete
   only their own published post of this CTP.
 * $role->add_cap( ‘delete_published_annunci’ );
 * This code should give to a role the capability of delete published CTP annunci(
   only their own). But doesn’t work, so i don’t know what’s the error seen that
   the slug annunci is correct.
 *  [agnes.b](https://wordpress.org/support/users/agnesb-1/)
 * (@agnesb-1)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/ctp-capability-error/#post-4383037)
 * Hi again.
    Now it’s clear. You want to add some custom roles/capabilities to 
   manage your custom Annuncio posts.
 * You can achieve this in two ways:
    1. with php programming using ‘capability_type’
   => array(‘annunci’, ‘annuncies) and ‘map_meta_cap’ => true when registering your
   custom post type. Without these two parameters the code you tried won’t work.
 * 2. with our Access plugin, with no programming, just clicking:
    [http://wp-types.com/documentation/user-guides/setting-access-control/](http://wp-types.com/documentation/user-guides/setting-access-control/)
   [http://wp-types.com/documentation/user-guides/custom-roles-access-privileges/](http://wp-types.com/documentation/user-guides/custom-roles-access-privileges/)
 * If you choose option one and you’ve already have your custom post defined you
   will have to add a filter:
 *     ```
       add_filter( 'wpcf_type', 'custom_func', 10, 2 );
       function custom_func ( $data, $post_type ) {
       	$data['capability_type'] = array('annunci', 'annuncies');
       	$data['map_meta_cap'] = true;
       	return $data;
       }
       ```
   
 *  Thread Starter [otta88sun](https://wordpress.org/support/users/otta88sun/)
 * (@otta88sun)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/ctp-capability-error/#post-4383043)
 * Thanks for help, but it doesn’t work. I’ll buy Access.. 🙁
 *  [agnes.b](https://wordpress.org/support/users/agnesb-1/)
 * (@agnesb-1)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/ctp-capability-error/#post-4383044)
 * I missed annunci condition, once again:
 *     ```
       add_filter('wpcf_type', 'custom_func', 10, 2);
       function custom_func($data, $post_type) {
        if ($post_type == 'annunci') {//Post type slug as entered on Types setting page
         $data['capability_type'] = array('annunci', 'annuncies');
         $data['map_meta_cap'] = true;
        }
        return $data;
       }
       ```
   
 * Important: add filter before ‘init’ hook.
 *  [agnes.b](https://wordpress.org/support/users/agnesb-1/)
 * (@agnesb-1)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/ctp-capability-error/#post-4383045)
 * And please remember to adds capabilities after filtering. First filtering, than
   adding capabilities. The code should work now.
 * But Access is more friendly, try it out.
 *  Thread Starter [otta88sun](https://wordpress.org/support/users/otta88sun/)
 * (@otta88sun)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/ctp-capability-error/#post-4383047)
 * Thanks for code and your help, it became
 *     ```
       add_filter('wpcf_type', 'custom_func', 10, 2);
       function custom_func($data, $post_type) {
       	 if ($post_type == 'annuncio') {//Post type slug as entered on Types setting page
       	  $data['capability_type'] = array('annuncio', 'annuncios');
       	  $data['map_meta_cap'] = true;
       	 }
       	 return $data;
       }
   
       function add_theme_caps() {
       	// gets the author role
       	$roles[0] = get_role( 'cittadino' );
       	$roles[1] = get_role( 'contributor' );
       	$roles[2] = get_role( 'author' );
       	$roles[3] = get_role( 'editor' );
       	$roles[4] = get_role( 'administrator' );
   
       	// This only works, because it accesses the class instance.
       	// would allow the author to edit others' posts for current theme only
   
       	foreach($roles as $role){
       		$role->add_cap( 'delete_published_annuncios' );
       		$role->add_cap( 'edit_annuncio' );
       		$role->add_cap( 'edit_annuncios' );
       		$role->add_cap( 'read_annuncio' );
       		$role->add_cap( 'delete_annuncio' );
       	}
       }
       add_action( 'admin_init', 'add_theme_caps');
       ```
   
 * But it doesn’t work. I means the annuncio menu doesn’t appear for that users.
 * Am I wrong in something?
 *  [agnes.b](https://wordpress.org/support/users/agnesb-1/)
 * (@agnesb-1)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/ctp-capability-error/#post-4383050)
 * Dear otta88sun, this is not so easy to manage. That’s why we have Access plugin.
   Capabilities are in relations, so to have what you need it requires more testing.
 * I showed you how to enable mapping. Now you ask to me to help you to manage capabilities.
   Each capability is attached to set of capabilities.
 * Please try out the Access plugin. You can do it for free on our learning platform:
   [http://discover-wp.com/site-templates/](http://discover-wp.com/site-templates/)
   
   Access is used for example at Classifieds Site.
 *  Thread Starter [otta88sun](https://wordpress.org/support/users/otta88sun/)
 * (@otta88sun)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/ctp-capability-error/#post-4383056)
 * Sure, i think Access will do great job. I’ll use it. Thanks 😉

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘CTP capability error’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/types_ced1d3.svg)
 * [Toolset Types - Custom Post Types, Custom Fields and Taxonomies](https://wordpress.org/plugins/types/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/types/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/types/)
 * [Active Topics](https://wordpress.org/support/plugin/types/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/types/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/types/reviews/)

## Tags

 * [CTP](https://wordpress.org/support/topic-tag/ctp/)
 * [slug](https://wordpress.org/support/topic-tag/slug/)

 * 9 replies
 * 2 participants
 * Last reply from: [otta88sun](https://wordpress.org/support/users/otta88sun/)
 * Last activity: [12 years, 5 months ago](https://wordpress.org/support/topic/ctp-capability-error/#post-4383056)
 * Status: not resolved