[wp-trac] [WordPress Trac] #24972: wp_dropdown_roles() multiple pre-selected options

WordPress Trac noreply at wordpress.org
Thu Jul 20 19:03:19 UTC 2017


#24972: wp_dropdown_roles() multiple pre-selected options
-------------------------------------+-------------------------------------
 Reporter:  PauloASilva              |       Owner:
     Type:  enhancement              |      Status:  new
 Priority:  normal                   |   Milestone:  Awaiting Review
Component:  Users                    |     Version:  3.6
 Severity:  normal                   |  Resolution:
 Keywords:  has-patch needs-refresh  |     Focuses:  administration,
  ux-feedback                        |  template
-------------------------------------+-------------------------------------

Comment (by PauloASilva):

 Back in 2013, when this ticket was opened, I was working on some plugin
 whose interface would list user roles, allowing multiple roles to be
 selected (e.g. to link with post types).

 `wp_dropdown_roles()` is a template function which outputs `<option>`
 elements, intended for use with the `<select>` element, but it does not
 output it, so a developer can write it as follow to allow multiple entries
 to be selected at once (e.g. editor and contributor)

 {{{
 <select multiple>
     <?php wp_dropdown_roles( 'editor' ); ?>
 </select>
 }}}

 Then, selected options are persisted on database.
 How to do to get persisted options rendered back on this same control?

 As is `wp_dropdown_roles()` does not allow it.
 Proposed change makes it not only possible but also seamless, without
 requiring any custom function implementation or hackish way to do it (e.g.
 using buffers)


 {{{
 <select multiple>
     <?php wp_dropdown_roles( array( 'editor', 'contributor') ); ?>
 </select>
 }}}

 This way `editor` and `contributor` options will be rendered selected.

 I think it is interesting for developers.

 To clarify the `API` thing, I was not referring myself to the XML RPC API
 but to the WordPress core API (functions and Object provided by WordPress
 core).

 Regards,
 Paulo A. Silva

--
Ticket URL: <https://core.trac.wordpress.org/ticket/24972#comment:13>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list