- Timestamp:
- 11/30/2017 11:09:33 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php
r41760 r42343 46 46 public function register_routes() { 47 47 48 register_rest_route( $this->namespace, '/' . $this->rest_base, array( 49 array( 50 'methods' => WP_REST_Server::READABLE, 51 'callback' => array( $this, 'get_items' ), 52 'permission_callback' => array( $this, 'get_items_permissions_check' ), 53 'args' => $this->get_collection_params(), 54 ), 55 array( 56 'methods' => WP_REST_Server::CREATABLE, 57 'callback' => array( $this, 'create_item' ), 58 'permission_callback' => array( $this, 'create_item_permissions_check' ), 59 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), 60 ), 61 'schema' => array( $this, 'get_public_item_schema' ), 62 ) ); 63 64 register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array( 65 'args' => array( 66 'id' => array( 67 'description' => __( 'Unique identifier for the user.' ), 68 'type' => 'integer', 69 ), 70 ), 71 array( 72 'methods' => WP_REST_Server::READABLE, 73 'callback' => array( $this, 'get_item' ), 74 'permission_callback' => array( $this, 'get_item_permissions_check' ), 75 'args' => array( 76 'context' => $this->get_context_param( array( 'default' => 'view' ) ), 77 ), 78 ), 79 array( 80 'methods' => WP_REST_Server::EDITABLE, 81 'callback' => array( $this, 'update_item' ), 82 'permission_callback' => array( $this, 'update_item_permissions_check' ), 83 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), 84 ), 85 array( 86 'methods' => WP_REST_Server::DELETABLE, 87 'callback' => array( $this, 'delete_item' ), 88 'permission_callback' => array( $this, 'delete_item_permissions_check' ), 89 'args' => array( 90 'force' => array( 91 'type' => 'boolean', 92 'default' => false, 93 'description' => __( 'Required to be true, as users do not support trashing.' ), 48 register_rest_route( 49 $this->namespace, '/' . $this->rest_base, array( 50 array( 51 'methods' => WP_REST_Server::READABLE, 52 'callback' => array( $this, 'get_items' ), 53 'permission_callback' => array( $this, 'get_items_permissions_check' ), 54 'args' => $this->get_collection_params(), 55 ), 56 array( 57 'methods' => WP_REST_Server::CREATABLE, 58 'callback' => array( $this, 'create_item' ), 59 'permission_callback' => array( $this, 'create_item_permissions_check' ), 60 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), 61 ), 62 'schema' => array( $this, 'get_public_item_schema' ), 63 ) 64 ); 65 66 register_rest_route( 67 $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array( 68 'args' => array( 69 'id' => array( 70 'description' => __( 'Unique identifier for the user.' ), 71 'type' => 'integer', 94 72 ), 95 'reassign' => array( 96 'type' => 'integer', 97 'description' => __( 'Reassign the deleted user\'s posts and links to this user ID.' ), 98 'required' => true, 99 'sanitize_callback' => array( $this, 'check_reassign' ), 73 ), 74 array( 75 'methods' => WP_REST_Server::READABLE, 76 'callback' => array( $this, 'get_item' ), 77 'permission_callback' => array( $this, 'get_item_permissions_check' ), 78 'args' => array( 79 'context' => $this->get_context_param( array( 'default' => 'view' ) ), 100 80 ), 101 81 ), 102 ), 103 'schema' => array( $this, 'get_public_item_schema' ), 104 ) ); 105 106 register_rest_route( $this->namespace, '/' . $this->rest_base . '/me', array( 107 array( 108 'methods' => WP_REST_Server::READABLE, 109 'callback' => array( $this, 'get_current_item' ), 110 'args' => array( 111 'context' => $this->get_context_param( array( 'default' => 'view' ) ), 112 ), 113 ), 114 array( 115 'methods' => WP_REST_Server::EDITABLE, 116 'callback' => array( $this, 'update_current_item' ), 117 'permission_callback' => array( $this, 'update_current_item_permissions_check' ), 118 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), 119 ), 120 array( 121 'methods' => WP_REST_Server::DELETABLE, 122 'callback' => array( $this, 'delete_current_item' ), 123 'permission_callback' => array( $this, 'delete_current_item_permissions_check' ), 124 'args' => array( 125 'force' => array( 126 'type' => 'boolean', 127 'default' => false, 128 'description' => __( 'Required to be true, as users do not support trashing.' ), 82 array( 83 'methods' => WP_REST_Server::EDITABLE, 84 'callback' => array( $this, 'update_item' ), 85 'permission_callback' => array( $this, 'update_item_permissions_check' ), 86 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), 87 ), 88 array( 89 'methods' => WP_REST_Server::DELETABLE, 90 'callback' => array( $this, 'delete_item' ), 91 'permission_callback' => array( $this, 'delete_item_permissions_check' ), 92 'args' => array( 93 'force' => array( 94 'type' => 'boolean', 95 'default' => false, 96 'description' => __( 'Required to be true, as users do not support trashing.' ), 97 ), 98 'reassign' => array( 99 'type' => 'integer', 100 'description' => __( 'Reassign the deleted user\'s posts and links to this user ID.' ), 101 'required' => true, 102 'sanitize_callback' => array( $this, 'check_reassign' ), 103 ), 129 104 ), 130 'reassign' => array( 131 'type' => 'integer', 132 'description' => __( 'Reassign the deleted user\'s posts and links to this user ID.' ), 133 'required' => true, 134 'sanitize_callback' => array( $this, 'check_reassign' ), 105 ), 106 'schema' => array( $this, 'get_public_item_schema' ), 107 ) 108 ); 109 110 register_rest_route( 111 $this->namespace, '/' . $this->rest_base . '/me', array( 112 array( 113 'methods' => WP_REST_Server::READABLE, 114 'callback' => array( $this, 'get_current_item' ), 115 'args' => array( 116 'context' => $this->get_context_param( array( 'default' => 'view' ) ), 135 117 ), 136 118 ), 137 ), 138 'schema' => array( $this, 'get_public_item_schema' ), 139 )); 119 array( 120 'methods' => WP_REST_Server::EDITABLE, 121 'callback' => array( $this, 'update_current_item' ), 122 'permission_callback' => array( $this, 'update_current_item_permissions_check' ), 123 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), 124 ), 125 array( 126 'methods' => WP_REST_Server::DELETABLE, 127 'callback' => array( $this, 'delete_current_item' ), 128 'permission_callback' => array( $this, 'delete_current_item_permissions_check' ), 129 'args' => array( 130 'force' => array( 131 'type' => 'boolean', 132 'default' => false, 133 'description' => __( 'Required to be true, as users do not support trashing.' ), 134 ), 135 'reassign' => array( 136 'type' => 'integer', 137 'description' => __( 'Reassign the deleted user\'s posts and links to this user ID.' ), 138 'required' => true, 139 'sanitize_callback' => array( $this, 'check_reassign' ), 140 ), 141 ), 142 ), 143 'schema' => array( $this, 'get_public_item_schema' ), 144 ) 145 ); 140 146 } 141 147 … … 234 240 $prepared_args['offset'] = $request['offset']; 235 241 } else { 236 $prepared_args['offset'] 242 $prepared_args['offset'] = ( $request['page'] - 1 ) * $prepared_args['number']; 237 243 } 238 244 239 245 if ( isset( $registered['orderby'] ) ) { 240 $orderby_possibles = array(246 $orderby_possibles = array( 241 247 'id' => 'ID', 242 248 'include' => 'include', … … 275 281 276 282 foreach ( $query->results as $user ) { 277 $data = $this->prepare_item_for_response( $user, $request );283 $data = $this->prepare_item_for_response( $user, $request ); 278 284 $users[] = $this->prepare_response_for_collection( $data ); 279 285 } … … 392 398 } 393 399 394 $user = $this->prepare_item_for_response( $user, $request );400 $user = $this->prepare_item_for_response( $user, $request ); 395 401 $response = rest_ensure_response( $user ); 396 402 … … 416 422 $response = $this->prepare_item_for_response( $user, $request ); 417 423 $response = rest_ensure_response( $response ); 418 419 424 420 425 return $response; … … 494 499 } 495 500 496 $result = add_user_to_blog( get_site()->id, $user_id, '' );501 $result = add_user_to_blog( get_site()->id, $user_id, '' ); 497 502 if ( is_wp_error( $result ) ) { 498 503 return $result; … … 531 536 } 532 537 533 $user = get_user_by( 'id', $user_id );538 $user = get_user_by( 'id', $user_id ); 534 539 $fields_update = $this->update_additional_fields_for_object( $user, $request ); 535 540 … … 654 659 } 655 660 656 $user = get_user_by( 'id', $user_id );661 $user = get_user_by( 'id', $user_id ); 657 662 $fields_update = $this->update_additional_fields_for_object( $user, $request ); 658 663 … … 766 771 767 772 $response = new WP_REST_Response(); 768 $response->set_data( array( 'deleted' => true, 'previous' => $previous->get_data() ) ); 773 $response->set_data( 774 array( 775 'deleted' => true, 776 'previous' => $previous->get_data(), 777 ) 778 ); 769 779 770 780 /** … … 929 939 protected function prepare_links( $user ) { 930 940 $links = array( 931 'self' => array(941 'self' => array( 932 942 'href' => rest_url( sprintf( '%s/%s/%d', $this->namespace, $this->rest_base, $user->ID ) ), 933 943 ), … … 1115 1125 } 1116 1126 1117 if ( false !== strpos( $password, "\\") ) {1127 if ( false !== strpos( $password, '\\' ) ) { 1118 1128 return new WP_Error( 'rest_user_invalid_password', __( 'Passwords cannot contain the "\\" character.' ), array( 'status' => 400 ) ); 1119 1129 } … … 1135 1145 'type' => 'object', 1136 1146 'properties' => array( 1137 'id' => array(1147 'id' => array( 1138 1148 'description' => __( 'Unique identifier for the user.' ), 1139 1149 'type' => 'integer', … … 1141 1151 'readonly' => true, 1142 1152 ), 1143 'username' => array(1153 'username' => array( 1144 1154 'description' => __( 'Login name for the user.' ), 1145 1155 'type' => 'string', … … 1150 1160 ), 1151 1161 ), 1152 'name' => array(1162 'name' => array( 1153 1163 'description' => __( 'Display name for the user.' ), 1154 1164 'type' => 'string', … … 1158 1168 ), 1159 1169 ), 1160 'first_name' => array(1170 'first_name' => array( 1161 1171 'description' => __( 'First name for the user.' ), 1162 1172 'type' => 'string', … … 1166 1176 ), 1167 1177 ), 1168 'last_name' => array(1178 'last_name' => array( 1169 1179 'description' => __( 'Last name for the user.' ), 1170 1180 'type' => 'string', … … 1174 1184 ), 1175 1185 ), 1176 'email' => array(1186 'email' => array( 1177 1187 'description' => __( 'The email address for the user.' ), 1178 1188 'type' => 'string', … … 1181 1191 'required' => true, 1182 1192 ), 1183 'url' => array(1193 'url' => array( 1184 1194 'description' => __( 'URL of the user.' ), 1185 1195 'type' => 'string', … … 1187 1197 'context' => array( 'embed', 'view', 'edit' ), 1188 1198 ), 1189 'description' => array(1199 'description' => array( 1190 1200 'description' => __( 'Description of the user.' ), 1191 1201 'type' => 'string', 1192 1202 'context' => array( 'embed', 'view', 'edit' ), 1193 1203 ), 1194 'link' => array(1204 'link' => array( 1195 1205 'description' => __( 'Author URL of the user.' ), 1196 1206 'type' => 'string', … … 1199 1209 'readonly' => true, 1200 1210 ), 1201 'locale' => array(1211 'locale' => array( 1202 1212 'description' => __( 'Locale for the user.' ), 1203 1213 'type' => 'string', … … 1205 1215 'context' => array( 'edit' ), 1206 1216 ), 1207 'nickname' => array(1217 'nickname' => array( 1208 1218 'description' => __( 'The nickname for the user.' ), 1209 1219 'type' => 'string', … … 1213 1223 ), 1214 1224 ), 1215 'slug' => array(1225 'slug' => array( 1216 1226 'description' => __( 'An alphanumeric identifier for the user.' ), 1217 1227 'type' => 'string', … … 1221 1231 ), 1222 1232 ), 1223 'registered_date' => array(1233 'registered_date' => array( 1224 1234 'description' => __( 'Registration date for the user.' ), 1225 1235 'type' => 'string', … … 1228 1238 'readonly' => true, 1229 1239 ), 1230 'roles' => array(1240 'roles' => array( 1231 1241 'description' => __( 'Roles assigned to the user.' ), 1232 1242 'type' => 'array', 1233 1243 'items' => array( 1234 'type' 1244 'type' => 'string', 1235 1245 ), 1236 1246 'context' => array( 'edit' ), 1237 1247 ), 1238 'password' => array(1248 'password' => array( 1239 1249 'description' => __( 'Password for the user (never included).' ), 1240 1250 'type' => 'string', … … 1245 1255 ), 1246 1256 ), 1247 'capabilities' => array(1257 'capabilities' => array( 1248 1258 'description' => __( 'All capabilities assigned to the user.' ), 1249 1259 'type' => 'object', … … 1275 1285 } 1276 1286 1277 $schema['properties']['avatar_urls'] 1287 $schema['properties']['avatar_urls'] = array( 1278 1288 'description' => __( 'Avatar URLs for the user.' ), 1279 1289 'type' => 'object', … … 1302 1312 1303 1313 $query_params['exclude'] = array( 1304 'description' 1305 'type' 1306 'items' 1307 'type' 1314 'description' => __( 'Ensure result set excludes specific IDs.' ), 1315 'type' => 'array', 1316 'items' => array( 1317 'type' => 'integer', 1308 1318 ), 1309 'default' 1319 'default' => array(), 1310 1320 ); 1311 1321 1312 1322 $query_params['include'] = array( 1313 'description' 1314 'type' 1315 'items' 1316 'type' 1323 'description' => __( 'Limit result set to specific IDs.' ), 1324 'type' => 'array', 1325 'items' => array( 1326 'type' => 'integer', 1317 1327 ), 1318 'default' 1328 'default' => array(), 1319 1329 ); 1320 1330 1321 1331 $query_params['offset'] = array( 1322 'description' 1323 'type' 1332 'description' => __( 'Offset the result set by a specific number of items.' ), 1333 'type' => 'integer', 1324 1334 ); 1325 1335 1326 1336 $query_params['order'] = array( 1327 'default' 1328 'description' 1329 'enum' 1330 'type' 1337 'default' => 'asc', 1338 'description' => __( 'Order sort attribute ascending or descending.' ), 1339 'enum' => array( 'asc', 'desc' ), 1340 'type' => 'string', 1331 1341 ); 1332 1342 1333 1343 $query_params['orderby'] = array( 1334 'default' 1335 'description' 1336 'enum' 1344 'default' => 'name', 1345 'description' => __( 'Sort collection by object attribute.' ), 1346 'enum' => array( 1337 1347 'id', 1338 1348 'include', … … 1344 1354 'url', 1345 1355 ), 1346 'type' 1356 'type' => 'string', 1347 1357 ); 1348 1358 1349 $query_params['slug'] 1350 'description' 1351 'type' 1352 'items' 1353 'type' 1359 $query_params['slug'] = array( 1360 'description' => __( 'Limit result set to users with one or more specific slugs.' ), 1361 'type' => 'array', 1362 'items' => array( 1363 'type' => 'string', 1354 1364 ), 1355 1365 ); 1356 1366 1357 $query_params['roles'] 1358 'description' 1359 'type' 1360 'items' 1361 'type' 1367 $query_params['roles'] = array( 1368 'description' => __( 'Limit result set to users matching at least one specific role provided. Accepts csv list or single role.' ), 1369 'type' => 'array', 1370 'items' => array( 1371 'type' => 'string', 1362 1372 ), 1363 1373 );
Note: See TracChangeset
for help on using the changeset viewer.