WordPress.org

Make WordPress Core

Ticket #24972: wp_dropdown_roles.diff

File wp_dropdown_roles.diff, 1.5 KB (added by PauloASilva, 6 years ago)

diff

  • wp-admin/includes/template.php

    diff -r e185f8cbbec5 wp-admin/includes/template.php
    a b  
    751751/**
    752752 * Print out <option> html elements for role selectors
    753753 *
     754 * <code>
     755 * // call with a single pre-selected option
     756 * wp_dropdown_roles( 'editor' ):
     757 *
     758 * // call with multiple pre-selected options
     759 * wp_dropdown_roles( array( 'editor', 'administrator' ) ):
     760 * </code>
     761 *
    754762 * @since 2.1.0
    755763 *
    756  * @param string $selected slug for the role that should be already selected
     764 * @param       string|array    $selected list of role slugs that should be already
     765 * selected
     766 * @return      string  list of HTML <option> elements with user roles
    757767 */
    758768function wp_dropdown_roles( $selected = false ) {
    759769        $p = '';
     
    761771
    762772        $editable_roles = get_editable_roles();
    763773
     774        // For backwards compatibility
     775        if ( is_string($selected) )
     776                $selected = array( $selected );
     777
    764778        foreach ( $editable_roles as $role => $details ) {
    765779                $name = translate_user_role($details['name'] );
    766                 if ( $selected == $role ) // preselect specified role
    767                         $p = "\n\t<option selected='selected' value='" . esc_attr($role) . "'>$name</option>";
     780                if ( is_array($selected) AND in_array($role,$selected) ) // preselect specified role
     781                        $p .= "\n\t<option selected='selected' value='" . esc_attr($role) . "'>$name</option>";
    768782                else
    769783                        $r .= "\n\t<option value='" . esc_attr($role) . "'>$name</option>";
    770784        }