Make WordPress Core

Opened 3 years ago

Last modified 7 months ago

#16841 new defect (bug)

manually created user roles not showing in author dropdown irregardless of assigned capabilities

Reported by: 10sexyapples Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 3.1
Component: Role/Capability Keywords:
Focuses: Cc:


I posted the below on wp-testers hoping to verify or gain experiences from others in order to confirm this prior to reporting it as a bug, but, haven't received any further input, and it's just becoming more evident to me that perhaps it should be posted here, so, I hope I'm not creating a false report here. Please excuse me if I am.

I'm posting this as a link so that it will translate more clearly rather than just cluttering up this message with more text than necessary.

Upon further investigation I have also come across the following:

I'm not an expert at debugging this sort of thing, but, I have attempted all within my knowledge thus far, and in looking at all of the returned objects and entries, the only difference I can spot between how the default user roles ( which show up properly in the dropdown ) and the custom created roles ( which do not ) are being returned is that the default user roles, editor for instance, correctly show the deprecated level_7 entry, and the custom user role ( with more assigned privileges than the editor ) does not show user levels in the capabilities array at all, and shows level_0 in the object.

This is leading me to think that perhaps there is something happening with those user levels in creating the author dropdown on the post editor that is blocking the custom user roles from showing up as expected.

When running the following code:

echo '<br /><br /><h3>Roles</h3>';
	foreach ( $wp_roles->role_names as $role => $name ) :
		echo '<br /> <br />';
		echo '<pre> Role displayed in Admin as ' . $name ;
		echo  '     Database entry: '  . $role . '</pre>';

		echo '<h5> Capabilities assigned to the role of ' . $name. '</h5>';
		// print_r( $caps);
		echo '<pre>';
		$rolename = get_role($role);
		$caps = $rolename->capabilities;
			foreach ($caps as $capability => $value):
				echo  $capability . ' '.  $value . "\n" ;
		echo '</pre>';

the default wp roles return the following capability value pairings

delete_published_posts 1

roles created with Justin Tadlock's members plugin return the following

delete_published_posts delete_published_posts

roles created manually in functions.php utilizing

add_role( 'test_role', 'Test Role' );

//saved and then removed before running the code below ...

$role = get_role('test_role');


return the following ...

delete_published_posts 1

but lack the user levels as mentioned above.

Let me know if there is any further info I can provide to help sort this out~

Change History (14)

comment:1 10sexyapples3 years ago

ahA! okay, I believe the use of user_level here is the culprit:

If user level is going to stick around in this way then shouldn't add_cap perhaps take this into consideration?

Last edited 3 years ago by scribu (previous) (diff)

comment:2 scribu3 years ago

  • Component changed from General to Role/Capability

The workaround would just be to add a 'level_1' cap to your role.

It's PITA, considering how user levels have been deprecated so long ago, but there you go.

comment:3 scribu3 years ago

PS: Instead of posting the full ticket url, just write #123, where 123 is the ticket number.

comment:4 10sexyapples3 years ago

Hmm. I actually tried adding the level caps, but, didn't see any change in the array after.
I was using add_cap.
Perhaps I saved, and then removed my code before it got picked up? I'm going to try it again.
And yes, definitely a PITA ... I saw your comments in having to put it there in the first place ...
As usual, thanks for the tips on proper posting etiquette ;-)
# 123 it is.

Last edited 3 years ago by 10sexyapples (previous) (diff)

comment:5 scribu3 years ago

Related: #16714

comment:6 magicroundabout2 years ago

Hello, this is my first post on Trac, so I hope it's useful.

I spotted that new users in roles added with add_role don't appear in the author dropdown list. This seems to have been introduced in #15871 when code was added to WP_User_Query->prepare_query to only select users with an old-school user-level of > 0 if 'who' => 'authors' was passed in the args.

I don't quite understand the discussion on the logic of this (in #15871). It seems to me that user levels are deprecated, so shouldn't this select users with the edit_posts capability?

Alternatively (additionally?), perhaps we could have a filter hook in wp_dropdown_users that lets us modify the arguments passed to get_users()?

comment:7 scribu2 years ago

We still use user levels there because we don't have a good way of getting the same list via capabilties. It's a mess.

comment:8 lgladdy2 years ago

And additional (imo) bug stops add_cap('level_1') from fixing this for existing users. I've posted a trac ticket for it #19747

Last edited 2 years ago by lgladdy (previous) (diff)

comment:9 markoheijnen2 years ago

  • Cc marko@… added

comment:10 pauldewouters2 years ago

  • Cc pauldewouters added

comment:11 scottconnerly21 months ago

  • Cc scott@… added

comment:12 BandonRandon17 months ago

  • Cc BandonRandon added

comment:13 viniciusrtf10 months ago

While trying to apply level_1 to my custom role, I didn't remember the custom role name (it is different from display name and it doesn't appear anywhere in backend), so I figured it out with this dirty SQL query:

SELECT meta_value FROM wp_usermeta WHERE user_id = 223;
Version 0, edited 10 months ago by viniciusrtf (next)

comment:14 jchristopher7 months ago

  • Cc jonathan@… added
Note: See TracTickets for help on using tickets.