bbp_is_valid_role( string $role = '' )
Check if a role ID is valid
Description
This helper function accepts a role ID as a string, and compares it against the array of registered dynamic roles.
Use this function anytime you are manually attempting to set a user role without using the bbp_set_user_role() function, or if you need to halt additional processing during role validation.
Parameters
- $role
-
(string) (Optional) A well-formed (string) role ID to validate
Default value: ''
Return
(bool) True if role is valid. False if role is not valid.
Source
File: bp-forums/users/capabilities.php
function bbp_is_valid_role( $role = '' ) { // Default return value $retval = false; // Skip if no role to check if ( ! empty( $role ) && is_string( $role ) ) { // Get the dynamic role IDs $roles = array_keys( bbp_get_dynamic_roles() ); // Skip if no known role IDs if ( ! empty( $roles ) ) { // Is role in dynamic roles array? $retval = in_array( $role, $roles, true ); } } // Filter & return return (bool) apply_filters( 'bbp_is_valid_role', $retval, $role ); }
Changelog
Version | Description |
---|---|
BBPress 2.6.5 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.