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