Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (8 years ago)
Author:
pento
Message:

Code is Poetry.
WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-roles.php

    r42151 r42343  
    1616 *
    1717 *     array (
    18  *          'rolename' => array (
    19  *              'name' => 'rolename',
    20  *              'capabilities' => array()
    21  *          )
     18 *          'rolename' => array (
     19 *              'name' => 'rolename',
     20 *              'capabilities' => array()
     21 *          )
    2222 *     )
    2323 *
     
    158158        }
    159159
    160         $this->roles[$role] = array(
    161             'name' => $display_name,
    162             'capabilities' => $capabilities
    163             );
    164         if ( $this->use_db )
     160        $this->roles[ $role ] = array(
     161            'name'         => $display_name,
     162            'capabilities' => $capabilities,
     163        );
     164        if ( $this->use_db ) {
    165165            update_option( $this->role_key, $this->roles );
    166         $this->role_objects[$role] = new WP_Role( $role, $capabilities );
    167         $this->role_names[$role] = $display_name;
    168         return $this->role_objects[$role];
     166        }
     167        $this->role_objects[ $role ] = new WP_Role( $role, $capabilities );
     168        $this->role_names[ $role ]   = $display_name;
     169        return $this->role_objects[ $role ];
    169170    }
    170171
     
    177178     */
    178179    public function remove_role( $role ) {
    179         if ( ! isset( $this->role_objects[$role] ) )
    180             return;
    181 
    182         unset( $this->role_objects[$role] );
    183         unset( $this->role_names[$role] );
    184         unset( $this->roles[$role] );
    185 
    186         if ( $this->use_db )
     180        if ( ! isset( $this->role_objects[ $role ] ) ) {
     181            return;
     182        }
     183
     184        unset( $this->role_objects[ $role ] );
     185        unset( $this->role_names[ $role ] );
     186        unset( $this->roles[ $role ] );
     187
     188        if ( $this->use_db ) {
    187189            update_option( $this->role_key, $this->roles );
    188 
    189         if ( get_option( 'default_role' ) == $role )
     190        }
     191
     192        if ( get_option( 'default_role' ) == $role ) {
    190193            update_option( 'default_role', 'subscriber' );
     194        }
    191195    }
    192196
     
    201205     */
    202206    public function add_cap( $role, $cap, $grant = true ) {
    203         if ( ! isset( $this->roles[$role] ) )
    204             return;
    205 
    206         $this->roles[$role]['capabilities'][$cap] = $grant;
    207         if ( $this->use_db )
     207        if ( ! isset( $this->roles[ $role ] ) ) {
     208            return;
     209        }
     210
     211        $this->roles[ $role ]['capabilities'][ $cap ] = $grant;
     212        if ( $this->use_db ) {
    208213            update_option( $this->role_key, $this->roles );
     214        }
    209215    }
    210216
     
    218224     */
    219225    public function remove_cap( $role, $cap ) {
    220         if ( ! isset( $this->roles[$role] ) )
    221             return;
    222 
    223         unset( $this->roles[$role]['capabilities'][$cap] );
    224         if ( $this->use_db )
     226        if ( ! isset( $this->roles[ $role ] ) ) {
     227            return;
     228        }
     229
     230        unset( $this->roles[ $role ]['capabilities'][ $cap ] );
     231        if ( $this->use_db ) {
    225232            update_option( $this->role_key, $this->roles );
     233        }
    226234    }
    227235
     
    235243     */
    236244    public function get_role( $role ) {
    237         if ( isset( $this->role_objects[$role] ) )
    238             return $this->role_objects[$role];
    239         else
     245        if ( isset( $this->role_objects[ $role ] ) ) {
     246            return $this->role_objects[ $role ];
     247        } else {
    240248            return null;
     249        }
    241250    }
    242251
     
    261270     */
    262271    public function is_role( $role ) {
    263         return isset( $this->role_names[$role] );
     272        return isset( $this->role_names[ $role ] );
    264273    }
    265274
     
    275284
    276285        $this->role_objects = array();
    277         $this->role_names = array();
     286        $this->role_names   = array();
    278287        foreach ( array_keys( $this->roles ) as $role ) {
    279288            $this->role_objects[ $role ] = new WP_Role( $role, $this->roles[ $role ]['capabilities'] );
    280             $this->role_names[ $role ] = $this->roles[ $role ]['name'];
     289            $this->role_names[ $role ]   = $this->roles[ $role ]['name'];
    281290        }
    282291
Note: See TracChangeset for help on using the changeset viewer.