WP_Users_List_Table::get_role_list() WordPress Method

The WP_Users_List_Table::get_role_list() function is used to get a list of roles for a given user. The function takes a user object as its only parameter and returns an array of roles for the user.

WP_Users_List_Table::get_role_list( WP_User $user_object ) #

Returns an array of translated user role names for a given user object.


Parameters

$user_object

(WP_User)(Required)The WP_User object.


Top ↑

Return

(string[]) An array of user role names keyed by role.


Top ↑

Source

File: wp-admin/includes/class-wp-users-list-table.php

	protected function get_role_list( $user_object ) {
		$wp_roles = wp_roles();

		$role_list = array();

		foreach ( $user_object->roles as $role ) {
			if ( isset( $wp_roles->role_names[ $role ] ) ) {
				$role_list[ $role ] = translate_user_role( $wp_roles->role_names[ $role ] );
			}
		}

		if ( empty( $role_list ) ) {
			$role_list['none'] = _x( 'None', 'no user roles' );
		}

		/**
		 * Filters the returned array of translated role names for a user.
		 *
		 * @since 4.4.0
		 *
		 * @param string[] $role_list   An array of translated user role names keyed by role.
		 * @param WP_User  $user_object A WP_User object.
		 */
		return apply_filters( 'get_role_list', $role_list, $user_object );
	}


Top ↑

Changelog

Changelog
VersionDescription
4.4.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.