Make WordPress Core

Opened 8 months ago

Last modified 13 days ago

#54554 new enhancement

Allow returning content for wp_dropdown_roles()

Reported by: nithi22's profile nithi22 Owned by:
Milestone: 6.1 Priority: normal
Severity: normal Version:
Component: Role/Capability Keywords: has-patch
Focuses: Cc:

Description

Currently wp_dropdown_roles() function is set to echo the content instead of the option to echo or return the content. Similar wp_dropdown_* functions allows to echo or not the content.

Change History (7)

#1 @sabernhardt
8 months ago

  • Component changed from General to Role/Capability

This ticket was mentioned in PR #2006 on WordPress/wordpress-develop by nithinjohn22.


8 months ago

  • Keywords has-patch added

Currently wp_dropdown_roles function only prints the elements for the role selectors not to display or retrieve the HTML like other dropdown functions.

Trac ticket: https://core.trac.wordpress.org/ticket/54554

This ticket was mentioned in Slack in #core by nithi22. View the logs.


2 months ago

#4 @SergeyBiryukov
2 months ago

  • Milestone changed from Awaiting Review to 6.1

#5 @prbot
13 days ago

audrasjb commented on PR #2006:

I added one commit to fix a merge conflict and to add proper since mention.

#6 @audrasjb
13 days ago

I tested the PR with the following code:

add_filter( 'admin_footer_text', function() {
	echo '<select>';
	wp_dropdown_roles( 'editor' );
	echo '</select>';
} );

It returns the same result than before the patch.

and then I tested it with this snippet:

add_filter( 'admin_footer_text', function() {
	$roles = wp_dropdown_roles( array(
		'echo' => false,
	) );
	var_export( $roles );
} );

$roles is an array of roles.

Looks good to me 👍

#7 @audrasjb
13 days ago

Ah, wait, no. In the above example, $roles is not an array. It's a string.
I can hardly see how to use it in real life. We should probably just return an array of user roles. Probably just returning the content of $editable_roles should be enough.

Note: See TracTickets for help on using tickets.