Skip Navigation

[Closed] Adding multiple roles to Author Dropdown

This support ticket is created 2 years, 7 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 7 replies, has 3 voices.

Last updated by Waqar 2 years, 7 months ago.

Assisted by: Waqar.

Author
Posts
#2164967

Tell us what you are trying to do? I have created two custom user roles; partner and staff. I am trying to add a code snippet to add users with those roles to the author dropdowns in WP Admin.

Is there any documentation that you are following?
I'm trying to use the code snippet in this article. https://toolset.com/forums/topic/author-dropdown-and-custom-roles/
I have tried changing array to array('partner', 'staff') but that doesn't work. How can I modify the code to add more than one custom user role?

#2165233

Hello, since the implementation of Gutenberg / Block editor, the script you mentioned is no longer sufficient for changing the author dropdown in all 3 wp-admin author dropdowns (Batch/Quick Edit, classic post editor, Blocks post editor). I think you need at least one more snippet to cover the Block Editor post author options. See more information about this and a link to some additional code examples in another ticket here: https://toolset.com/forums/topic/custom-role-users-to-display-in-authors-dropdown/

#2168005

I am only trying to change the author via the classic editor, not the block editor. The code referenced in my original question does work, but only for adding a single user role. I need to modify that code to allow for adding two user roles to the author dropdown list in the classic editor. Is that possible? I'm willing to live without changing the author via the block editor settings.

#2168453

The code referenced in my original question does work, but only for adding a single user role. I need to modify that code to allow for adding two user roles to the author dropdown list in the classic editor. Is that possible?
Yes, you should be able to add additional role slugs to the role slug array using a comma-separated syntax like this:

function wpdocs_add_members_to_dropdown( $query_args, $r ) {
 
    $query_args['role'] = array('member', 'customrole1', 'customrole2');
     // ...the remaining code follows below, unchanged...
     

You would replace customrole1 and customrole2 with the slugs of any custom User roles you would like to see available in the author dropdown.

Let me know if this isn't clear or if you have follow up questions after implementation.

#2170129

I updated the code but it's not working. When I use the code below the author dropdown is missing both when using the classic editor and the quick edit.

/** ADD USER ROLE TO AUTHOR DROPDOWN */
function wpdocs_add_members_to_dropdown( $query_args, $r ) {
    
    $query_args['role'] = array('partner', 'staff');
    
    // Unset the 'who' as this defaults to the 'author' role
    unset( $query_args['who'] );
    
    return $query_args;
}
add_filter( 'wp_dropdown_users_args', 'wpdocs_add_members_to_dropdown', 10, 2 );
#2173221

Okay there must be something else going on here because normally this code would be sufficient for allowing those user roles to appear in the author dropdown. Can you provide some additional information so I can do a bit more investigation?

Please tell me:
- In which post type(s) would you like to add these custom roles to the author dropdown?
- hat User/role do you test this in wp-admin?
- Please temporarily disable all 3rd-party plugins except Types, Blocks (or Views), and Access. Temporarily activate a default theme like Twenty Twenty One. If the custom code snippet was added in your theme's functions.php file, please add it as a custom code snippet instead in Toolset > Settings > Custom Code. Temporarily disable all other custom code snippets, then test the author dropdown again.
- If the problem is resolved, this indicates a possible conflict with some other active component of the site. Reactivate your other custom code snippets, theme, and plugins one by one, testing each time until the problem returns.
- If the problem is still unresolved, I'll need to take a closer look. Please provide admin login credentials in the private fields available for your next reply. If necessary, I may need to make a clone of the site so I can install a copy locally in my own environment and run additional tests in a controlled setup. To make a clone of the site, I will install a plugin like Duplicator or All-in-One WP Migration. Please let me know if you approve, and I'll get started on those tests.

#2181183

Sorry for my delayed response. I will do the testing you have recommended and respond back. It will be a couple days before I can respond.

#2181565

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thanks for the update and please take your time.

Note: I've set your next reply as private again, in case you need to share temporary admin access details.

The topic ‘[Closed] Adding multiple roles to Author Dropdown’ is closed to new replies.