WP_Roles::get_role() WordPress Method
The WP_Roles::get_role() method is used to get a role object by its name. This method is part of the WP_Roles class, which manages the roles and capabilities of users on a WordPress site. The get_role() method allows you to get a role object by its name. This role object can then be used to check if a user has the required capabilities for that role. The get_role() method takes one parameter, which is the name of the role you want to get. This name should be a string. If the role you are trying to get does not exist, then the get_role() method will return false.
WP_Roles::get_role( string $role ) #
Retrieve role object by name.
Parameters
- $role
(string)(Required)Role name.
Return
(WP_Role|null) WP_Role object if found, null if the role does not exist.
Source
File: wp-includes/class-wp-roles.php
public function get_role( $role ) { if ( isset( $this->role_objects[ $role ] ) ) { return $this->role_objects[ $role ]; } else { return null; } }
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
Version | Description |
---|---|
2.0.0 | Introduced. |