Make WordPress Core

Ticket #40320: 40320.patch

File 40320.patch, 1.3 KB (added by keraweb, 7 years ago)

Add WP_Roles::rename_role() method + rename_role() helper function

  • wp-includes/capabilities.php

     
    677677}
    678678
    679679/**
     680 * Rename an existing role.
     681 *
     682 * @since 4.8.0
     683 *
     684 * @param string $role Role slug.
     685 * @param string $new_name New role name.
     686 */
     687function rename_role( $role, $new_name ) {
     688        wp_roles()->rename_role( $role, $new_name );
     689}
     690
     691/**
    680692 * Retrieve a list of super admins.
    681693 *
    682694 * @since 3.0.0
  • wp-includes/class-wp-roles.php

     
    209209        }
    210210
    211211        /**
     212         * Rename an existing role.
     213         *
     214         * @since  4.8.0
     215         *
     216         * @param string $role Role slug.
     217         * @param string $new_name New role name.
     218         */
     219        public function rename_role( $role, $new_name ) {
     220                if ( ! isset( $this->role_objects[ $role ] ) )
     221                        return;
     222
     223                $this->role_objects[ $role ]->name = $new_name;
     224                $this->role_names[ $role ] = $new_name;
     225                $this->roles[ $role ]['name'] = $new_name;
     226
     227                if ( $this->use_db )
     228                        update_option( $this->role_key, $this->roles );
     229        }
     230
     231        /**
    212232         * Add capability to role.
    213233         *
    214234         * @since 2.0.0