WPSEO_Capability_Utils::get_applicable_roles()public staticYoast 1.0

Retrieves the roles that have the specified capability.

Метод класса: WPSEO_Capability_Utils{}

Хуков нет.

Возвращает

Массив. The names of the roles that have the capability.

Использование

$result = WPSEO_Capability_Utils::get_applicable_roles( $capability );
$capability(строка) (обязательный)
The name of the capability.

Код WPSEO_Capability_Utils::get_applicable_roles() Yoast 21.6

public static function get_applicable_roles( $capability ) {
	$roles      = wp_roles();
	$role_names = $roles->get_names();

	$applicable_roles = [];
	foreach ( array_keys( $role_names ) as $role_name ) {
		$role = $roles->get_role( $role_name );

		if ( ! $role ) {
			continue;
		}

		// Add role if it has the capability.
		if ( array_key_exists( $capability, $role->capabilities ) && $role->capabilities[ $capability ] === true ) {
			$applicable_roles[] = $role_name;
		}
	}

	return $applicable_roles;
}