Changeset 42343 for trunk/src/wp-includes/class-wp-roles.php
- Timestamp:
- 11/30/2017 11:09:33 PM (8 years ago)
- File:
-
- 1 edited
-
trunk/src/wp-includes/class-wp-roles.php (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-roles.php
r42151 r42343 16 16 * 17 17 * array ( 18 * 'rolename' => array (19 * 'name' => 'rolename',20 * 'capabilities' => array()21 * )18 * 'rolename' => array ( 19 * 'name' => 'rolename', 20 * 'capabilities' => array() 21 * ) 22 22 * ) 23 23 * … … 158 158 } 159 159 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 ) { 165 165 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 ]; 169 170 } 170 171 … … 177 178 */ 178 179 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 ) { 187 189 update_option( $this->role_key, $this->roles ); 188 189 if ( get_option( 'default_role' ) == $role ) 190 } 191 192 if ( get_option( 'default_role' ) == $role ) { 190 193 update_option( 'default_role', 'subscriber' ); 194 } 191 195 } 192 196 … … 201 205 */ 202 206 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 ) { 208 213 update_option( $this->role_key, $this->roles ); 214 } 209 215 } 210 216 … … 218 224 */ 219 225 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 ) { 225 232 update_option( $this->role_key, $this->roles ); 233 } 226 234 } 227 235 … … 235 243 */ 236 244 public function get_role( $role ) { 237 if ( isset( $this->role_objects[ $role] ) )238 return $this->role_objects[ $role];239 else245 if ( isset( $this->role_objects[ $role ] ) ) { 246 return $this->role_objects[ $role ]; 247 } else { 240 248 return null; 249 } 241 250 } 242 251 … … 261 270 */ 262 271 public function is_role( $role ) { 263 return isset( $this->role_names[ $role] );272 return isset( $this->role_names[ $role ] ); 264 273 } 265 274 … … 275 284 276 285 $this->role_objects = array(); 277 $this->role_names =array();286 $this->role_names = array(); 278 287 foreach ( array_keys( $this->roles ) as $role ) { 279 288 $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']; 281 290 } 282 291
Note: See TracChangeset
for help on using the changeset viewer.