# wp-graphql/trunk/src/Data/Loader/UserRoleLoader.php

WPGraphQL, version trunk. 48 lines.

- Page: https://pluginprobe.com/plugins/wp-graphql/trunk/code/src/Data/Loader/UserRoleLoader.php
- Raw: https://pluginprobe.com/plugins/wp-graphql/trunk/raw/src/Data/Loader/UserRoleLoader.php
- Modified: 2023-11-02T19:07:14+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/wp-graphql/trunk/code/src/Data/Loader/UserRoleLoader.php#L10-L20`.

```php
<?php

namespace WPGraphQL\Data\Loader;

use WPGraphQL\Model\UserRole;

/**
 * Class UserRoleLoader
 *
 * @package WPGraphQL\Data\Loader
 */
class UserRoleLoader extends AbstractDataLoader {

	/**
	 * {@inheritDoc}
	 *
	 * @return \WPGraphQL\Model\UserRole
	 */
	protected function get_model( $entry, $key ) {
		return new UserRole( $entry );
	}

	/**
	 * {@inheritDoc}
	 */
	public function loadKeys( array $keys ) {
		$wp_roles = wp_roles()->roles;

		$loaded = [];
		if ( ! empty( $wp_roles ) && is_array( $wp_roles ) ) {
			foreach ( $keys as $key ) {
				if ( isset( $wp_roles[ $key ] ) ) {
					$role                = $wp_roles[ $key ];
					$role['slug']        = $key;
					$role['id']          = $key;
					$role['displayName'] = $role['name'];
					$role['name']        = $key;
					$loaded[ $key ]      = $role;
				} else {
					$loaded[ $key ] = null;
				}
			}
		}

		return $loaded;
	}
}

```
