0

I have created a custom post type 'book'. All book post-type are public, so I want to remove some capabilities such as 'delete_private_books', 'read_private_books' etc. How can I achieve this since when I activate member plugin it show all default capabilities including the above mentioned which has nothing to do with my custom post type.

I have registered my post type book and added capabilities to it.

$labels = array(
  'name'               => _x( 'Books', 'post type general name' ),
  'singular_name'      => _x( 'Book', 'post type singular name' ),
  'menu_name'          => _x( 'Book', 'admin menu' ),
  'name_admin_bar'     => _x( 'Book', 'add new on admin bar' ),
  'add_new'            => _x( 'Add New', 'Book' ),
  'add_new_item'       => __( 'Add New Book' ),
  'new_item'           => __( 'New Books' ),
  'edit_item'          => __( 'Edit Books' ),
  'view_item'          => __( 'View Books' ),
  'all_items'          => __( 'Books' ),
  'search_items'       => __( 'Search Books' ),
  'parent_item_colon'  => __( 'Parent text:' ),
  'not_found'          => __( 'No Books found.' ),
  'not_found_in_trash' => __( 'No Books found in Trash.' )
);

$capabilities = array(
  'edit_post'              => 'edit_books',
  'read_post'              => 'read_books',
  'delete_post'            => 'delete_books',
  'edit_posts'             => 'edit_books',
  'edit_others_posts'      => 'edit_others_books',
  'publish_posts'          => 'publish_books',
  'read_private_posts'     => 'read_private_books',
  'create_posts'           => 'edit_books',
  'delete_posts'           => 'delete_books',
  'delete_private_posts'   => 'delete_private_books',
  'delete_published_posts' => 'delete_published_books',
  'delete_others_posts'    => 'delete_others_books',
  'edit_private_posts'     => 'edit_private_books',
  'edit_published_posts'   => 'edit_published_books',
);
$args = array(
  'labels'             => $labels,
  'public'             => true,
  'publicly_queryable' => true,
  'show_ui'            => true,
  'show_in_menu'       => false,
  'query_var'          => true,
  'rewrite'            => array('slug' => 'books'),
  'capability_type'    => 'books',
  'has_archive'        => true,
  'hierarchical'       => false,
  'menu_position'      => '',
  'supports'           => false,
  'map_meta_cap'       => null,
  'capabilities'       => $capabilities,
);

register_post_type( 'wp-type-books', $args );
0

Why are you setting up those custom capabilities then? You're registering your CPT with custom capabilities, and the first thing I noticed is you still have capability_type set

'capability_type'    => 'books',

if anything that should be omitted from the array or at least an empty string if you plan on using custom capabilities (this would only be used as fallback if capabilities is not set)

'capability_type' => '',

Regarding custom capabilities ... make sure you have your members plugin setup correctly. When using custom capabilities you will need to add those to specific user roles in order for them to be supported ... so you saying that the members plugin automatically does that, says that either you have it configured incorrectly, or are not understanding how capabilities and user roles work

I strongly recommend you read, and then re-read, the documentation on custom post types, and capabilities:

https://codex.wordpress.org/Function_Reference/register_post_type#capabilities

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.