Custom Post Type and User Role
-
I’m working on a plugin that creates a custom post type and an associated user role.
The cpt does not have a public facing side.
Also only want to show the CPTs to the publisher and administrator.
So basically what I have so far in it’s current state:
However with this configuration merchants are able to see others posts and the administrator can not see the cpt.
$post_type = register_post_type('credit_app', array( 'labels' => array( 'name' => __( 'Credit Application', $this->plugin_name ), 'singular_name' => __( 'Credit Application', $this->plugin_name ), 'menu_name' => __( 'Credit Applications', $this->plugin_name ), 'name_admin_bar' => __( 'Credit Applications', $this->plugin_name ), 'add_new' => __( 'Credit Application', $this->plugin_name ), 'add_new_item' => __( 'Credit Application', $this->plugin_name ), 'new_item' => __( 'Credit Application', $this->plugin_name ), 'not_found' => __( 'Application Not Found', $this->plugin_name ), 'all_items' => __( 'All Credit Applications', $this->plugin_name ), ), 'exclude_from_search' => true, 'publicly_queryable' => false, 'show_ui' => true, 'show_in_menu' => true, 'show_in_nav_menus' => false, 'has_archive' => false, 'supports' => array( 'title', 'editor', 'author', 'custom-fields' ), 'rewrite' => false, 'capability_type' => 'credit_app', 'map_meta_cap' => true ) );
$result = add_role('ebf_merchant', __('Merchant'), array( 'read' => true, 'credit_app' => true, 'edit_credit_apps' => true, 'publish_credit_apps' => true ) ); $admin_role = get_role( 'administrator' ); $admin_role->add_cap( 'credit_app' ); $admin_role->add_cap( 'edit_others_credit_apps' );
Also receiving some notices and warnings:
[16-Mar-2018 13:55:53 UTC] PHP Notice: Trying to get property 'capability_type' of non-object in //wp-includes/post.php on line 1261 [16-Mar-2018 13:55:53 UTC] PHP Notice: Trying to get property 'capability_type' of non-object in //wp-includes/post.php on line 1262 [16-Mar-2018 13:55:53 UTC] PHP Notice: Trying to get property 'capability_type' of non-object in //wp-includes/post.php on line 1262 [16-Mar-2018 13:55:53 UTC] PHP Warning: Attempt to assign property 'capability_type' of non-object in //wp-includes/post.php on line 1262 [16-Mar-2018 13:55:53 UTC] PHP Notice: Trying to get property 'capability_type' of non-object in //wp-includes/post.php on line 1265 [16-Mar-2018 13:55:53 UTC] PHP Notice: //wp-includes/post.php on line 1280 [16-Mar-2018 13:55:53 UTC] PHP Notice: Trying to get property 'capabilities' of non-object in //wp-includes/post.php on line 1293 [16-Mar-2018 13:55:53 UTC] PHP Warning: array_merge(): Argument #2 is not an array in //wp-includes/post.php on line 1293 [16-Mar-2018 13:55:53 UTC] PHP Notice: Trying to get property 'map_meta_cap' of non-object in //wp-includes/post.php on line 1300
Viewing 8 replies - 1 through 8 (of 8 total)
Viewing 8 replies - 1 through 8 (of 8 total)
- The topic ‘Custom Post Type and User Role’ is closed to new replies.