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.


Top ↑

Return

(WP_Role|null) WP_Role object if found, null if the role does not exist.


Top ↑

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;
		}
	}


Top ↑

Changelog

Changelog
VersionDescription
2.0.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.