Make WordPress Core

Opened 2 years ago

Last modified 20 months ago

#54554 new enhancement

Allow returning content for wp_dropdown_roles()

Reported by: nithi22's profile nithi22 Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version:
Component: Role/Capability Keywords: has-patch dev-feedback
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 (8)

#1 @sabernhardt
2 years ago

  • Component changed from General to Role/Capability

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


2 years ago
#2

  • 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 years ago

#4 @SergeyBiryukov
2 years ago

  • Milestone changed from Awaiting Review to 6.1

audrasjb commented on PR #2006:


22 months ago
#5

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

#6 @audrasjb
22 months 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
22 months 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.

#8 @davidbaumwald
20 months ago

  • Keywords dev-feedback added
  • Milestone changed from 6.1 to Future Release

I'm not sure about this. Every instance I see in core where wp_dropdown_roles is called, it's being output. wp_dropdown_roles only creates the options, not the outer select element.

One thing I could see going here is maybe a apply_filters call at the echo.

Marking for dev-feedback and moving to Future Release until this has a more solid direction.

Note: See TracTickets for help on using tickets.