I need to be able to allow Administrators to choose a different author for a post they create or edit in admin.
I've added the post author capability, and the select field displays on the edit screen, but the only options given are the Admin and the current post author, if it is already set.
The other users have the organization_administrator role.
Here is my post_type setup:
$post_type = register_extended_post_type('organization_event', [
'supports' => ['title', 'author'],
'public' => true,
'publicly_queryable' => true,
'show_in_admin_bar' => true,
'show_in_menu' => true,
'menu_icon' => 'dashicons-calendar-alt',
'has_archive' => true,
'capabilities' => array(
'edit_post' => 'edit_organization_event',
'edit_posts' => 'edit_organization_events',
'edit_others_posts' => 'edit_other_organization_events',
'publish_posts' => 'publish_organization_events',
'read_post' => 'read_organization_event',
'read_private_posts' => 'read_private_organization_events',
'delete_post' => 'delete_organization_event'
),
'map_meta_cap' => true,
]);
$admins = get_role('administrator');
$admins->add_cap('edit_organization_event');
$admins->add_cap('edit_organization_events');
$admins->add_cap('edit_other_organization_events');
$admins->add_cap('publish_organization_events');
$admins->add_cap('read_organization_event');
$admins->add_cap('read_private_organization_events');
$admins->add_cap('delete_organization_event');
And the organization_administrator role
add_role('organization_administrator', __('Organization Administrator', 'sage'), [
'edit_organization' => true,
'edit_organizations' => true,
'edit_organization_event' => true,
'edit_organization_events' => true,
]);
Thanks for any help you can provide.
I need to be able to allow Administrators to choose a different author for a post they create or edit in admin.
I've added the post author capability, and the select field displays on the edit screen, but the only options given are the Admin and the current post author, if it is already set.
The other users have the organization_administrator role.
Here is my post_type setup:
$post_type = register_extended_post_type('organization_event', [
'supports' => ['title', 'author'],
'public' => true,
'publicly_queryable' => true,
'show_in_admin_bar' => true,
'show_in_menu' => true,
'menu_icon' => 'dashicons-calendar-alt',
'has_archive' => true,
'capabilities' => array(
'edit_post' => 'edit_organization_event',
'edit_posts' => 'edit_organization_events',
'edit_others_posts' => 'edit_other_organization_events',
'publish_posts' => 'publish_organization_events',
'read_post' => 'read_organization_event',
'read_private_posts' => 'read_private_organization_events',
'delete_post' => 'delete_organization_event'
),
'map_meta_cap' => true,
]);
$admins = get_role('administrator');
$admins->add_cap('edit_organization_event');
$admins->add_cap('edit_organization_events');
$admins->add_cap('edit_other_organization_events');
$admins->add_cap('publish_organization_events');
$admins->add_cap('read_organization_event');
$admins->add_cap('read_private_organization_events');
$admins->add_cap('delete_organization_event');
And the organization_administrator role
add_role('organization_administrator', __('Organization Administrator', 'sage'), [
'edit_organization' => true,
'edit_organizations' => true,
'edit_organization_event' => true,
'edit_organization_events' => true,
]);
Thanks for any help you can provide.
Share Improve this question asked Oct 13, 2019 at 15:35 christianchristian 1791 silver badge7 bronze badges1 Answer
Reset to default 1All users with author and contributor roles - actualy any in-built role above subscriber - should be available from the author dropdown. However, if you want organization_administrator
users to be available also, you will need to assign those users a contibrutor or author role as well (anything more than subscriber.)
This seems to be due to a throwback from when WordPress had user levels instead of roles because the post author metabox is called with an argument of 'who' => 'authors'
... It probably should not be this way any more but that's how it is. See /wp-includes/class-wp-user-query.php
where the who
argument is checked:
if ( isset( $qv['who'] ) && 'authors' == $qv['who'] && $blog_id ) {
$who_query = array(
'key' => $wpdb->get_blog_prefix( $blog_id ) . 'user_level',
'value' => 0,
'compare' => '!=',
);
Alternatively, you can add 'level_1' => true,
(or any level_*
except level_0
) to your role capability list, but you will need to remove and add the role from each user with it to trigger an update of the user_level
user meta for that user. (Unfortunately there doesn't seem to be an in-built way of updating this for all users of a role.)