PluginProbe
WPGraphQL / trunk
WPGraphQL vtrunk
2.22.3 2.22.2 2.22.1 2.22.0 2.21.1 2.21.0 2.20.0 2.19.0 2.18.0 2.17.0 2.16.0 2.15.1 2.15.0 2.14.1 2.14.0 2.13.0 2.2.0 2.3.0 2.3.3 2.3.6 2.3.8 2.5.0 2.5.1 2.5.2 2.5.3 All 177 releases
wp-graphql / src / Data / Loader / UserRoleLoader.php

UserRoleLoader.php in WPGraphQL trunk, at src/Data/Loader/UserRoleLoader.php

48 lines 904 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WPGraphQL\Data\Loader;
4
5 use WPGraphQL\Model\UserRole;
6
7 /**
8 * Class UserRoleLoader
9 *
10 * @package WPGraphQL\Data\Loader
11 */
12 class UserRoleLoader extends AbstractDataLoader {
13
14 /**
15 * {@inheritDoc}
16 *
17 * @return \WPGraphQL\Model\UserRole
18 */
19 protected function get_model( $entry, $key ) {
20 return new UserRole( $entry );
21 }
22
23 /**
24 * {@inheritDoc}
25 */
26 public function loadKeys( array $keys ) {
27 $wp_roles = wp_roles()->roles;
28
29 $loaded = [];
30 if ( ! empty( $wp_roles ) && is_array( $wp_roles ) ) {
31 foreach ( $keys as $key ) {
32 if ( isset( $wp_roles[ $key ] ) ) {
33 $role = $wp_roles[ $key ];
34 $role['slug'] = $key;
35 $role['id'] = $key;
36 $role['displayName'] = $role['name'];
37 $role['name'] = $key;
38 $loaded[ $key ] = $role;
39 } else {
40 $loaded[ $key ] = null;
41 }
42 }
43 }
44
45 return $loaded;
46 }
47 }
48