No authors in change author dropdown

I have added a custom post type “Review”, and a custom role “Reviewer”. The issue is when logged as admin I take review which current author is admin and I want to change author to a Reviewer I have no options in dropdown besides admin. When I change a post whose author is a Reviewer, I have 2 options in dropdown: the current author and admin. Other Reviewers are not visible.

here is a part with capabilities

'capabilities' => array(
    'edit_post' => 'edit_review',
    'edit_others_posts' => 'edit_others_reviews',
    'publish_posts' => 'publish_reviews',
    'read_post' => 'read_swpd_review',
    'read_private_posts' => 'read_private_reviews',
    'delete_post' => 'delete_swpd_review'
),

and setting new role

/* Add guest author role to the blog */
add_role('reviewer', 'Reviewer', array('edit_review','read_review','delete_review'));

//add capabilities for admin
$role_object = get_role( 'administrator' );
$role_object->add_cap( 'read_review' );
$role_object->add_cap( 'edit_review' );
$role_object->add_cap( 'delete_review' );
$role_object->add_cap( 'publish_reviews' );
$role_object->add_cap( 'edit_others_reviews' );
//set level for reviewer (should fix a dropdown bug)
$role_object = get_role( 'reviewer' );
$role_object->add_cap('level_1');

Is it a matter of capabilities? What could be wrong?

1 Answer
1

The role “Reviewer” only has special capabilities, no other capabilities. To get into the author list you have to be at least a contributor or author.

function rb_addroles() {
    $role = get_role('contributor');
    remove_role( 'reviewer' );
    add_role( 'reviewer', 'Reviewer', $role->capabilities );

    $reviewer = get_role('reviewer');

    $reviewer->add_cap( 'edit_review' );
    $reviewer->add_cap( 'read_review' );
    $reviewer->add_cap( 'delete_review' );
}  
add_action( 'admin_init', 'rb_addroles' );

With this function a reviewer has contributor capabilities plus your special reviewer capabilities. You can change contributor in author to give them also editable powers in the back-end.

Btw you have to run the script only once, preferable in a plugin or functions.php with logged in admin account.

You can check the role by:

$reviewer = get_role('reviewer');
print_r($reviewer);

Leave a Comment