1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
<?php
namespace WPGraphQL\Type\User\Connection;
use GraphQL\Type\Definition\EnumType;
use WPGraphQL\Type\WPEnumType;
use WPGraphQL\Type\WPInputObjectType;
use WPGraphQL\Types;
class UserConnectionArgs extends WPInputObjectType {
public static $fields;
private static $roles_enum;
private static $search_columns_enum;
public function __construct( $config = [] ) {
$config['name'] = 'UserArgs';
$config['fields'] = self::fields();
parent::__construct( $config );
}
private static function fields() {
if ( null === self::$fields ) :
$fields = [
'role' => [
'type' => self::roles_enum(),
'description' => __( 'An array of role names that users must match to be included in results. Note that this is an inclusive list: users must match *each* role.', 'wp-graphql' ),
],
'roleIn' => [
'type' => Types::list_of( self::roles_enum() ),
'description' => __( 'An array of role names. Matched users must have at least one of these roles.', 'wp-graphql' ),
],
'roleNotIn' => [
'type' => Types::list_of( self::roles_enum() ),
'description' => __( 'An array of role names to exclude. Users matching one or more of these roles will not be included in results.', 'wp-graphql' ),
],
'include' => [
'type' => Types::list_of( Types::int() ),
'description' => __( 'Array of comment IDs to include.', 'wp-graphql' ),
],
'exclude' => [
'type' => Types::list_of( Types::int() ),
'description' => __( 'Array of IDs of users whose unapproved comments will be returned by the query regardless of status.', 'wp-graphql' ),
],
'search' => [
'type' => Types::string(),
'description' => __( 'Search keyword. Searches for possible string matches on columns. When `searchColumns` is left empty, it tries to determine which column to search in based on search string.', 'wp-graphql' ),
],
'searchColumns' => [
'type' => Types::list_of( self::search_columns_enum() ),
'description' => __( 'Array of column names to be searched. Accepts \'ID\', \'login\', \'nicename\', \'email\', \'url\'.', 'wp-graphql' ),
],
'hasPublishedPosts' => [
'type' => Types::list_of( Types::post_type_enum() ),
'description' => __( 'Pass an array of post types to filter results to users who have published posts in those post types.', 'wp-graphql' ),
],
'nicename' => [
'type' => Types::int(),
'description' => __( 'The user nicename.', 'wp-graphql' ),
],
'nicenameIn' => [
'type' => Types::list_of( Types::string() ),
'description' => __( 'An array of nicenames to include. Users matching one of these nicenames will be included in results.', 'wp-graphql' ),
],
'nicenameNotIn' => [
'type' => Types::list_of( Types::string() ),
'description' => __( 'An array of nicenames to exclude. Users matching one of these nicenames will not be included in results.', 'wp-graphql' ),
],
'login' => [
'type' => Types::string(),
'description' => __( 'The user login.', 'wp-graphql' ),
],
'loginIn' => [
'type' => Types::int(),
'description' => __( 'An array of logins to include. Users matching one of these logins will be included in results.', 'wp-graphql' ),
],
'loginNotIn' => [
'type' => Types::int(),
'description' => __( 'An array of logins to exclude. Users matching one of these logins will not be included in results.', 'wp-graphql' ),
],
];
self::$fields = self::prepare_fields( $fields, 'UserArgs' );
endif;
return self::$fields;
}
private static function search_columns_enum() {
if ( null === self::$search_columns_enum ) :
self::$search_columns_enum = new WPEnumType([
'name' => 'SearchColumnsEnum',
'values' => [
'ID' => [
'value' => 'ID',
],
'LOGIN' => [
'value' => 'login',
],
'NICENAME' => [
'value' => 'nicename',
],
'EMAIL' => [
'value' => 'email',
],
'URL' => [
'value' => 'url',
],
],
]);
endif;
return self::$search_columns_enum;
}
private static function roles_enum() {
if ( null === self::$roles_enum ) :
global $wp_roles;
$all_roles = $wp_roles->roles;
$editable_roles = apply_filters( 'editable_roles', $all_roles );
$roles = [];
if ( ! empty( $editable_roles ) && is_array( $editable_roles ) ) {
foreach ( $editable_roles as $key => $role ) {
$formatted_role = self::format_enum_name( $role['name'] );
$roles[ $formatted_role ] = [
'value' => $key,
];
}
}
if ( ! empty( $roles ) ) {
self::$roles_enum = new WPEnumType( [
'name' => 'UserRoleEnum',
'values' => $roles,
] );
}
endif;
return self::$roles_enum;
}
}