Make WordPress Core

Ticket #14578: garyc40.14578.diff

File garyc40.14578.diff, 4.0 KB (added by garyc40, 14 years ago)

reverse role dropdown list, add a verification filter for 'default_role', update 'default_role' when remove_role()

  • wp-admin/includes/template.php

    diff --git wp-admin/includes/template.php wp-admin/includes/template.php
    index a788b8f..5d112ce 100644
    function the_attachment_links( $id = false ) { 
    759759 * @param string $selected slug for the role that should be already selected
    760760 */
    761761function wp_dropdown_roles( $selected = false ) {
    762         $p = '';
    763762        $r = '';
    764763
    765         $editable_roles = get_editable_roles();
     764        $editable_roles = array_reverse(get_editable_roles());
    766765
    767766        foreach ( $editable_roles as $role => $details ) {
    768767                $name = translate_user_role($details['name'] );
    769768                if ( $selected == $role ) // preselect specified role
    770                         $p = "\n\t<option selected='selected' value='" . esc_attr($role) . "'>$name</option>";
     769                        $r .= "\n\t<option selected='selected' value='" . esc_attr($role) . "'>$name</option>";
    771770                else
    772771                        $r .= "\n\t<option value='" . esc_attr($role) . "'>$name</option>";
    773772        }
    774         echo $p . $r;
     773        echo $r;
    775774}
    776775
    777776/**
  • wp-admin/options-general.php

    diff --git wp-admin/options-general.php wp-admin/options-general.php
    index 57a1b14..4da6f6b 100644
    include('./admin-header.php'); 
    113113</fieldset></td>
    114114</tr>
    115115<tr valign="top">
    116 <th scope="row"><label for="default_role"><?php _e('New User Default Role') ?></label></th>
     116<th scope="row"><label for="default_role"><?php _e('New User Default Role'); ?></label></th>
    117117<td>
    118118<select name="default_role" id="default_role"><?php wp_dropdown_roles( get_option('default_role') ); ?></select>
    119119</td>
  • wp-includes/capabilities.php

    diff --git wp-includes/capabilities.php wp-includes/capabilities.php
    index 7d8a00d..9c00296 100644
    class WP_Roles { 
    166166
    167167                if ( $this->use_db )
    168168                        update_option( $this->role_key, $this->roles );
     169               
     170                if ( get_option( 'default_role' ) == $role )
     171                        update_option( 'default_role', 'subscriber' );
    169172        }
    170173
    171174        /**
    class WP_Roles { 
    206209         * @access public
    207210         *
    208211         * @param string $role Role name.
    209          * @return object|null Null, if role does not exist. WP_Role object, if found.
     212         * @return object|null empty object, if role does not exist. WP_Role object, if found.
    210213         */
    211214        function &get_role( $role ) {
    212                 if ( isset( $this->role_objects[$role] ) )
     215                if ( isset( $this->role_objects[$role] ) ) {
    213216                        return $this->role_objects[$role];
    214                 else
    215                         return null;
     217                }
     218                else {
     219                        $obj = null; // prevent invalid variable reference notice
     220                        return $obj;
     221                }
    216222        }
    217223
    218224        /**
    function user_can( $user, $capability ) { 
    11181124 * @param string $role Role name.
    11191125 * @return object
    11201126 */
    1121 function get_role( $role ) {
     1127function &get_role( $role ) {
    11221128        global $wp_roles;
    11231129
    11241130        if ( ! isset( $wp_roles ) )
  • wp-includes/default-filters.php

    diff --git wp-includes/default-filters.php wp-includes/default-filters.php
    index c796453..fda9a2b 100644
    add_filter( 'option_ping_sites', 'privacy_ping_filter' ); 
    172172add_filter( 'option_blog_charset',  '_wp_specialchars'                    ); // IMPORTANT: This must not be wp_specialchars() or esc_html() or it'll cause an infinite loop
    173173add_filter( 'option_home',          '_config_wp_home'                     );
    174174add_filter( 'option_siteurl',       '_config_wp_siteurl'                  );
     175add_filter( 'option_default_role',  '_wp_filter_verify_default_role'      );
    175176add_filter( 'tiny_mce_before_init', '_mce_set_direction'                  );
    176177add_filter( 'pre_kses',             'wp_pre_kses_less_than'               );
    177178add_filter( 'sanitize_title',       'sanitize_title_with_dashes'          );
  • wp-includes/functions.php

    diff --git wp-includes/functions.php wp-includes/functions.php
    index abcb63d..19473fa 100644
    function wp_find_hierarchy_loop_tortoise_hare( $callback, $start, $override = ar 
    44714471        return false;
    44724472}
    44734473
     4474function _wp_filter_verify_default_role( $role ) {
     4475        $role_obj = get_role( $role );
     4476        if ( empty( $role_obj ) )
     4477                $role = 'subscriber';
     4478        return $role;
     4479}
    44744480?>