@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | * @return \WP_Error|\WP_REST_Response |
66 | 66 | */ |
67 | 67 | public function get_item( $request ) { |
68 | - $object = $this->get_object( (int) $request['id'] ); |
|
68 | + $object = $this->get_object( (int) $request[ 'id' ] ); |
|
69 | 69 | |
70 | 70 | if ( ! $object || 0 === $object->get_id() ) { |
71 | 71 | return new \WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'Invalid ID.', 'woocommerce-rest-api' ), array( 'status' => 404 ) ); |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | * @return \WP_Error|\WP_REST_Response |
111 | 111 | */ |
112 | 112 | public function create_item( $request ) { |
113 | - if ( ! empty( $request['id'] ) ) { |
|
113 | + if ( ! empty( $request[ 'id' ] ) ) { |
|
114 | 114 | /* translators: %s: post type */ |
115 | 115 | return new \WP_Error( "woocommerce_rest_{$this->post_type}_exists", sprintf( __( 'Cannot create existing %s.', 'woocommerce-rest-api' ), $this->post_type ), array( 'status' => 400 ) ); |
116 | 116 | } |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | * @return \WP_Error|\WP_REST_Response |
157 | 157 | */ |
158 | 158 | public function update_item( $request ) { |
159 | - $object = $this->get_object( (int) $request['id'] ); |
|
159 | + $object = $this->get_object( (int) $request[ 'id' ] ); |
|
160 | 160 | |
161 | 161 | if ( ! $object || 0 === $object->get_id() ) { |
162 | 162 | return new \WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'Invalid ID.', 'woocommerce-rest-api' ), array( 'status' => 404 ) ); |
@@ -199,42 +199,42 @@ discard block |
||
199 | 199 | */ |
200 | 200 | protected function prepare_objects_query( $request ) { |
201 | 201 | $args = array(); |
202 | - $args['offset'] = $request['offset']; |
|
203 | - $args['order'] = $request['order']; |
|
204 | - $args['orderby'] = $request['orderby']; |
|
205 | - $args['paged'] = $request['page']; |
|
206 | - $args['post__in'] = $request['include']; |
|
207 | - $args['post__not_in'] = $request['exclude']; |
|
208 | - $args['posts_per_page'] = $request['per_page']; |
|
209 | - $args['name'] = $request['slug']; |
|
210 | - $args['post_parent__in'] = $request['parent']; |
|
211 | - $args['post_parent__not_in'] = $request['parent_exclude']; |
|
212 | - $args['s'] = $request['search']; |
|
213 | - $args['fields'] = 'ids'; |
|
214 | - |
|
215 | - if ( 'date' === $args['orderby'] ) { |
|
216 | - $args['orderby'] = 'date ID'; |
|
202 | + $args[ 'offset' ] = $request[ 'offset' ]; |
|
203 | + $args[ 'order' ] = $request[ 'order' ]; |
|
204 | + $args[ 'orderby' ] = $request[ 'orderby' ]; |
|
205 | + $args[ 'paged' ] = $request[ 'page' ]; |
|
206 | + $args[ 'post__in' ] = $request[ 'include' ]; |
|
207 | + $args[ 'post__not_in' ] = $request[ 'exclude' ]; |
|
208 | + $args[ 'posts_per_page' ] = $request[ 'per_page' ]; |
|
209 | + $args[ 'name' ] = $request[ 'slug' ]; |
|
210 | + $args[ 'post_parent__in' ] = $request[ 'parent' ]; |
|
211 | + $args[ 'post_parent__not_in' ] = $request[ 'parent_exclude' ]; |
|
212 | + $args[ 's' ] = $request[ 'search' ]; |
|
213 | + $args[ 'fields' ] = 'ids'; |
|
214 | + |
|
215 | + if ( 'date' === $args[ 'orderby' ] ) { |
|
216 | + $args[ 'orderby' ] = 'date ID'; |
|
217 | 217 | } |
218 | 218 | |
219 | - $args['date_query'] = array(); |
|
219 | + $args[ 'date_query' ] = array(); |
|
220 | 220 | |
221 | 221 | // Set before into date query. Date query must be specified as an array of an array. |
222 | - if ( isset( $request['before'] ) ) { |
|
223 | - $args['date_query'][0]['before'] = $request['before']; |
|
222 | + if ( isset( $request[ 'before' ] ) ) { |
|
223 | + $args[ 'date_query' ][ 0 ][ 'before' ] = $request[ 'before' ]; |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | // Set after into date query. Date query must be specified as an array of an array. |
227 | - if ( isset( $request['after'] ) ) { |
|
228 | - $args['date_query'][0]['after'] = $request['after']; |
|
227 | + if ( isset( $request[ 'after' ] ) ) { |
|
228 | + $args[ 'date_query' ][ 0 ][ 'after' ] = $request[ 'after' ]; |
|
229 | 229 | } |
230 | 230 | |
231 | 231 | // Set date query colummn. Defaults to post_date. |
232 | - if ( isset( $request['date_column'] ) && ! empty( $args['date_query'][0] ) ) { |
|
233 | - $args['date_query'][0]['column'] = 'post_' . $request['date_column']; |
|
232 | + if ( isset( $request[ 'date_column' ] ) && ! empty( $args[ 'date_query' ][ 0 ] ) ) { |
|
233 | + $args[ 'date_query' ][ 0 ][ 'column' ] = 'post_' . $request[ 'date_column' ]; |
|
234 | 234 | } |
235 | 235 | |
236 | 236 | // Force the post_type argument, since it's not a user input variable. |
237 | - $args['post_type'] = $this->post_type; |
|
237 | + $args[ 'post_type' ] = $this->post_type; |
|
238 | 238 | |
239 | 239 | /** |
240 | 240 | * Filter the query arguments for a request. |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | $total_posts = $query->found_posts; |
265 | 265 | if ( $total_posts < 1 ) { |
266 | 266 | // Out-of-bounds, run the query again without LIMIT for total count. |
267 | - unset( $query_args['paged'] ); |
|
267 | + unset( $query_args[ 'paged' ] ); |
|
268 | 268 | $count_query = new \WP_Query(); |
269 | 269 | $count_query->query( $query_args ); |
270 | 270 | $total_posts = $count_query->found_posts; |
@@ -273,7 +273,7 @@ discard block |
||
273 | 273 | return array( |
274 | 274 | 'objects' => array_filter( array_map( array( $this, 'get_object' ), $result ) ), |
275 | 275 | 'total' => (int) $total_posts, |
276 | - 'pages' => (int) ceil( $total_posts / (int) $query->query_vars['posts_per_page'] ), |
|
276 | + 'pages' => (int) ceil( $total_posts / (int) $query->query_vars[ 'posts_per_page' ] ), |
|
277 | 277 | ); |
278 | 278 | } |
279 | 279 | |
@@ -288,17 +288,17 @@ discard block |
||
288 | 288 | $query_results = $this->get_objects( $query_args ); |
289 | 289 | |
290 | 290 | $objects = array(); |
291 | - foreach ( $query_results['objects'] as $object ) { |
|
291 | + foreach ( $query_results[ 'objects' ] as $object ) { |
|
292 | 292 | if ( ! Permissions::user_can_read( $this->post_type, $object->get_id() ) ) { |
293 | 293 | continue; |
294 | 294 | } |
295 | 295 | |
296 | 296 | $data = $this->prepare_item_for_response( $object, $request ); |
297 | - $objects[] = $this->prepare_response_for_collection( $data ); |
|
297 | + $objects[ ] = $this->prepare_response_for_collection( $data ); |
|
298 | 298 | } |
299 | 299 | |
300 | - $total = $query_results['total']; |
|
301 | - $max_pages = $query_results['pages']; |
|
300 | + $total = $query_results[ 'total' ]; |
|
301 | + $max_pages = $query_results[ 'pages' ]; |
|
302 | 302 | |
303 | 303 | $response = rest_ensure_response( $objects ); |
304 | 304 | $response = Pagination::add_pagination_headers( $response, $request, $total, $max_pages ); |
@@ -313,8 +313,8 @@ discard block |
||
313 | 313 | * @return \WP_REST_Response|\WP_Error |
314 | 314 | */ |
315 | 315 | public function delete_item( $request ) { |
316 | - $force = (bool) $request['force']; |
|
317 | - $object = $this->get_object( (int) $request['id'] ); |
|
316 | + $force = (bool) $request[ 'force' ]; |
|
317 | + $object = $this->get_object( (int) $request[ 'id' ] ); |
|
318 | 318 | $result = false; |
319 | 319 | |
320 | 320 | if ( ! $object || 0 === $object->get_id() ) { |
@@ -424,10 +424,10 @@ discard block |
||
424 | 424 | */ |
425 | 425 | public function get_collection_params() { |
426 | 426 | $params = array(); |
427 | - $params['context'] = $this->get_context_param(); |
|
428 | - $params['context']['default'] = 'view'; |
|
427 | + $params[ 'context' ] = $this->get_context_param(); |
|
428 | + $params[ 'context' ][ 'default' ] = 'view'; |
|
429 | 429 | |
430 | - $params['page'] = array( |
|
430 | + $params[ 'page' ] = array( |
|
431 | 431 | 'description' => __( 'Current page of the collection.', 'woocommerce-rest-api' ), |
432 | 432 | 'type' => 'integer', |
433 | 433 | 'default' => 1, |
@@ -436,7 +436,7 @@ discard block |
||
436 | 436 | 'minimum' => 1, |
437 | 437 | ); |
438 | 438 | |
439 | - $params['per_page'] = array( |
|
439 | + $params[ 'per_page' ] = array( |
|
440 | 440 | 'description' => __( 'Maximum number of items to be returned in result set.', 'woocommerce-rest-api' ), |
441 | 441 | 'type' => 'integer', |
442 | 442 | 'default' => 10, |
@@ -446,28 +446,28 @@ discard block |
||
446 | 446 | 'validate_callback' => 'rest_validate_request_arg', |
447 | 447 | ); |
448 | 448 | |
449 | - $params['search'] = array( |
|
449 | + $params[ 'search' ] = array( |
|
450 | 450 | 'description' => __( 'Limit results to those matching a string.', 'woocommerce-rest-api' ), |
451 | 451 | 'type' => 'string', |
452 | 452 | 'sanitize_callback' => 'sanitize_text_field', |
453 | 453 | 'validate_callback' => 'rest_validate_request_arg', |
454 | 454 | ); |
455 | 455 | |
456 | - $params['after'] = array( |
|
456 | + $params[ 'after' ] = array( |
|
457 | 457 | 'description' => __( 'Limit response to resources created after a given ISO8601 compliant date.', 'woocommerce-rest-api' ), |
458 | 458 | 'type' => 'string', |
459 | 459 | 'format' => 'date-time', |
460 | 460 | 'validate_callback' => 'rest_validate_request_arg', |
461 | 461 | ); |
462 | 462 | |
463 | - $params['before'] = array( |
|
463 | + $params[ 'before' ] = array( |
|
464 | 464 | 'description' => __( 'Limit response to resources created before a given ISO8601 compliant date.', 'woocommerce-rest-api' ), |
465 | 465 | 'type' => 'string', |
466 | 466 | 'format' => 'date-time', |
467 | 467 | 'validate_callback' => 'rest_validate_request_arg', |
468 | 468 | ); |
469 | 469 | |
470 | - $params['date_column'] = array( |
|
470 | + $params[ 'date_column' ] = array( |
|
471 | 471 | 'description' => __( 'When limiting response using after/before, which date column to compare against.', 'woocommerce-rest-api' ), |
472 | 472 | 'type' => 'string', |
473 | 473 | 'default' => 'date', |
@@ -480,14 +480,14 @@ discard block |
||
480 | 480 | 'validate_callback' => 'rest_validate_request_arg', |
481 | 481 | ); |
482 | 482 | |
483 | - $params['modified_before'] = array( |
|
483 | + $params[ 'modified_before' ] = array( |
|
484 | 484 | 'description' => __( 'Limit response to resources modified before a given ISO8601 compliant date.', 'woocommerce-rest-api' ), |
485 | 485 | 'type' => 'string', |
486 | 486 | 'format' => 'date-time', |
487 | 487 | 'validate_callback' => 'rest_validate_request_arg', |
488 | 488 | ); |
489 | 489 | |
490 | - $params['exclude'] = array( |
|
490 | + $params[ 'exclude' ] = array( |
|
491 | 491 | 'description' => __( 'Ensure result set excludes specific IDs.', 'woocommerce-rest-api' ), |
492 | 492 | 'type' => 'array', |
493 | 493 | 'items' => array( |
@@ -497,7 +497,7 @@ discard block |
||
497 | 497 | 'sanitize_callback' => 'wp_parse_id_list', |
498 | 498 | ); |
499 | 499 | |
500 | - $params['include'] = array( |
|
500 | + $params[ 'include' ] = array( |
|
501 | 501 | 'description' => __( 'Limit result set to specific ids.', 'woocommerce-rest-api' ), |
502 | 502 | 'type' => 'array', |
503 | 503 | 'items' => array( |
@@ -507,14 +507,14 @@ discard block |
||
507 | 507 | 'sanitize_callback' => 'wp_parse_id_list', |
508 | 508 | ); |
509 | 509 | |
510 | - $params['offset'] = array( |
|
510 | + $params[ 'offset' ] = array( |
|
511 | 511 | 'description' => __( 'Offset the result set by a specific number of items.', 'woocommerce-rest-api' ), |
512 | 512 | 'type' => 'integer', |
513 | 513 | 'sanitize_callback' => 'absint', |
514 | 514 | 'validate_callback' => 'rest_validate_request_arg', |
515 | 515 | ); |
516 | 516 | |
517 | - $params['order'] = array( |
|
517 | + $params[ 'order' ] = array( |
|
518 | 518 | 'description' => __( 'Order sort attribute ascending or descending.', 'woocommerce-rest-api' ), |
519 | 519 | 'type' => 'string', |
520 | 520 | 'default' => 'desc', |
@@ -522,7 +522,7 @@ discard block |
||
522 | 522 | 'validate_callback' => 'rest_validate_request_arg', |
523 | 523 | ); |
524 | 524 | |
525 | - $params['orderby'] = array( |
|
525 | + $params[ 'orderby' ] = array( |
|
526 | 526 | 'description' => __( 'Sort collection by object attribute.', 'woocommerce-rest-api' ), |
527 | 527 | 'type' => 'string', |
528 | 528 | 'default' => 'date', |
@@ -538,7 +538,7 @@ discard block |
||
538 | 538 | ); |
539 | 539 | |
540 | 540 | if ( $this->hierarchical ) { |
541 | - $params['parent'] = array( |
|
541 | + $params[ 'parent' ] = array( |
|
542 | 542 | 'description' => __( 'Limit result set to those of particular parent IDs.', 'woocommerce-rest-api' ), |
543 | 543 | 'type' => 'array', |
544 | 544 | 'items' => array( |
@@ -548,7 +548,7 @@ discard block |
||
548 | 548 | 'default' => array(), |
549 | 549 | ); |
550 | 550 | |
551 | - $params['parent_exclude'] = array( |
|
551 | + $params[ 'parent_exclude' ] = array( |
|
552 | 552 | 'description' => __( 'Limit result set to all items except those of a particular parent ID.', 'woocommerce-rest-api' ), |
553 | 553 | 'type' => 'array', |
554 | 554 | 'items' => array( |
@@ -599,14 +599,14 @@ discard block |
||
599 | 599 | } |
600 | 600 | } |
601 | 601 | |
602 | - $query_args['ignore_sticky_posts'] = true; |
|
602 | + $query_args[ 'ignore_sticky_posts' ] = true; |
|
603 | 603 | |
604 | - if ( 'include' === $query_args['orderby'] ) { |
|
605 | - $query_args['orderby'] = 'post__in'; |
|
606 | - } elseif ( 'id' === $query_args['orderby'] ) { |
|
607 | - $query_args['orderby'] = 'ID'; // ID must be capitalized. |
|
608 | - } elseif ( 'slug' === $query_args['orderby'] ) { |
|
609 | - $query_args['orderby'] = 'name'; |
|
604 | + if ( 'include' === $query_args[ 'orderby' ] ) { |
|
605 | + $query_args[ 'orderby' ] = 'post__in'; |
|
606 | + } elseif ( 'id' === $query_args[ 'orderby' ] ) { |
|
607 | + $query_args[ 'orderby' ] = 'ID'; // ID must be capitalized. |
|
608 | + } elseif ( 'slug' === $query_args[ 'orderby' ] ) { |
|
609 | + $query_args[ 'orderby' ] = 'name'; |
|
610 | 610 | } |
611 | 611 | |
612 | 612 | return $query_args; |
@@ -694,13 +694,13 @@ discard block |
||
694 | 694 | * @return array |
695 | 695 | */ |
696 | 696 | protected function add_meta_query( $args, $meta_query ) { |
697 | - if ( empty( $args['meta_query'] ) ) { |
|
698 | - $args['meta_query'] = []; // phpcs:ignore |
|
697 | + if ( empty( $args[ 'meta_query' ] ) ) { |
|
698 | + $args[ 'meta_query' ] = [ ]; // phpcs:ignore |
|
699 | 699 | } |
700 | 700 | |
701 | - $args['meta_query'][] = $meta_query; |
|
701 | + $args[ 'meta_query' ][ ] = $meta_query; |
|
702 | 702 | |
703 | - return $args['meta_query']; |
|
703 | + return $args[ 'meta_query' ]; |
|
704 | 704 | } |
705 | 705 | |
706 | 706 | /** |