Support » Developing with WordPress » Custom User Role doesn’t appear in dropdown list of Author

  • Hi there,

    I created a Custom User role using a plugin with the following code:

    function sk_add_custom_roles_on_plugin_activation() {
        
        // Remove custom roles to update capabilities changes
    
        if( get_role('sk_guide') ){
              remove_role( 'sk_guide' );
        }
        
        add_role(
            'sk_guide',
            __( 'NewAuthor' , 'sk-custom-user-role'),
            array(
                'read' => true,  // true allows this capability
                'edit_published_posts' => true,
                'upload_files' => true,
                'publish_posts' => true,
                'delete_published_posts' => true,
                'edit_posts' => true,
                'delete_posts' => true,
            )
        );
    }
    register_activation_hook( __FILE__, 'sk_add_custom_roles_on_plugin_activation' );

    The new user has the same capabilities of Author.

    Unfortunately when I attempt to change an Article author to one with my NewAuthor role it doesn’t appear in the list.

    I found this solution https://stormconsultancy.co.uk/blog/development/bug-of-the-day/custom-roles-in-wordpress-not-appearing-in-author-lists/ but it’s very outdated.

    Does anyone have an update or an alternative?

    Thanks a lot,

    Simone

Viewing 5 replies - 1 through 5 (of 5 total)
  • I can’t tell if you mean that the user name isn’t in a user list, or the role name isn’t in a role list, or the article doesn’t appear in a list. The user doing the manipulating also needs the capability to see the new stuff, even if it’s admin, it doesn’t get it by default.

    Did you look at the tickets that the article referenced, to see if they were fixed?

    Moderator bcworkz

    (@bcworkz)

    There’s nothing wrong with your code, it works correctly on my site. Your plugin wouldn’t be a “must use” plugin would it? Such plugins run too early to manage roles.

    The reason you don’t see your role could be due to caching somewhere. Flush your browser cache to start with. Flush any caching plugins you might have. If your host has caching active, there should be a flush option in your hosting control panel.

    Hi Joy, hi bcworks,

    thanks for your help! I meant that the users with my custom role don’t appear in the dropdown menu of the Author field of Articles (see screenshot below):

    https://pasteboard.co/HURQmep.png

    @bcworkz

    No, it’s not a must use plugin and I triend flushing the cache. The issue is still there.

    @joyously

    How I add the capability you mention at my admins? I also check the tickets regarding similar issued to mine but non of them seem fixed.

    Thanks for any follows up,

    Simone

    Sorry, one thing I was thinking was custom post type, but you don’t have that. You have added a new role only. When you are trying to change the author, what role is the user that you are logged in as? (I just wonder about the role not having edit_others_posts.)

    Moderator bcworkz

    (@bcworkz)

    I thought you were referring to a different dropdown. My bad. The one I checked works, but the quick edit author list would not work. It’s not directly a matter of proper capabilities, though that is a factor. The function that generates the drop down has a strange definition of what an “author” is. Instead of trying to match that definition, I suggest you alter the arguments of the drop down function through the ‘wp_dropdown_users_args’ filter. Add a “role__in” query arg, setting its value to an array of all role names that should be included in the list. You may need to also set the “who” query arg to an empty string.

    To avoid altering other unrelated user drop downs, only add the “role__in” query arg if the “who” arg is set to 'authors' (before setting it empty of course).

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Custom User Role doesn’t appear in dropdown list of Author’ is closed to new replies.