@@ -176,29 +176,29 @@ discard block |
||
176 | 176 | } |
177 | 177 | } |
178 | 178 | |
179 | - if ( isset( $registered['orderby'] ) ) { |
|
180 | - $prepared_args['orderby'] = $this->normalize_query_param( $request['orderby'] ); |
|
179 | + if ( isset( $registered[ 'orderby' ] ) ) { |
|
180 | + $prepared_args[ 'orderby' ] = $this->normalize_query_param( $request[ 'orderby' ] ); |
|
181 | 181 | } |
182 | 182 | |
183 | - if ( isset( $prepared_args['status'] ) ) { |
|
184 | - $prepared_args['status'] = 'approved' === $prepared_args['status'] ? 'approve' : $prepared_args['status']; |
|
183 | + if ( isset( $prepared_args[ 'status' ] ) ) { |
|
184 | + $prepared_args[ 'status' ] = 'approved' === $prepared_args[ 'status' ] ? 'approve' : $prepared_args[ 'status' ]; |
|
185 | 185 | } |
186 | 186 | |
187 | - $prepared_args['no_found_rows'] = false; |
|
188 | - $prepared_args['date_query'] = array(); |
|
187 | + $prepared_args[ 'no_found_rows' ] = false; |
|
188 | + $prepared_args[ 'date_query' ] = array(); |
|
189 | 189 | |
190 | 190 | // Set before into date query. Date query must be specified as an array of an array. |
191 | - if ( isset( $registered['before'], $request['before'] ) ) { |
|
192 | - $prepared_args['date_query'][0]['before'] = $request['before']; |
|
191 | + if ( isset( $registered[ 'before' ], $request[ 'before' ] ) ) { |
|
192 | + $prepared_args[ 'date_query' ][ 0 ][ 'before' ] = $request[ 'before' ]; |
|
193 | 193 | } |
194 | 194 | |
195 | 195 | // Set after into date query. Date query must be specified as an array of an array. |
196 | - if ( isset( $registered['after'], $request['after'] ) ) { |
|
197 | - $prepared_args['date_query'][0]['after'] = $request['after']; |
|
196 | + if ( isset( $registered[ 'after' ], $request[ 'after' ] ) ) { |
|
197 | + $prepared_args[ 'date_query' ][ 0 ][ 'after' ] = $request[ 'after' ]; |
|
198 | 198 | } |
199 | 199 | |
200 | - if ( isset( $registered['page'] ) && empty( $request['offset'] ) ) { |
|
201 | - $prepared_args['offset'] = $prepared_args['number'] * ( absint( $request['page'] ) - 1 ); |
|
200 | + if ( isset( $registered[ 'page' ] ) && empty( $request[ 'offset' ] ) ) { |
|
201 | + $prepared_args[ 'offset' ] = $prepared_args[ 'number' ] * ( absint( $request[ 'page' ] ) - 1 ); |
|
202 | 202 | } |
203 | 203 | |
204 | 204 | /** |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | $prepared_args = apply_filters( 'woocommerce_rest_product_review_query', $prepared_args, $request ); |
213 | 213 | |
214 | 214 | // Make sure that returns only reviews. |
215 | - $prepared_args['type'] = 'review'; |
|
215 | + $prepared_args[ 'type' ] = 'review'; |
|
216 | 216 | |
217 | 217 | // Query reviews. |
218 | 218 | $query = new \WP_Comment_Query(); |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | } |
226 | 226 | |
227 | 227 | $data = $this->prepare_item_for_response( $review, $request ); |
228 | - $reviews[] = $this->prepare_response_for_collection( $data ); |
|
228 | + $reviews[ ] = $this->prepare_response_for_collection( $data ); |
|
229 | 229 | } |
230 | 230 | |
231 | 231 | $total_reviews = (int) $query->found_comments; |
@@ -233,13 +233,13 @@ discard block |
||
233 | 233 | |
234 | 234 | if ( $total_reviews < 1 ) { |
235 | 235 | // Out-of-bounds, run the query again without LIMIT for total count. |
236 | - unset( $prepared_args['number'], $prepared_args['offset'] ); |
|
236 | + unset( $prepared_args[ 'number' ], $prepared_args[ 'offset' ] ); |
|
237 | 237 | |
238 | 238 | $query = new \WP_Comment_Query(); |
239 | - $prepared_args['count'] = true; |
|
239 | + $prepared_args[ 'count' ] = true; |
|
240 | 240 | |
241 | 241 | $total_reviews = $query->query( $prepared_args ); |
242 | - $max_pages = ceil( $total_reviews / $request['per_page'] ); |
|
242 | + $max_pages = ceil( $total_reviews / $request[ 'per_page' ] ); |
|
243 | 243 | } |
244 | 244 | |
245 | 245 | $response = rest_ensure_response( $reviews ); |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | */ |
257 | 257 | public function create_item( $request ) { |
258 | 258 | try { |
259 | - if ( ! empty( $request['id'] ) ) { |
|
259 | + if ( ! empty( $request[ 'id' ] ) ) { |
|
260 | 260 | return new \WP_Error( 'woocommerce_rest_review_exists', __( 'Cannot create existing product review.', 'woocommerce-rest-api' ), array( 'status' => 400 ) ); |
261 | 261 | } |
262 | 262 | |
@@ -312,11 +312,11 @@ discard block |
||
312 | 312 | throw new \WC_REST_Exception( 'woocommerce_rest_review_failed_create', __( 'Creating product review failed.', 'woocommerce-rest-api' ), 500 ); |
313 | 313 | } |
314 | 314 | |
315 | - if ( isset( $request['status'] ) ) { |
|
316 | - $this->handle_status_param( $request['status'], $review_id ); |
|
315 | + if ( isset( $request[ 'status' ] ) ) { |
|
316 | + $this->handle_status_param( $request[ 'status' ], $review_id ); |
|
317 | 317 | } |
318 | 318 | |
319 | - update_comment_meta( $review_id, 'rating', ! empty( $request['rating'] ) ? $request['rating'] : '0' ); |
|
319 | + update_comment_meta( $review_id, 'rating', ! empty( $request[ 'rating' ] ) ? $request[ 'rating' ] : '0' ); |
|
320 | 320 | } catch ( \WC_REST_Exception $e ) { |
321 | 321 | return new \WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); |
322 | 322 | } |
@@ -358,12 +358,12 @@ discard block |
||
358 | 358 | * @return array |
359 | 359 | */ |
360 | 360 | protected function validate_review( $prepared_review, $creating = false ) { |
361 | - if ( empty( $prepared_review['comment_content'] ) ) { |
|
361 | + if ( empty( $prepared_review[ 'comment_content' ] ) ) { |
|
362 | 362 | throw new \WC_REST_Exception( 'woocommerce_rest_review_content_invalid', __( 'Invalid review content.', 'woocommerce-rest-api' ), 400 ); |
363 | 363 | } |
364 | 364 | |
365 | - if ( ! empty( $prepared_review['comment_post_ID'] ) ) { |
|
366 | - if ( 'product' !== get_post_type( $prepared_review['comment_post_ID'] ) ) { |
|
365 | + if ( ! empty( $prepared_review[ 'comment_post_ID' ] ) ) { |
|
366 | + if ( 'product' !== get_post_type( $prepared_review[ 'comment_post_ID' ] ) ) { |
|
367 | 367 | throw new \WC_REST_Exception( 'woocommerce_rest_product_invalid_id', __( 'Invalid product ID.', 'woocommerce-rest-api' ), 404 ); |
368 | 368 | } |
369 | 369 | } |
@@ -376,7 +376,7 @@ discard block |
||
376 | 376 | } |
377 | 377 | |
378 | 378 | if ( $creating ) { |
379 | - $prepared_review['comment_approved'] = $this->get_comment_approved( $prepared_review ); |
|
379 | + $prepared_review[ 'comment_approved' ] = $this->get_comment_approved( $prepared_review ); |
|
380 | 380 | } |
381 | 381 | |
382 | 382 | return $prepared_review; |
@@ -388,8 +388,8 @@ discard block |
||
388 | 388 | * @return string |
389 | 389 | */ |
390 | 390 | protected function get_comment_author_ip() { |
391 | - if ( ! empty( $_SERVER['REMOTE_ADDR'] ) && rest_is_ip_address( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) ) { // WPCS: input var ok, sanitization ok. |
|
392 | - return wc_clean( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ); // WPCS: input var ok. |
|
391 | + if ( ! empty( $_SERVER[ 'REMOTE_ADDR' ] ) && rest_is_ip_address( wp_unslash( $_SERVER[ 'REMOTE_ADDR' ] ) ) ) { // WPCS: input var ok, sanitization ok. |
|
392 | + return wc_clean( wp_unslash( $_SERVER[ 'REMOTE_ADDR' ] ) ); // WPCS: input var ok. |
|
393 | 393 | } else { |
394 | 394 | return '127.0.0.1'; |
395 | 395 | } |
@@ -402,8 +402,8 @@ discard block |
||
402 | 402 | * @return string |
403 | 403 | */ |
404 | 404 | protected function get_comment_agent( $request ) { |
405 | - if ( ! empty( $request['author_user_agent'] ) ) { |
|
406 | - return $request['author_user_agent']; |
|
405 | + if ( ! empty( $request[ 'author_user_agent' ] ) ) { |
|
406 | + return $request[ 'author_user_agent' ]; |
|
407 | 407 | } elseif ( $request->get_header( 'user_agent' ) ) { |
408 | 408 | return $request->get_header( 'user_agent' ); |
409 | 409 | } else { |
@@ -444,7 +444,7 @@ discard block |
||
444 | 444 | * @return \WP_Error|\WP_REST_Response |
445 | 445 | */ |
446 | 446 | public function get_item( $request ) { |
447 | - $review = $this->get_review( $request['id'] ); |
|
447 | + $review = $this->get_review( $request[ 'id' ] ); |
|
448 | 448 | if ( is_wp_error( $review ) ) { |
449 | 449 | return $review; |
450 | 450 | } |
@@ -460,7 +460,7 @@ discard block |
||
460 | 460 | */ |
461 | 461 | public function update_item( $request ) { |
462 | 462 | try { |
463 | - $review = $this->get_review( $request['id'] ); |
|
463 | + $review = $this->get_review( $request[ 'id' ] ); |
|
464 | 464 | |
465 | 465 | if ( is_wp_error( $review ) ) { |
466 | 466 | return $review; |
@@ -468,7 +468,7 @@ discard block |
||
468 | 468 | |
469 | 469 | $review_id = (int) $review->comment_ID; |
470 | 470 | |
471 | - if ( isset( $request['type'] ) && 'review' !== get_comment_type( $review_id ) ) { |
|
471 | + if ( isset( $request[ 'type' ] ) && 'review' !== get_comment_type( $review_id ) ) { |
|
472 | 472 | return new \WP_Error( 'woocommerce_rest_review_invalid_type', __( 'Sorry, you are not allowed to change the comment type.', 'woocommerce-rest-api' ), array( 'status' => 404 ) ); |
473 | 473 | } |
474 | 474 | |
@@ -493,12 +493,12 @@ discard block |
||
493 | 493 | |
494 | 494 | wp_update_comment( wp_slash( $prepared_review ) ); |
495 | 495 | |
496 | - if ( isset( $request['status'] ) ) { |
|
497 | - $this->handle_status_param( $request['status'], $review_id ); |
|
496 | + if ( isset( $request[ 'status' ] ) ) { |
|
497 | + $this->handle_status_param( $request[ 'status' ], $review_id ); |
|
498 | 498 | } |
499 | 499 | |
500 | - if ( ! empty( $request['rating'] ) ) { |
|
501 | - update_comment_meta( $review_id, 'rating', $request['rating'] ); |
|
500 | + if ( ! empty( $request[ 'rating' ] ) ) { |
|
501 | + update_comment_meta( $review_id, 'rating', $request[ 'rating' ] ); |
|
502 | 502 | } |
503 | 503 | } catch ( \WC_REST_Exception $e ) { |
504 | 504 | return new \WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); |
@@ -533,12 +533,12 @@ discard block |
||
533 | 533 | * @return \WP_Error|\WP_REST_Response Response object on success, or error object on failure. |
534 | 534 | */ |
535 | 535 | public function delete_item( $request ) { |
536 | - $review = $this->get_review( $request['id'] ); |
|
536 | + $review = $this->get_review( $request[ 'id' ] ); |
|
537 | 537 | if ( is_wp_error( $review ) ) { |
538 | 538 | return $review; |
539 | 539 | } |
540 | 540 | |
541 | - $force = isset( $request['force'] ) ? (bool) $request['force'] : false; |
|
541 | + $force = isset( $request[ 'force' ] ) ? (bool) $request[ 'force' ] : false; |
|
542 | 542 | |
543 | 543 | /** |
544 | 544 | * Filters whether a review can be trashed. |
@@ -634,17 +634,17 @@ discard block |
||
634 | 634 | $prepared_review[ $key ] = $request[ $value ]; |
635 | 635 | } |
636 | 636 | |
637 | - if ( ! empty( $request['date_created'] ) ) { |
|
638 | - $date_data = rest_get_date_with_gmt( $request['date_created'] ); |
|
637 | + if ( ! empty( $request[ 'date_created' ] ) ) { |
|
638 | + $date_data = rest_get_date_with_gmt( $request[ 'date_created' ] ); |
|
639 | 639 | |
640 | 640 | if ( ! empty( $date_data ) ) { |
641 | - list( $prepared_review['comment_date'], $prepared_review['comment_date_gmt'] ) = $date_data; |
|
641 | + list( $prepared_review[ 'comment_date' ], $prepared_review[ 'comment_date_gmt' ] ) = $date_data; |
|
642 | 642 | } |
643 | - } elseif ( ! empty( $request['date_created_gmt'] ) ) { |
|
644 | - $date_data = rest_get_date_with_gmt( $request['date_created_gmt'], true ); |
|
643 | + } elseif ( ! empty( $request[ 'date_created_gmt' ] ) ) { |
|
644 | + $date_data = rest_get_date_with_gmt( $request[ 'date_created_gmt' ], true ); |
|
645 | 645 | |
646 | 646 | if ( ! empty( $date_data ) ) { |
647 | - list( $prepared_review['comment_date'], $prepared_review['comment_date_gmt'] ) = $date_data; |
|
647 | + list( $prepared_review[ 'comment_date' ], $prepared_review[ 'comment_date_gmt' ] ) = $date_data; |
|
648 | 648 | } |
649 | 649 | } |
650 | 650 | |
@@ -668,13 +668,13 @@ discard block |
||
668 | 668 | ), |
669 | 669 | ); |
670 | 670 | if ( 0 !== (int) $item->comment_post_ID ) { |
671 | - $links['up'] = array( |
|
671 | + $links[ 'up' ] = array( |
|
672 | 672 | 'href' => rest_url( sprintf( '/%s/products/%d', $this->namespace, $item->comment_post_ID ) ), |
673 | 673 | 'embeddable' => true, |
674 | 674 | ); |
675 | 675 | } |
676 | 676 | if ( 0 !== (int) $item->user_id ) { |
677 | - $links['reviewer'] = array( |
|
677 | + $links[ 'reviewer' ] = array( |
|
678 | 678 | 'href' => rest_url( 'wp/v2/users/' . $item->user_id ), |
679 | 679 | 'embeddable' => true, |
680 | 680 | ); |
@@ -769,7 +769,7 @@ discard block |
||
769 | 769 | 'context' => array( 'embed', 'view', 'edit' ), |
770 | 770 | ); |
771 | 771 | } |
772 | - $schema['properties']['reviewer_avatar_urls'] = array( |
|
772 | + $schema[ 'properties' ][ 'reviewer_avatar_urls' ] = array( |
|
773 | 773 | 'description' => __( 'Avatar URLs for the object reviewer.', 'woocommerce-rest-api' ), |
774 | 774 | 'type' => 'object', |
775 | 775 | 'context' => array( 'view', 'edit' ), |
@@ -789,19 +789,19 @@ discard block |
||
789 | 789 | public function get_collection_params() { |
790 | 790 | $params = parent::get_collection_params(); |
791 | 791 | |
792 | - $params['context']['default'] = 'view'; |
|
792 | + $params[ 'context' ][ 'default' ] = 'view'; |
|
793 | 793 | |
794 | - $params['after'] = array( |
|
794 | + $params[ 'after' ] = array( |
|
795 | 795 | 'description' => __( 'Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce-rest-api' ), |
796 | 796 | 'type' => 'string', |
797 | 797 | 'format' => 'date-time', |
798 | 798 | ); |
799 | - $params['before'] = array( |
|
799 | + $params[ 'before' ] = array( |
|
800 | 800 | 'description' => __( 'Limit response to reviews published before a given ISO8601 compliant date.', 'woocommerce-rest-api' ), |
801 | 801 | 'type' => 'string', |
802 | 802 | 'format' => 'date-time', |
803 | 803 | ); |
804 | - $params['exclude'] = array( |
|
804 | + $params[ 'exclude' ] = array( |
|
805 | 805 | 'description' => __( 'Ensure result set excludes specific IDs.', 'woocommerce-rest-api' ), |
806 | 806 | 'type' => 'array', |
807 | 807 | 'items' => array( |
@@ -809,7 +809,7 @@ discard block |
||
809 | 809 | ), |
810 | 810 | 'default' => array(), |
811 | 811 | ); |
812 | - $params['include'] = array( |
|
812 | + $params[ 'include' ] = array( |
|
813 | 813 | 'description' => __( 'Limit result set to specific IDs.', 'woocommerce-rest-api' ), |
814 | 814 | 'type' => 'array', |
815 | 815 | 'items' => array( |
@@ -817,11 +817,11 @@ discard block |
||
817 | 817 | ), |
818 | 818 | 'default' => array(), |
819 | 819 | ); |
820 | - $params['offset'] = array( |
|
820 | + $params[ 'offset' ] = array( |
|
821 | 821 | 'description' => __( 'Offset the result set by a specific number of items.', 'woocommerce-rest-api' ), |
822 | 822 | 'type' => 'integer', |
823 | 823 | ); |
824 | - $params['order'] = array( |
|
824 | + $params[ 'order' ] = array( |
|
825 | 825 | 'description' => __( 'Order sort attribute ascending or descending.', 'woocommerce-rest-api' ), |
826 | 826 | 'type' => 'string', |
827 | 827 | 'default' => 'desc', |
@@ -830,7 +830,7 @@ discard block |
||
830 | 830 | 'desc', |
831 | 831 | ), |
832 | 832 | ); |
833 | - $params['orderby'] = array( |
|
833 | + $params[ 'orderby' ] = array( |
|
834 | 834 | 'description' => __( 'Sort collection by object attribute.', 'woocommerce-rest-api' ), |
835 | 835 | 'type' => 'string', |
836 | 836 | 'default' => 'date_gmt', |
@@ -842,27 +842,27 @@ discard block |
||
842 | 842 | 'product', |
843 | 843 | ), |
844 | 844 | ); |
845 | - $params['reviewer'] = array( |
|
845 | + $params[ 'reviewer' ] = array( |
|
846 | 846 | 'description' => __( 'Limit result set to reviews assigned to specific user IDs.', 'woocommerce-rest-api' ), |
847 | 847 | 'type' => 'array', |
848 | 848 | 'items' => array( |
849 | 849 | 'type' => 'integer', |
850 | 850 | ), |
851 | 851 | ); |
852 | - $params['reviewer_exclude'] = array( |
|
852 | + $params[ 'reviewer_exclude' ] = array( |
|
853 | 853 | 'description' => __( 'Ensure result set excludes reviews assigned to specific user IDs.', 'woocommerce-rest-api' ), |
854 | 854 | 'type' => 'array', |
855 | 855 | 'items' => array( |
856 | 856 | 'type' => 'integer', |
857 | 857 | ), |
858 | 858 | ); |
859 | - $params['reviewer_email'] = array( |
|
859 | + $params[ 'reviewer_email' ] = array( |
|
860 | 860 | 'default' => null, |
861 | 861 | 'description' => __( 'Limit result set to that from a specific author email.', 'woocommerce-rest-api' ), |
862 | 862 | 'format' => 'email', |
863 | 863 | 'type' => 'string', |
864 | 864 | ); |
865 | - $params['product'] = array( |
|
865 | + $params[ 'product' ] = array( |
|
866 | 866 | 'default' => array(), |
867 | 867 | 'description' => __( 'Limit result set to reviews assigned to specific product IDs.', 'woocommerce-rest-api' ), |
868 | 868 | 'type' => 'array', |
@@ -870,7 +870,7 @@ discard block |
||
870 | 870 | 'type' => 'integer', |
871 | 871 | ), |
872 | 872 | ); |
873 | - $params['status'] = array( |
|
873 | + $params[ 'status' ] = array( |
|
874 | 874 | 'default' => 'approved', |
875 | 875 | 'description' => __( 'Limit result set to reviews assigned a specific status.', 'woocommerce-rest-api' ), |
876 | 876 | 'sanitize_callback' => 'sanitize_key', |