Changeset 7086 for trunk/src/includes/users/capabilities.php
- Timestamp:
- 05/28/2020 03:38:54 PM (6 years ago)
- File:
-
- 1 edited
-
trunk/src/includes/users/capabilities.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/includes/users/capabilities.php
r7060 r7086 149 149 * @param int $user_id 150 150 * 151 * @return string151 * @return mixed False if no change. String of new role if changed. 152 152 */ 153 153 function bbp_set_user_role( $user_id = 0, $new_role = '' ) { … … 160 160 if ( ! empty( $user ) ) { 161 161 162 // Get user sforum role162 // Get user forum role 163 163 $role = bbp_get_user_role( $user_id ); 164 164 … … 167 167 $new_role = false; 168 168 169 // User s role is different than the newrole170 } else {169 // User role is different than the new (valid) role 170 } elseif ( bbp_is_valid_role( $new_role ) ) { 171 171 172 172 // Remove the old role … … 305 305 // Set the new forums role 306 306 bbp_set_user_role( $user_id, $new_role ); 307 } 308 309 /** 310 * Check if a role ID is valid 311 * 312 * This helper function accepts a role ID as a string, and compares it against 313 * the array of registered dynamic roles. 314 * 315 * Use this function anytime you are manually attempting to set a user role 316 * without using the bbp_set_user_role() function, or if you need to halt 317 * additional processing during role validation. 318 * 319 * @since 2.6.5 320 * 321 * @param string $role A well-formed (string) role ID to validate 322 * 323 * @return bool True if role is valid. False if role is not valid. 324 */ 325 function bbp_is_valid_role( $role = '' ) { 326 327 // Default return value 328 $retval = false; 329 330 // Skip if no role to check 331 if ( ! empty( $role ) && is_string( $role ) ) { 332 333 // Get the dynamic role IDs 334 $roles = array_keys( bbp_get_dynamic_roles() ); 335 336 // Skip if no known role IDs 337 if ( ! empty( $roles ) ) { 338 339 // Is role in dynamic roles array? 340 $retval = in_array( $role, $roles, true ); 341 } 342 } 343 344 // Filter & return 345 return (bool) apply_filters( 'bbp_is_valid_role', $retval, $role ); 307 346 } 308 347
Note: See TracChangeset
for help on using the changeset viewer.