Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Tweeted twitter.com/StackWordPress/status/741106905586749440
Added database content
Source Link
Chris Morris
  • 928
  • 1
  • 9
  • 18

Edit Here you can see a dump of the blog_manager capabilities from the database, there is a fair bit of testing BS left in there, bu/t that shouldn't stop them being able to login from what I know.

'blog_manager' => array (
    'name' => 'Blog Manager',
    'capabilities' => array (
        'read' => true,
        'edit_posts' => false,
        'delete_posts' => false,
        'publish_posts' => false,
        'upload_files' => true,
        'read_blog' => true,
        'read_private_blog' => true,
        'edit_blog' => true,
        'edit_others_blog' => true,
        'edit_published_blog' => true,
        'publish_blog' => true,
        'delete_others_blog' => true,
        'delete_private_blog' => true,
        'delete_published_blog' => true,
        'blog' => true,
        'read_private_blogs' => true,
        'edit_blogs' => true,
        'edit_others_blogs' => true,
        'edit_published_blogs' => true,
        'publish_blogs' => true,
        'delete_others_blogs' => true,
        'delete_private_blogs' => true,
        'delete_published_blogs' => true,
        'delete_blogs' => true,
        'delete_blog' => true,
    ),
)

Edit Here you can see a dump of the blog_manager capabilities from the database, there is a fair bit of testing BS left in there, bu/t that shouldn't stop them being able to login from what I know.

'blog_manager' => array (
    'name' => 'Blog Manager',
    'capabilities' => array (
        'read' => true,
        'edit_posts' => false,
        'delete_posts' => false,
        'publish_posts' => false,
        'upload_files' => true,
        'read_blog' => true,
        'read_private_blog' => true,
        'edit_blog' => true,
        'edit_others_blog' => true,
        'edit_published_blog' => true,
        'publish_blog' => true,
        'delete_others_blog' => true,
        'delete_private_blog' => true,
        'delete_published_blog' => true,
        'blog' => true,
        'read_private_blogs' => true,
        'edit_blogs' => true,
        'edit_others_blogs' => true,
        'edit_published_blogs' => true,
        'publish_blogs' => true,
        'delete_others_blogs' => true,
        'delete_private_blogs' => true,
        'delete_published_blogs' => true,
        'delete_blogs' => true,
        'delete_blog' => true,
    ),
)
Source Link
Chris Morris
  • 928
  • 1
  • 9
  • 18

Allowing custom role access to custom post type in back end

So I'm having some issues with this and I can't see why. I just need a custom role that can access the blog in the back end.

I've added a new post type with a Capability type of blog and a new user role with all the caps fr it that would allow admin access users to add/edit the custom post type. This works for admins and they can access the post type in the back end. However users of my custom role can not get into the back end at all.

Post type args of note

"capability_type" => 'blog',
"map_meta_cap" => true,

Register role

function add_blog_manager_role(){
    add_role(
        'blog_manager',
        'Blog Manager',
        array(
            'read' => true,
            'edit_posts' => false,
            'delete_posts' => false,
            'publish_posts' => false,
            'upload_files' => true
        )
    );
}
add_action( 'admin_init', 'add_blog_manager_role', 4 );

Add Caps

function add_blog_role_caps() {
    $roles = array('blog_manager', 'editor','administrator');
    foreach($roles as $the_role) {
        $role = get_role($the_role);
        $role->add_cap( 'read' );
        $role->add_cap( 'read_blog');
        $role->add_cap( 'read_private_blog' );
        $role->add_cap( 'edit_blog' );
        $role->add_cap( 'edit_others_blog' );
        $role->add_cap( 'edit_published_blog' );
        $role->add_cap( 'publish_blog' );
        $role->add_cap( 'delete_others_blog' );
        $role->add_cap( 'delete_private_blog' );
        $role->add_cap( 'delete_published_blog' );
    }
}
add_action('admin_init', 'add_blog_role_caps', 5 );

I've been googeling frantically trying to find the cause of this. I've tried with plural, non plural caps, tried adding capabilities into the post type args. However I'm never able to get into the back end. I've not got any other code in the theme that might kick users out of the admin (I removed my own code that kicked them out while testing this)