@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | * @return \WP_Error|boolean |
| 151 | 151 | */ |
| 152 | 152 | public function get_item_permissions_check( $request ) { |
| 153 | - $id = (int) $request['id']; |
|
| 153 | + $id = (int) $request[ 'id' ]; |
|
| 154 | 154 | $review = get_comment( $id ); |
| 155 | 155 | |
| 156 | 156 | if ( $review && ! wc_rest_check_product_reviews_permissions( 'read', $review->comment_ID ) ) { |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | * @return \WP_Error|boolean |
| 182 | 182 | */ |
| 183 | 183 | public function update_item_permissions_check( $request ) { |
| 184 | - $id = (int) $request['id']; |
|
| 184 | + $id = (int) $request[ 'id' ]; |
|
| 185 | 185 | $review = get_comment( $id ); |
| 186 | 186 | |
| 187 | 187 | if ( $review && ! wc_rest_check_product_reviews_permissions( 'edit', $review->comment_ID ) ) { |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | * @return \WP_Error|boolean |
| 199 | 199 | */ |
| 200 | 200 | public function delete_item_permissions_check( $request ) { |
| 201 | - $id = (int) $request['id']; |
|
| 201 | + $id = (int) $request[ 'id' ]; |
|
| 202 | 202 | $review = get_comment( $id ); |
| 203 | 203 | |
| 204 | 204 | if ( $review && ! wc_rest_check_product_reviews_permissions( 'delete', $review->comment_ID ) ) { |
@@ -271,29 +271,29 @@ discard block |
||
| 271 | 271 | } |
| 272 | 272 | } |
| 273 | 273 | |
| 274 | - if ( isset( $registered['orderby'] ) ) { |
|
| 275 | - $prepared_args['orderby'] = $this->normalize_query_param( $request['orderby'] ); |
|
| 274 | + if ( isset( $registered[ 'orderby' ] ) ) { |
|
| 275 | + $prepared_args[ 'orderby' ] = $this->normalize_query_param( $request[ 'orderby' ] ); |
|
| 276 | 276 | } |
| 277 | 277 | |
| 278 | - if ( isset( $prepared_args['status'] ) ) { |
|
| 279 | - $prepared_args['status'] = 'approved' === $prepared_args['status'] ? 'approve' : $prepared_args['status']; |
|
| 278 | + if ( isset( $prepared_args[ 'status' ] ) ) { |
|
| 279 | + $prepared_args[ 'status' ] = 'approved' === $prepared_args[ 'status' ] ? 'approve' : $prepared_args[ 'status' ]; |
|
| 280 | 280 | } |
| 281 | 281 | |
| 282 | - $prepared_args['no_found_rows'] = false; |
|
| 283 | - $prepared_args['date_query'] = array(); |
|
| 282 | + $prepared_args[ 'no_found_rows' ] = false; |
|
| 283 | + $prepared_args[ 'date_query' ] = array(); |
|
| 284 | 284 | |
| 285 | 285 | // Set before into date query. Date query must be specified as an array of an array. |
| 286 | - if ( isset( $registered['before'], $request['before'] ) ) { |
|
| 287 | - $prepared_args['date_query'][0]['before'] = $request['before']; |
|
| 286 | + if ( isset( $registered[ 'before' ], $request[ 'before' ] ) ) { |
|
| 287 | + $prepared_args[ 'date_query' ][ 0 ][ 'before' ] = $request[ 'before' ]; |
|
| 288 | 288 | } |
| 289 | 289 | |
| 290 | 290 | // Set after into date query. Date query must be specified as an array of an array. |
| 291 | - if ( isset( $registered['after'], $request['after'] ) ) { |
|
| 292 | - $prepared_args['date_query'][0]['after'] = $request['after']; |
|
| 291 | + if ( isset( $registered[ 'after' ], $request[ 'after' ] ) ) { |
|
| 292 | + $prepared_args[ 'date_query' ][ 0 ][ 'after' ] = $request[ 'after' ]; |
|
| 293 | 293 | } |
| 294 | 294 | |
| 295 | - if ( isset( $registered['page'] ) && empty( $request['offset'] ) ) { |
|
| 296 | - $prepared_args['offset'] = $prepared_args['number'] * ( absint( $request['page'] ) - 1 ); |
|
| 295 | + if ( isset( $registered[ 'page' ] ) && empty( $request[ 'offset' ] ) ) { |
|
| 296 | + $prepared_args[ 'offset' ] = $prepared_args[ 'number' ] * ( absint( $request[ 'page' ] ) - 1 ); |
|
| 297 | 297 | } |
| 298 | 298 | |
| 299 | 299 | /** |
@@ -307,7 +307,7 @@ discard block |
||
| 307 | 307 | $prepared_args = apply_filters( 'woocommerce_rest_product_review_query', $prepared_args, $request ); |
| 308 | 308 | |
| 309 | 309 | // Make sure that returns only reviews. |
| 310 | - $prepared_args['type'] = 'review'; |
|
| 310 | + $prepared_args[ 'type' ] = 'review'; |
|
| 311 | 311 | |
| 312 | 312 | // Query reviews. |
| 313 | 313 | $query = new \WP_Comment_Query(); |
@@ -320,7 +320,7 @@ discard block |
||
| 320 | 320 | } |
| 321 | 321 | |
| 322 | 322 | $data = $this->prepare_item_for_response( $review, $request ); |
| 323 | - $reviews[] = $this->prepare_response_for_collection( $data ); |
|
| 323 | + $reviews[ ] = $this->prepare_response_for_collection( $data ); |
|
| 324 | 324 | } |
| 325 | 325 | |
| 326 | 326 | $total_reviews = (int) $query->found_comments; |
@@ -328,13 +328,13 @@ discard block |
||
| 328 | 328 | |
| 329 | 329 | if ( $total_reviews < 1 ) { |
| 330 | 330 | // Out-of-bounds, run the query again without LIMIT for total count. |
| 331 | - unset( $prepared_args['number'], $prepared_args['offset'] ); |
|
| 331 | + unset( $prepared_args[ 'number' ], $prepared_args[ 'offset' ] ); |
|
| 332 | 332 | |
| 333 | 333 | $query = new \WP_Comment_Query(); |
| 334 | - $prepared_args['count'] = true; |
|
| 334 | + $prepared_args[ 'count' ] = true; |
|
| 335 | 335 | |
| 336 | 336 | $total_reviews = $query->query( $prepared_args ); |
| 337 | - $max_pages = ceil( $total_reviews / $request['per_page'] ); |
|
| 337 | + $max_pages = ceil( $total_reviews / $request[ 'per_page' ] ); |
|
| 338 | 338 | } |
| 339 | 339 | |
| 340 | 340 | $response = rest_ensure_response( $reviews ); |
@@ -343,8 +343,8 @@ discard block |
||
| 343 | 343 | |
| 344 | 344 | $base = add_query_arg( $request->get_query_params(), rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ) ); |
| 345 | 345 | |
| 346 | - if ( $request['page'] > 1 ) { |
|
| 347 | - $prev_page = $request['page'] - 1; |
|
| 346 | + if ( $request[ 'page' ] > 1 ) { |
|
| 347 | + $prev_page = $request[ 'page' ] - 1; |
|
| 348 | 348 | |
| 349 | 349 | if ( $prev_page > $max_pages ) { |
| 350 | 350 | $prev_page = $max_pages; |
@@ -354,8 +354,8 @@ discard block |
||
| 354 | 354 | $response->link_header( 'prev', $prev_link ); |
| 355 | 355 | } |
| 356 | 356 | |
| 357 | - if ( $max_pages > $request['page'] ) { |
|
| 358 | - $next_page = $request['page'] + 1; |
|
| 357 | + if ( $max_pages > $request[ 'page' ] ) { |
|
| 358 | + $next_page = $request[ 'page' ] + 1; |
|
| 359 | 359 | $next_link = add_query_arg( 'page', $next_page, $base ); |
| 360 | 360 | |
| 361 | 361 | $response->link_header( 'next', $next_link ); |
@@ -371,11 +371,11 @@ discard block |
||
| 371 | 371 | * @return \WP_Error|\WP_REST_Response |
| 372 | 372 | */ |
| 373 | 373 | public function create_item( $request ) { |
| 374 | - if ( ! empty( $request['id'] ) ) { |
|
| 374 | + if ( ! empty( $request[ 'id' ] ) ) { |
|
| 375 | 375 | return new \WP_Error( 'woocommerce_rest_review_exists', __( 'Cannot create existing product review.', 'woocommerce' ), array( 'status' => 400 ) ); |
| 376 | 376 | } |
| 377 | 377 | |
| 378 | - $product_id = (int) $request['product_id']; |
|
| 378 | + $product_id = (int) $request[ 'product_id' ]; |
|
| 379 | 379 | |
| 380 | 380 | if ( 'product' !== get_post_type( $product_id ) ) { |
| 381 | 381 | return new \WP_Error( 'woocommerce_rest_product_invalid_id', __( 'Invalid product ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
@@ -386,32 +386,32 @@ discard block |
||
| 386 | 386 | return $prepared_review; |
| 387 | 387 | } |
| 388 | 388 | |
| 389 | - $prepared_review['comment_type'] = 'review'; |
|
| 389 | + $prepared_review[ 'comment_type' ] = 'review'; |
|
| 390 | 390 | |
| 391 | 391 | /* |
| 392 | 392 | * Do not allow a comment to be created with missing or empty comment_content. See wp_handle_comment_submission(). |
| 393 | 393 | */ |
| 394 | - if ( empty( $prepared_review['comment_content'] ) ) { |
|
| 394 | + if ( empty( $prepared_review[ 'comment_content' ] ) ) { |
|
| 395 | 395 | return new \WP_Error( 'woocommerce_rest_review_content_invalid', __( 'Invalid review content.', 'woocommerce' ), array( 'status' => 400 ) ); |
| 396 | 396 | } |
| 397 | 397 | |
| 398 | 398 | // Setting remaining values before wp_insert_comment so we can use wp_allow_comment(). |
| 399 | - if ( ! isset( $prepared_review['comment_date_gmt'] ) ) { |
|
| 400 | - $prepared_review['comment_date_gmt'] = current_time( 'mysql', true ); |
|
| 399 | + if ( ! isset( $prepared_review[ 'comment_date_gmt' ] ) ) { |
|
| 400 | + $prepared_review[ 'comment_date_gmt' ] = current_time( 'mysql', true ); |
|
| 401 | 401 | } |
| 402 | 402 | |
| 403 | - if ( ! empty( $_SERVER['REMOTE_ADDR'] ) && rest_is_ip_address( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) ) { // WPCS: input var ok, sanitization ok. |
|
| 404 | - $prepared_review['comment_author_IP'] = wc_clean( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ); // WPCS: input var ok. |
|
| 403 | + if ( ! empty( $_SERVER[ 'REMOTE_ADDR' ] ) && rest_is_ip_address( wp_unslash( $_SERVER[ 'REMOTE_ADDR' ] ) ) ) { // WPCS: input var ok, sanitization ok. |
|
| 404 | + $prepared_review[ 'comment_author_IP' ] = wc_clean( wp_unslash( $_SERVER[ 'REMOTE_ADDR' ] ) ); // WPCS: input var ok. |
|
| 405 | 405 | } else { |
| 406 | - $prepared_review['comment_author_IP'] = '127.0.0.1'; |
|
| 406 | + $prepared_review[ 'comment_author_IP' ] = '127.0.0.1'; |
|
| 407 | 407 | } |
| 408 | 408 | |
| 409 | - if ( ! empty( $request['author_user_agent'] ) ) { |
|
| 410 | - $prepared_review['comment_agent'] = $request['author_user_agent']; |
|
| 409 | + if ( ! empty( $request[ 'author_user_agent' ] ) ) { |
|
| 410 | + $prepared_review[ 'comment_agent' ] = $request[ 'author_user_agent' ]; |
|
| 411 | 411 | } elseif ( $request->get_header( 'user_agent' ) ) { |
| 412 | - $prepared_review['comment_agent'] = $request->get_header( 'user_agent' ); |
|
| 412 | + $prepared_review[ 'comment_agent' ] = $request->get_header( 'user_agent' ); |
|
| 413 | 413 | } else { |
| 414 | - $prepared_review['comment_agent'] = ''; |
|
| 414 | + $prepared_review[ 'comment_agent' ] = ''; |
|
| 415 | 415 | } |
| 416 | 416 | |
| 417 | 417 | $check_comment_lengths = wp_check_comment_data_max_lengths( $prepared_review ); |
@@ -420,13 +420,13 @@ discard block |
||
| 420 | 420 | return new \WP_Error( 'woocommerce_rest_' . $error_code, __( 'Product review field exceeds maximum length allowed.', 'woocommerce' ), array( 'status' => 400 ) ); |
| 421 | 421 | } |
| 422 | 422 | |
| 423 | - $prepared_review['comment_parent'] = 0; |
|
| 424 | - $prepared_review['comment_author_url'] = ''; |
|
| 425 | - $prepared_review['comment_approved'] = wp_allow_comment( $prepared_review, true ); |
|
| 423 | + $prepared_review[ 'comment_parent' ] = 0; |
|
| 424 | + $prepared_review[ 'comment_author_url' ] = ''; |
|
| 425 | + $prepared_review[ 'comment_approved' ] = wp_allow_comment( $prepared_review, true ); |
|
| 426 | 426 | |
| 427 | - if ( is_wp_error( $prepared_review['comment_approved'] ) ) { |
|
| 428 | - $error_code = $prepared_review['comment_approved']->get_error_code(); |
|
| 429 | - $error_message = $prepared_review['comment_approved']->get_error_message(); |
|
| 427 | + if ( is_wp_error( $prepared_review[ 'comment_approved' ] ) ) { |
|
| 428 | + $error_code = $prepared_review[ 'comment_approved' ]->get_error_code(); |
|
| 429 | + $error_message = $prepared_review[ 'comment_approved' ]->get_error_message(); |
|
| 430 | 430 | |
| 431 | 431 | if ( 'comment_duplicate' === $error_code ) { |
| 432 | 432 | return new \WP_Error( 'woocommerce_rest_' . $error_code, $error_message, array( 'status' => 409 ) ); |
@@ -436,7 +436,7 @@ discard block |
||
| 436 | 436 | return new \WP_Error( 'woocommerce_rest_' . $error_code, $error_message, array( 'status' => 400 ) ); |
| 437 | 437 | } |
| 438 | 438 | |
| 439 | - return $prepared_review['comment_approved']; |
|
| 439 | + return $prepared_review[ 'comment_approved' ]; |
|
| 440 | 440 | } |
| 441 | 441 | |
| 442 | 442 | /** |
@@ -461,11 +461,11 @@ discard block |
||
| 461 | 461 | return new \WP_Error( 'woocommerce_rest_review_failed_create', __( 'Creating product review failed.', 'woocommerce' ), array( 'status' => 500 ) ); |
| 462 | 462 | } |
| 463 | 463 | |
| 464 | - if ( isset( $request['status'] ) ) { |
|
| 465 | - $this->handle_status_param( $request['status'], $review_id ); |
|
| 464 | + if ( isset( $request[ 'status' ] ) ) { |
|
| 465 | + $this->handle_status_param( $request[ 'status' ], $review_id ); |
|
| 466 | 466 | } |
| 467 | 467 | |
| 468 | - update_comment_meta( $review_id, 'rating', ! empty( $request['rating'] ) ? $request['rating'] : '0' ); |
|
| 468 | + update_comment_meta( $review_id, 'rating', ! empty( $request[ 'rating' ] ) ? $request[ 'rating' ] : '0' ); |
|
| 469 | 469 | |
| 470 | 470 | $review = get_comment( $review_id ); |
| 471 | 471 | |
@@ -502,7 +502,7 @@ discard block |
||
| 502 | 502 | * @return \WP_Error|\WP_REST_Response |
| 503 | 503 | */ |
| 504 | 504 | public function get_item( $request ) { |
| 505 | - $review = $this->get_review( $request['id'] ); |
|
| 505 | + $review = $this->get_review( $request[ 'id' ] ); |
|
| 506 | 506 | if ( is_wp_error( $review ) ) { |
| 507 | 507 | return $review; |
| 508 | 508 | } |
@@ -520,14 +520,14 @@ discard block |
||
| 520 | 520 | * @return \WP_Error|\WP_REST_Response Response object on success, or error object on failure. |
| 521 | 521 | */ |
| 522 | 522 | public function update_item( $request ) { |
| 523 | - $review = $this->get_review( $request['id'] ); |
|
| 523 | + $review = $this->get_review( $request[ 'id' ] ); |
|
| 524 | 524 | if ( is_wp_error( $review ) ) { |
| 525 | 525 | return $review; |
| 526 | 526 | } |
| 527 | 527 | |
| 528 | 528 | $id = (int) $review->comment_ID; |
| 529 | 529 | |
| 530 | - if ( isset( $request['type'] ) && 'review' !== get_comment_type( $id ) ) { |
|
| 530 | + if ( isset( $request[ 'type' ] ) && 'review' !== get_comment_type( $id ) ) { |
|
| 531 | 531 | return new \WP_Error( 'woocommerce_rest_review_invalid_type', __( 'Sorry, you are not allowed to change the comment type.', 'woocommerce' ), array( 'status' => 404 ) ); |
| 532 | 532 | } |
| 533 | 533 | |
@@ -536,15 +536,15 @@ discard block |
||
| 536 | 536 | return $prepared_args; |
| 537 | 537 | } |
| 538 | 538 | |
| 539 | - if ( ! empty( $prepared_args['comment_post_ID'] ) ) { |
|
| 540 | - if ( 'product' !== get_post_type( (int) $prepared_args['comment_post_ID'] ) ) { |
|
| 539 | + if ( ! empty( $prepared_args[ 'comment_post_ID' ] ) ) { |
|
| 540 | + if ( 'product' !== get_post_type( (int) $prepared_args[ 'comment_post_ID' ] ) ) { |
|
| 541 | 541 | return new \WP_Error( 'woocommerce_rest_product_invalid_id', __( 'Invalid product ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
| 542 | 542 | } |
| 543 | 543 | } |
| 544 | 544 | |
| 545 | - if ( empty( $prepared_args ) && isset( $request['status'] ) ) { |
|
| 545 | + if ( empty( $prepared_args ) && isset( $request[ 'status' ] ) ) { |
|
| 546 | 546 | // Only the comment status is being changed. |
| 547 | - $change = $this->handle_status_param( $request['status'], $id ); |
|
| 547 | + $change = $this->handle_status_param( $request[ 'status' ], $id ); |
|
| 548 | 548 | |
| 549 | 549 | if ( ! $change ) { |
| 550 | 550 | return new \WP_Error( 'woocommerce_rest_review_failed_edit', __( 'Updating review status failed.', 'woocommerce' ), array( 'status' => 500 ) ); |
@@ -554,11 +554,11 @@ discard block |
||
| 554 | 554 | return $prepared_args; |
| 555 | 555 | } |
| 556 | 556 | |
| 557 | - if ( isset( $prepared_args['comment_content'] ) && empty( $prepared_args['comment_content'] ) ) { |
|
| 557 | + if ( isset( $prepared_args[ 'comment_content' ] ) && empty( $prepared_args[ 'comment_content' ] ) ) { |
|
| 558 | 558 | return new \WP_Error( 'woocommerce_rest_review_content_invalid', __( 'Invalid review content.', 'woocommerce' ), array( 'status' => 400 ) ); |
| 559 | 559 | } |
| 560 | 560 | |
| 561 | - $prepared_args['comment_ID'] = $id; |
|
| 561 | + $prepared_args[ 'comment_ID' ] = $id; |
|
| 562 | 562 | |
| 563 | 563 | $check_comment_lengths = wp_check_comment_data_max_lengths( $prepared_args ); |
| 564 | 564 | if ( is_wp_error( $check_comment_lengths ) ) { |
@@ -572,13 +572,13 @@ discard block |
||
| 572 | 572 | return new \WP_Error( 'woocommerce_rest_comment_failed_edit', __( 'Updating review failed.', 'woocommerce' ), array( 'status' => 500 ) ); |
| 573 | 573 | } |
| 574 | 574 | |
| 575 | - if ( isset( $request['status'] ) ) { |
|
| 576 | - $this->handle_status_param( $request['status'], $id ); |
|
| 575 | + if ( isset( $request[ 'status' ] ) ) { |
|
| 576 | + $this->handle_status_param( $request[ 'status' ], $id ); |
|
| 577 | 577 | } |
| 578 | 578 | } |
| 579 | 579 | |
| 580 | - if ( ! empty( $request['rating'] ) ) { |
|
| 581 | - update_comment_meta( $id, 'rating', $request['rating'] ); |
|
| 580 | + if ( ! empty( $request[ 'rating' ] ) ) { |
|
| 581 | + update_comment_meta( $id, 'rating', $request[ 'rating' ] ); |
|
| 582 | 582 | } |
| 583 | 583 | |
| 584 | 584 | $review = get_comment( $id ); |
@@ -606,12 +606,12 @@ discard block |
||
| 606 | 606 | * @return \WP_Error|\WP_REST_Response Response object on success, or error object on failure. |
| 607 | 607 | */ |
| 608 | 608 | public function delete_item( $request ) { |
| 609 | - $review = $this->get_review( $request['id'] ); |
|
| 609 | + $review = $this->get_review( $request[ 'id' ] ); |
|
| 610 | 610 | if ( is_wp_error( $review ) ) { |
| 611 | 611 | return $review; |
| 612 | 612 | } |
| 613 | 613 | |
| 614 | - $force = isset( $request['force'] ) ? (bool) $request['force'] : false; |
|
| 614 | + $force = isset( $request[ 'force' ] ) ? (bool) $request[ 'force' ] : false; |
|
| 615 | 615 | |
| 616 | 616 | /** |
| 617 | 617 | * Filters whether a review can be trashed. |
@@ -676,42 +676,42 @@ discard block |
||
| 676 | 676 | * @return \WP_REST_Response $response Response data. |
| 677 | 677 | */ |
| 678 | 678 | public function prepare_item_for_response( $review, $request ) { |
| 679 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
| 679 | + $context = ! empty( $request[ 'context' ] ) ? $request[ 'context' ] : 'view'; |
|
| 680 | 680 | $fields = $this->get_fields_for_response( $request ); |
| 681 | 681 | $data = array(); |
| 682 | 682 | |
| 683 | 683 | if ( in_array( 'id', $fields, true ) ) { |
| 684 | - $data['id'] = (int) $review->comment_ID; |
|
| 684 | + $data[ 'id' ] = (int) $review->comment_ID; |
|
| 685 | 685 | } |
| 686 | 686 | if ( in_array( 'date_created', $fields, true ) ) { |
| 687 | - $data['date_created'] = wc_rest_prepare_date_response( $review->comment_date ); |
|
| 687 | + $data[ 'date_created' ] = wc_rest_prepare_date_response( $review->comment_date ); |
|
| 688 | 688 | } |
| 689 | 689 | if ( in_array( 'date_created_gmt', $fields, true ) ) { |
| 690 | - $data['date_created_gmt'] = wc_rest_prepare_date_response( $review->comment_date_gmt ); |
|
| 690 | + $data[ 'date_created_gmt' ] = wc_rest_prepare_date_response( $review->comment_date_gmt ); |
|
| 691 | 691 | } |
| 692 | 692 | if ( in_array( 'product_id', $fields, true ) ) { |
| 693 | - $data['product_id'] = (int) $review->comment_post_ID; |
|
| 693 | + $data[ 'product_id' ] = (int) $review->comment_post_ID; |
|
| 694 | 694 | } |
| 695 | 695 | if ( in_array( 'status', $fields, true ) ) { |
| 696 | - $data['status'] = $this->prepare_status_response( (string) $review->comment_approved ); |
|
| 696 | + $data[ 'status' ] = $this->prepare_status_response( (string) $review->comment_approved ); |
|
| 697 | 697 | } |
| 698 | 698 | if ( in_array( 'reviewer', $fields, true ) ) { |
| 699 | - $data['reviewer'] = $review->comment_author; |
|
| 699 | + $data[ 'reviewer' ] = $review->comment_author; |
|
| 700 | 700 | } |
| 701 | 701 | if ( in_array( 'reviewer_email', $fields, true ) ) { |
| 702 | - $data['reviewer_email'] = $review->comment_author_email; |
|
| 702 | + $data[ 'reviewer_email' ] = $review->comment_author_email; |
|
| 703 | 703 | } |
| 704 | 704 | if ( in_array( 'review', $fields, true ) ) { |
| 705 | - $data['review'] = 'view' === $context ? wpautop( $review->comment_content ) : $review->comment_content; |
|
| 705 | + $data[ 'review' ] = 'view' === $context ? wpautop( $review->comment_content ) : $review->comment_content; |
|
| 706 | 706 | } |
| 707 | 707 | if ( in_array( 'rating', $fields, true ) ) { |
| 708 | - $data['rating'] = (int) get_comment_meta( $review->comment_ID, 'rating', true ); |
|
| 708 | + $data[ 'rating' ] = (int) get_comment_meta( $review->comment_ID, 'rating', true ); |
|
| 709 | 709 | } |
| 710 | 710 | if ( in_array( 'verified', $fields, true ) ) { |
| 711 | - $data['verified'] = wc_review_is_from_verified_owner( $review->comment_ID ); |
|
| 711 | + $data[ 'verified' ] = wc_review_is_from_verified_owner( $review->comment_ID ); |
|
| 712 | 712 | } |
| 713 | 713 | if ( in_array( 'reviewer_avatar_urls', $fields, true ) ) { |
| 714 | - $data['reviewer_avatar_urls'] = rest_get_avatar_urls( $review->comment_author_email ); |
|
| 714 | + $data[ 'reviewer_avatar_urls' ] = rest_get_avatar_urls( $review->comment_author_email ); |
|
| 715 | 715 | } |
| 716 | 716 | |
| 717 | 717 | $data = $this->add_additional_fields_to_object( $data, $request ); |
@@ -739,37 +739,37 @@ discard block |
||
| 739 | 739 | * @return array|\WP_Error $prepared_review |
| 740 | 740 | */ |
| 741 | 741 | protected function prepare_item_for_database( $request ) { |
| 742 | - if ( isset( $request['id'] ) ) { |
|
| 743 | - $prepared_review['comment_ID'] = (int) $request['id']; |
|
| 742 | + if ( isset( $request[ 'id' ] ) ) { |
|
| 743 | + $prepared_review[ 'comment_ID' ] = (int) $request[ 'id' ]; |
|
| 744 | 744 | } |
| 745 | 745 | |
| 746 | - if ( isset( $request['review'] ) ) { |
|
| 747 | - $prepared_review['comment_content'] = $request['review']; |
|
| 746 | + if ( isset( $request[ 'review' ] ) ) { |
|
| 747 | + $prepared_review[ 'comment_content' ] = $request[ 'review' ]; |
|
| 748 | 748 | } |
| 749 | 749 | |
| 750 | - if ( isset( $request['product_id'] ) ) { |
|
| 751 | - $prepared_review['comment_post_ID'] = (int) $request['product_id']; |
|
| 750 | + if ( isset( $request[ 'product_id' ] ) ) { |
|
| 751 | + $prepared_review[ 'comment_post_ID' ] = (int) $request[ 'product_id' ]; |
|
| 752 | 752 | } |
| 753 | 753 | |
| 754 | - if ( isset( $request['reviewer'] ) ) { |
|
| 755 | - $prepared_review['comment_author'] = $request['reviewer']; |
|
| 754 | + if ( isset( $request[ 'reviewer' ] ) ) { |
|
| 755 | + $prepared_review[ 'comment_author' ] = $request[ 'reviewer' ]; |
|
| 756 | 756 | } |
| 757 | 757 | |
| 758 | - if ( isset( $request['reviewer_email'] ) ) { |
|
| 759 | - $prepared_review['comment_author_email'] = $request['reviewer_email']; |
|
| 758 | + if ( isset( $request[ 'reviewer_email' ] ) ) { |
|
| 759 | + $prepared_review[ 'comment_author_email' ] = $request[ 'reviewer_email' ]; |
|
| 760 | 760 | } |
| 761 | 761 | |
| 762 | - if ( ! empty( $request['date_created'] ) ) { |
|
| 763 | - $date_data = rest_get_date_with_gmt( $request['date_created'] ); |
|
| 762 | + if ( ! empty( $request[ 'date_created' ] ) ) { |
|
| 763 | + $date_data = rest_get_date_with_gmt( $request[ 'date_created' ] ); |
|
| 764 | 764 | |
| 765 | 765 | if ( ! empty( $date_data ) ) { |
| 766 | - list( $prepared_review['comment_date'], $prepared_review['comment_date_gmt'] ) = $date_data; |
|
| 766 | + list( $prepared_review[ 'comment_date' ], $prepared_review[ 'comment_date_gmt' ] ) = $date_data; |
|
| 767 | 767 | } |
| 768 | - } elseif ( ! empty( $request['date_created_gmt'] ) ) { |
|
| 769 | - $date_data = rest_get_date_with_gmt( $request['date_created_gmt'], true ); |
|
| 768 | + } elseif ( ! empty( $request[ 'date_created_gmt' ] ) ) { |
|
| 769 | + $date_data = rest_get_date_with_gmt( $request[ 'date_created_gmt' ], true ); |
|
| 770 | 770 | |
| 771 | 771 | if ( ! empty( $date_data ) ) { |
| 772 | - list( $prepared_review['comment_date'], $prepared_review['comment_date_gmt'] ) = $date_data; |
|
| 772 | + list( $prepared_review[ 'comment_date' ], $prepared_review[ 'comment_date_gmt' ] ) = $date_data; |
|
| 773 | 773 | } |
| 774 | 774 | } |
| 775 | 775 | |
@@ -801,13 +801,13 @@ discard block |
||
| 801 | 801 | ), |
| 802 | 802 | ); |
| 803 | 803 | if ( 0 !== (int) $review->comment_post_ID ) { |
| 804 | - $links['up'] = array( |
|
| 804 | + $links[ 'up' ] = array( |
|
| 805 | 805 | 'href' => rest_url( sprintf( '/%s/products/%d', $this->namespace, $review->comment_post_ID ) ), |
| 806 | 806 | 'embeddable' => true, |
| 807 | 807 | ); |
| 808 | 808 | } |
| 809 | 809 | if ( 0 !== (int) $review->user_id ) { |
| 810 | - $links['reviewer'] = array( |
|
| 810 | + $links[ 'reviewer' ] = array( |
|
| 811 | 811 | 'href' => rest_url( 'wp/v2/users/' . $review->user_id ), |
| 812 | 812 | 'embeddable' => true, |
| 813 | 813 | ); |
@@ -902,7 +902,7 @@ discard block |
||
| 902 | 902 | 'context' => array( 'embed', 'view', 'edit' ), |
| 903 | 903 | ); |
| 904 | 904 | } |
| 905 | - $schema['properties']['reviewer_avatar_urls'] = array( |
|
| 905 | + $schema[ 'properties' ][ 'reviewer_avatar_urls' ] = array( |
|
| 906 | 906 | 'description' => __( 'Avatar URLs for the object reviewer.', 'woocommerce' ), |
| 907 | 907 | 'type' => 'object', |
| 908 | 908 | 'context' => array( 'view', 'edit' ), |
@@ -922,19 +922,19 @@ discard block |
||
| 922 | 922 | public function get_collection_params() { |
| 923 | 923 | $params = parent::get_collection_params(); |
| 924 | 924 | |
| 925 | - $params['context']['default'] = 'view'; |
|
| 925 | + $params[ 'context' ][ 'default' ] = 'view'; |
|
| 926 | 926 | |
| 927 | - $params['after'] = array( |
|
| 927 | + $params[ 'after' ] = array( |
|
| 928 | 928 | 'description' => __( 'Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce' ), |
| 929 | 929 | 'type' => 'string', |
| 930 | 930 | 'format' => 'date-time', |
| 931 | 931 | ); |
| 932 | - $params['before'] = array( |
|
| 932 | + $params[ 'before' ] = array( |
|
| 933 | 933 | 'description' => __( 'Limit response to reviews published before a given ISO8601 compliant date.', 'woocommerce' ), |
| 934 | 934 | 'type' => 'string', |
| 935 | 935 | 'format' => 'date-time', |
| 936 | 936 | ); |
| 937 | - $params['exclude'] = array( |
|
| 937 | + $params[ 'exclude' ] = array( |
|
| 938 | 938 | 'description' => __( 'Ensure result set excludes specific IDs.', 'woocommerce' ), |
| 939 | 939 | 'type' => 'array', |
| 940 | 940 | 'items' => array( |
@@ -942,7 +942,7 @@ discard block |
||
| 942 | 942 | ), |
| 943 | 943 | 'default' => array(), |
| 944 | 944 | ); |
| 945 | - $params['include'] = array( |
|
| 945 | + $params[ 'include' ] = array( |
|
| 946 | 946 | 'description' => __( 'Limit result set to specific IDs.', 'woocommerce' ), |
| 947 | 947 | 'type' => 'array', |
| 948 | 948 | 'items' => array( |
@@ -950,11 +950,11 @@ discard block |
||
| 950 | 950 | ), |
| 951 | 951 | 'default' => array(), |
| 952 | 952 | ); |
| 953 | - $params['offset'] = array( |
|
| 953 | + $params[ 'offset' ] = array( |
|
| 954 | 954 | 'description' => __( 'Offset the result set by a specific number of items.', 'woocommerce' ), |
| 955 | 955 | 'type' => 'integer', |
| 956 | 956 | ); |
| 957 | - $params['order'] = array( |
|
| 957 | + $params[ 'order' ] = array( |
|
| 958 | 958 | 'description' => __( 'Order sort attribute ascending or descending.', 'woocommerce' ), |
| 959 | 959 | 'type' => 'string', |
| 960 | 960 | 'default' => 'desc', |
@@ -963,7 +963,7 @@ discard block |
||
| 963 | 963 | 'desc', |
| 964 | 964 | ), |
| 965 | 965 | ); |
| 966 | - $params['orderby'] = array( |
|
| 966 | + $params[ 'orderby' ] = array( |
|
| 967 | 967 | 'description' => __( 'Sort collection by object attribute.', 'woocommerce' ), |
| 968 | 968 | 'type' => 'string', |
| 969 | 969 | 'default' => 'date_gmt', |
@@ -975,27 +975,27 @@ discard block |
||
| 975 | 975 | 'product', |
| 976 | 976 | ), |
| 977 | 977 | ); |
| 978 | - $params['reviewer'] = array( |
|
| 978 | + $params[ 'reviewer' ] = array( |
|
| 979 | 979 | 'description' => __( 'Limit result set to reviews assigned to specific user IDs.', 'woocommerce' ), |
| 980 | 980 | 'type' => 'array', |
| 981 | 981 | 'items' => array( |
| 982 | 982 | 'type' => 'integer', |
| 983 | 983 | ), |
| 984 | 984 | ); |
| 985 | - $params['reviewer_exclude'] = array( |
|
| 985 | + $params[ 'reviewer_exclude' ] = array( |
|
| 986 | 986 | 'description' => __( 'Ensure result set excludes reviews assigned to specific user IDs.', 'woocommerce' ), |
| 987 | 987 | 'type' => 'array', |
| 988 | 988 | 'items' => array( |
| 989 | 989 | 'type' => 'integer', |
| 990 | 990 | ), |
| 991 | 991 | ); |
| 992 | - $params['reviewer_email'] = array( |
|
| 992 | + $params[ 'reviewer_email' ] = array( |
|
| 993 | 993 | 'default' => null, |
| 994 | 994 | 'description' => __( 'Limit result set to that from a specific author email.', 'woocommerce' ), |
| 995 | 995 | 'format' => 'email', |
| 996 | 996 | 'type' => 'string', |
| 997 | 997 | ); |
| 998 | - $params['product'] = array( |
|
| 998 | + $params[ 'product' ] = array( |
|
| 999 | 999 | 'default' => array(), |
| 1000 | 1000 | 'description' => __( 'Limit result set to reviews assigned to specific product IDs.', 'woocommerce' ), |
| 1001 | 1001 | 'type' => 'array', |
@@ -1003,7 +1003,7 @@ discard block |
||
| 1003 | 1003 | 'type' => 'integer', |
| 1004 | 1004 | ), |
| 1005 | 1005 | ); |
| 1006 | - $params['status'] = array( |
|
| 1006 | + $params[ 'status' ] = array( |
|
| 1007 | 1007 | 'default' => 'approved', |
| 1008 | 1008 | 'description' => __( 'Limit result set to reviews assigned a specific status.', 'woocommerce' ), |
| 1009 | 1009 | 'sanitize_callback' => 'sanitize_key', |
@@ -232,18 +232,18 @@ discard block |
||
| 232 | 232 | */ |
| 233 | 233 | public function get_items( $request ) { |
| 234 | 234 | $args = array(); |
| 235 | - $args['order'] = $request['order']; |
|
| 236 | - $args['orderby'] = $request['orderby']; |
|
| 237 | - $args['status'] = 'all' === $request['status'] ? '' : $request['status']; |
|
| 238 | - $args['include'] = implode( ',', $request['include'] ); |
|
| 239 | - $args['exclude'] = implode( ',', $request['exclude'] ); |
|
| 240 | - $args['limit'] = $request['per_page']; |
|
| 241 | - $args['search'] = $request['search']; |
|
| 242 | - $args['before'] = $request['before']; |
|
| 243 | - $args['after'] = $request['after']; |
|
| 244 | - |
|
| 245 | - if ( empty( $request['offset'] ) ) { |
|
| 246 | - $args['offset'] = 1 < $request['page'] ? ( $request['page'] - 1 ) * $args['limit'] : 0; |
|
| 235 | + $args[ 'order' ] = $request[ 'order' ]; |
|
| 236 | + $args[ 'orderby' ] = $request[ 'orderby' ]; |
|
| 237 | + $args[ 'status' ] = 'all' === $request[ 'status' ] ? '' : $request[ 'status' ]; |
|
| 238 | + $args[ 'include' ] = implode( ',', $request[ 'include' ] ); |
|
| 239 | + $args[ 'exclude' ] = implode( ',', $request[ 'exclude' ] ); |
|
| 240 | + $args[ 'limit' ] = $request[ 'per_page' ]; |
|
| 241 | + $args[ 'search' ] = $request[ 'search' ]; |
|
| 242 | + $args[ 'before' ] = $request[ 'before' ]; |
|
| 243 | + $args[ 'after' ] = $request[ 'after' ]; |
|
| 244 | + |
|
| 245 | + if ( empty( $request[ 'offset' ] ) ) { |
|
| 246 | + $args[ 'offset' ] = 1 < $request[ 'page' ] ? ( $request[ 'page' ] - 1 ) * $args[ 'limit' ] : 0; |
|
| 247 | 247 | } |
| 248 | 248 | |
| 249 | 249 | /** |
@@ -253,8 +253,8 @@ discard block |
||
| 253 | 253 | * @param \WP_REST_Request $request The current request. |
| 254 | 254 | */ |
| 255 | 255 | $prepared_args = apply_filters( 'woocommerce_rest_webhook_query', $args, $request ); |
| 256 | - unset( $prepared_args['page'] ); |
|
| 257 | - $prepared_args['paginate'] = true; |
|
| 256 | + unset( $prepared_args[ 'page' ] ); |
|
| 257 | + $prepared_args[ 'paginate' ] = true; |
|
| 258 | 258 | |
| 259 | 259 | // Get the webhooks. |
| 260 | 260 | $webhooks = array(); |
@@ -264,12 +264,12 @@ discard block |
||
| 264 | 264 | |
| 265 | 265 | foreach ( $webhook_ids as $webhook_id ) { |
| 266 | 266 | $data = $this->prepare_item_for_response( $webhook_id, $request ); |
| 267 | - $webhooks[] = $this->prepare_response_for_collection( $data ); |
|
| 267 | + $webhooks[ ] = $this->prepare_response_for_collection( $data ); |
|
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | $response = rest_ensure_response( $webhooks ); |
| 271 | - $per_page = (int) $prepared_args['limit']; |
|
| 272 | - $page = ceil( ( ( (int) $prepared_args['offset'] ) / $per_page ) + 1 ); |
|
| 271 | + $per_page = (int) $prepared_args[ 'limit' ]; |
|
| 272 | + $page = ceil( ( ( (int) $prepared_args[ 'offset' ] ) / $per_page ) + 1 ); |
|
| 273 | 273 | $total_webhooks = $results->total; |
| 274 | 274 | $max_pages = $results->max_num_pages; |
| 275 | 275 | $base = add_query_arg( $request->get_query_params(), rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ) ); |
@@ -301,7 +301,7 @@ discard block |
||
| 301 | 301 | * @return \WP_Error\WP_REST_Response |
| 302 | 302 | */ |
| 303 | 303 | public function get_item( $request ) { |
| 304 | - $id = (int) $request['id']; |
|
| 304 | + $id = (int) $request[ 'id' ]; |
|
| 305 | 305 | |
| 306 | 306 | if ( empty( $id ) ) { |
| 307 | 307 | return new \WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'Invalid ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
@@ -320,18 +320,18 @@ discard block |
||
| 320 | 320 | * @return \WP_Error\WP_REST_Response |
| 321 | 321 | */ |
| 322 | 322 | public function create_item( $request ) { |
| 323 | - if ( ! empty( $request['id'] ) ) { |
|
| 323 | + if ( ! empty( $request[ 'id' ] ) ) { |
|
| 324 | 324 | /* translators: %s: post type */ |
| 325 | 325 | return new \WP_Error( "woocommerce_rest_{$this->post_type}_exists", sprintf( __( 'Cannot create existing %s.', 'woocommerce' ), $this->post_type ), array( 'status' => 400 ) ); |
| 326 | 326 | } |
| 327 | 327 | |
| 328 | 328 | // Validate topic. |
| 329 | - if ( empty( $request['topic'] ) || ! wc_is_webhook_valid_topic( strtolower( $request['topic'] ) ) ) { |
|
| 329 | + if ( empty( $request[ 'topic' ] ) || ! wc_is_webhook_valid_topic( strtolower( $request[ 'topic' ] ) ) ) { |
|
| 330 | 330 | return new \WP_Error( "woocommerce_rest_{$this->post_type}_invalid_topic", __( 'Webhook topic is required and must be valid.', 'woocommerce' ), array( 'status' => 400 ) ); |
| 331 | 331 | } |
| 332 | 332 | |
| 333 | 333 | // Validate delivery URL. |
| 334 | - if ( empty( $request['delivery_url'] ) || ! wc_is_valid_url( $request['delivery_url'] ) ) { |
|
| 334 | + if ( empty( $request[ 'delivery_url' ] ) || ! wc_is_valid_url( $request[ 'delivery_url' ] ) ) { |
|
| 335 | 335 | return new \WP_Error( "woocommerce_rest_{$this->post_type}_invalid_delivery_url", __( 'Webhook delivery URL must be a valid URL starting with http:// or https://.', 'woocommerce' ), array( 'status' => 400 ) ); |
| 336 | 336 | } |
| 337 | 337 | |
@@ -344,9 +344,9 @@ discard block |
||
| 344 | 344 | $webhook->set_name( $post->post_title ); |
| 345 | 345 | $webhook->set_user_id( $post->post_author ); |
| 346 | 346 | $webhook->set_status( 'publish' === $post->post_status ? 'active' : 'disabled' ); |
| 347 | - $webhook->set_topic( $request['topic'] ); |
|
| 348 | - $webhook->set_delivery_url( $request['delivery_url'] ); |
|
| 349 | - $webhook->set_secret( ! empty( $request['secret'] ) ? $request['secret'] : wp_generate_password( 50, true, true ) ); |
|
| 347 | + $webhook->set_topic( $request[ 'topic' ] ); |
|
| 348 | + $webhook->set_delivery_url( $request[ 'delivery_url' ] ); |
|
| 349 | + $webhook->set_secret( ! empty( $request[ 'secret' ] ) ? $request[ 'secret' ] : wp_generate_password( 50, true, true ) ); |
|
| 350 | 350 | $webhook->set_api_version( $this->get_default_api_version() ); |
| 351 | 351 | $webhook->save(); |
| 352 | 352 | |
@@ -380,7 +380,7 @@ discard block |
||
| 380 | 380 | * @return \WP_Error\WP_REST_Response |
| 381 | 381 | */ |
| 382 | 382 | public function update_item( $request ) { |
| 383 | - $id = (int) $request['id']; |
|
| 383 | + $id = (int) $request[ 'id' ]; |
|
| 384 | 384 | $webhook = wc_get_webhook( $id ); |
| 385 | 385 | |
| 386 | 386 | if ( empty( $webhook ) || is_null( $webhook ) ) { |
@@ -388,32 +388,32 @@ discard block |
||
| 388 | 388 | } |
| 389 | 389 | |
| 390 | 390 | // Update topic. |
| 391 | - if ( ! empty( $request['topic'] ) ) { |
|
| 392 | - if ( wc_is_webhook_valid_topic( strtolower( $request['topic'] ) ) ) { |
|
| 393 | - $webhook->set_topic( $request['topic'] ); |
|
| 391 | + if ( ! empty( $request[ 'topic' ] ) ) { |
|
| 392 | + if ( wc_is_webhook_valid_topic( strtolower( $request[ 'topic' ] ) ) ) { |
|
| 393 | + $webhook->set_topic( $request[ 'topic' ] ); |
|
| 394 | 394 | } else { |
| 395 | 395 | return new \WP_Error( "woocommerce_rest_{$this->post_type}_invalid_topic", __( 'Webhook topic must be valid.', 'woocommerce' ), array( 'status' => 400 ) ); |
| 396 | 396 | } |
| 397 | 397 | } |
| 398 | 398 | |
| 399 | 399 | // Update delivery URL. |
| 400 | - if ( ! empty( $request['delivery_url'] ) ) { |
|
| 401 | - if ( wc_is_valid_url( $request['delivery_url'] ) ) { |
|
| 402 | - $webhook->set_delivery_url( $request['delivery_url'] ); |
|
| 400 | + if ( ! empty( $request[ 'delivery_url' ] ) ) { |
|
| 401 | + if ( wc_is_valid_url( $request[ 'delivery_url' ] ) ) { |
|
| 402 | + $webhook->set_delivery_url( $request[ 'delivery_url' ] ); |
|
| 403 | 403 | } else { |
| 404 | 404 | return new \WP_Error( "woocommerce_rest_{$this->post_type}_invalid_delivery_url", __( 'Webhook delivery URL must be a valid URL starting with http:// or https://.', 'woocommerce' ), array( 'status' => 400 ) ); |
| 405 | 405 | } |
| 406 | 406 | } |
| 407 | 407 | |
| 408 | 408 | // Update secret. |
| 409 | - if ( ! empty( $request['secret'] ) ) { |
|
| 410 | - $webhook->set_secret( $request['secret'] ); |
|
| 409 | + if ( ! empty( $request[ 'secret' ] ) ) { |
|
| 410 | + $webhook->set_secret( $request[ 'secret' ] ); |
|
| 411 | 411 | } |
| 412 | 412 | |
| 413 | 413 | // Update status. |
| 414 | - if ( ! empty( $request['status'] ) ) { |
|
| 415 | - if ( wc_is_webhook_valid_status( strtolower( $request['status'] ) ) ) { |
|
| 416 | - $webhook->set_status( $request['status'] ); |
|
| 414 | + if ( ! empty( $request[ 'status' ] ) ) { |
|
| 415 | + if ( wc_is_webhook_valid_status( strtolower( $request[ 'status' ] ) ) ) { |
|
| 416 | + $webhook->set_status( $request[ 'status' ] ); |
|
| 417 | 417 | } else { |
| 418 | 418 | return new \WP_Error( "woocommerce_rest_{$this->post_type}_invalid_status", __( 'Webhook status must be valid.', 'woocommerce' ), array( 'status' => 400 ) ); |
| 419 | 419 | } |
@@ -454,8 +454,8 @@ discard block |
||
| 454 | 454 | * @return \WP_REST_Response|\WP_Error |
| 455 | 455 | */ |
| 456 | 456 | public function delete_item( $request ) { |
| 457 | - $id = (int) $request['id']; |
|
| 458 | - $force = isset( $request['force'] ) ? (bool) $request['force'] : false; |
|
| 457 | + $id = (int) $request[ 'id' ]; |
|
| 458 | + $force = isset( $request[ 'force' ] ) ? (bool) $request[ 'force' ] : false; |
|
| 459 | 459 | |
| 460 | 460 | // We don't support trashing for this type, error out. |
| 461 | 461 | if ( ! $force ) { |
@@ -505,13 +505,13 @@ discard block |
||
| 505 | 505 | $data = new \stdClass(); |
| 506 | 506 | |
| 507 | 507 | // Post ID. |
| 508 | - if ( isset( $request['id'] ) ) { |
|
| 509 | - $data->ID = absint( $request['id'] ); |
|
| 508 | + if ( isset( $request[ 'id' ] ) ) { |
|
| 509 | + $data->ID = absint( $request[ 'id' ] ); |
|
| 510 | 510 | } |
| 511 | 511 | |
| 512 | 512 | // Validate required POST fields. |
| 513 | 513 | if ( 'POST' === $request->get_method() && empty( $data->ID ) ) { |
| 514 | - $data->post_title = ! empty( $request['name'] ) ? $request['name'] : sprintf( __( 'Webhook created on %s', 'woocommerce' ), strftime( _x( '%b %d, %Y @ %I:%M %p', 'Webhook created on date parsed by strftime', 'woocommerce' ) ) ); // @codingStandardsIgnoreLine |
|
| 514 | + $data->post_title = ! empty( $request[ 'name' ] ) ? $request[ 'name' ] : sprintf( __( 'Webhook created on %s', 'woocommerce' ), strftime( _x( '%b %d, %Y @ %I:%M %p', 'Webhook created on date parsed by strftime', 'woocommerce' ) ) ); // @codingStandardsIgnoreLine |
|
| 515 | 515 | |
| 516 | 516 | // Post author. |
| 517 | 517 | $data->post_author = get_current_user_id(); |
@@ -524,8 +524,8 @@ discard block |
||
| 524 | 524 | } else { |
| 525 | 525 | |
| 526 | 526 | // Allow edit post title. |
| 527 | - if ( ! empty( $request['name'] ) ) { |
|
| 528 | - $data->post_title = $request['name']; |
|
| 527 | + if ( ! empty( $request[ 'name' ] ) ) { |
|
| 528 | + $data->post_title = $request[ 'name' ]; |
|
| 529 | 529 | } |
| 530 | 530 | } |
| 531 | 531 | |
@@ -577,7 +577,7 @@ discard block |
||
| 577 | 577 | 'date_modified_gmt' => wc_rest_prepare_date_response( $webhook->get_date_modified() ), |
| 578 | 578 | ); |
| 579 | 579 | |
| 580 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
| 580 | + $context = ! empty( $request[ 'context' ] ) ? $request[ 'context' ] : 'view'; |
|
| 581 | 581 | $data = $this->add_additional_fields_to_object( $data, $request ); |
| 582 | 582 | $data = $this->filter_response_by_context( $data, $context ); |
| 583 | 583 | |
@@ -720,21 +720,21 @@ discard block |
||
| 720 | 720 | public function get_collection_params() { |
| 721 | 721 | $params = parent::get_collection_params(); |
| 722 | 722 | |
| 723 | - $params['context']['default'] = 'view'; |
|
| 723 | + $params[ 'context' ][ 'default' ] = 'view'; |
|
| 724 | 724 | |
| 725 | - $params['after'] = array( |
|
| 725 | + $params[ 'after' ] = array( |
|
| 726 | 726 | 'description' => __( 'Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce' ), |
| 727 | 727 | 'type' => 'string', |
| 728 | 728 | 'format' => 'date-time', |
| 729 | 729 | 'validate_callback' => 'rest_validate_request_arg', |
| 730 | 730 | ); |
| 731 | - $params['before'] = array( |
|
| 731 | + $params[ 'before' ] = array( |
|
| 732 | 732 | 'description' => __( 'Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce' ), |
| 733 | 733 | 'type' => 'string', |
| 734 | 734 | 'format' => 'date-time', |
| 735 | 735 | 'validate_callback' => 'rest_validate_request_arg', |
| 736 | 736 | ); |
| 737 | - $params['exclude'] = array( |
|
| 737 | + $params[ 'exclude' ] = array( |
|
| 738 | 738 | 'description' => __( 'Ensure result set excludes specific IDs.', 'woocommerce' ), |
| 739 | 739 | 'type' => 'array', |
| 740 | 740 | 'items' => array( |
@@ -743,7 +743,7 @@ discard block |
||
| 743 | 743 | 'default' => array(), |
| 744 | 744 | 'sanitize_callback' => 'wp_parse_id_list', |
| 745 | 745 | ); |
| 746 | - $params['include'] = array( |
|
| 746 | + $params[ 'include' ] = array( |
|
| 747 | 747 | 'description' => __( 'Limit result set to specific ids.', 'woocommerce' ), |
| 748 | 748 | 'type' => 'array', |
| 749 | 749 | 'items' => array( |
@@ -752,20 +752,20 @@ discard block |
||
| 752 | 752 | 'default' => array(), |
| 753 | 753 | 'sanitize_callback' => 'wp_parse_id_list', |
| 754 | 754 | ); |
| 755 | - $params['offset'] = array( |
|
| 755 | + $params[ 'offset' ] = array( |
|
| 756 | 756 | 'description' => __( 'Offset the result set by a specific number of items.', 'woocommerce' ), |
| 757 | 757 | 'type' => 'integer', |
| 758 | 758 | 'sanitize_callback' => 'absint', |
| 759 | 759 | 'validate_callback' => 'rest_validate_request_arg', |
| 760 | 760 | ); |
| 761 | - $params['order'] = array( |
|
| 761 | + $params[ 'order' ] = array( |
|
| 762 | 762 | 'description' => __( 'Order sort attribute ascending or descending.', 'woocommerce' ), |
| 763 | 763 | 'type' => 'string', |
| 764 | 764 | 'default' => 'desc', |
| 765 | 765 | 'enum' => array( 'asc', 'desc' ), |
| 766 | 766 | 'validate_callback' => 'rest_validate_request_arg', |
| 767 | 767 | ); |
| 768 | - $params['orderby'] = array( |
|
| 768 | + $params[ 'orderby' ] = array( |
|
| 769 | 769 | 'description' => __( 'Sort collection by object attribute.', 'woocommerce' ), |
| 770 | 770 | 'type' => 'string', |
| 771 | 771 | 'default' => 'date', |
@@ -776,7 +776,7 @@ discard block |
||
| 776 | 776 | ), |
| 777 | 777 | 'validate_callback' => 'rest_validate_request_arg', |
| 778 | 778 | ); |
| 779 | - $params['status'] = array( |
|
| 779 | + $params[ 'status' ] = array( |
|
| 780 | 780 | 'default' => 'all', |
| 781 | 781 | 'description' => __( 'Limit result set to webhooks assigned a specific status.', 'woocommerce' ), |
| 782 | 782 | 'type' => 'string', |
@@ -156,40 +156,40 @@ discard block |
||
| 156 | 156 | // Format decimal values. |
| 157 | 157 | foreach ( $format_decimal as $key ) { |
| 158 | 158 | if ( isset( $data[ $key ] ) ) { |
| 159 | - $data[ $key ] = wc_format_decimal( $data[ $key ], $this->request['dp'] ); |
|
| 159 | + $data[ $key ] = wc_format_decimal( $data[ $key ], $this->request[ 'dp' ] ); |
|
| 160 | 160 | } |
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | // Add SKU and PRICE to products. |
| 164 | 164 | if ( is_callable( array( $item, 'get_product' ) ) ) { |
| 165 | - $data['sku'] = $item->get_product() ? $item->get_product()->get_sku() : null; |
|
| 166 | - $data['price'] = $item->get_quantity() ? $item->get_total() / $item->get_quantity() : 0; |
|
| 165 | + $data[ 'sku' ] = $item->get_product() ? $item->get_product()->get_sku() : null; |
|
| 166 | + $data[ 'price' ] = $item->get_quantity() ? $item->get_total() / $item->get_quantity() : 0; |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | // Format taxes. |
| 170 | - if ( ! empty( $data['taxes']['total'] ) ) { |
|
| 170 | + if ( ! empty( $data[ 'taxes' ][ 'total' ] ) ) { |
|
| 171 | 171 | $taxes = array(); |
| 172 | 172 | |
| 173 | - foreach ( $data['taxes']['total'] as $tax_rate_id => $tax ) { |
|
| 174 | - $taxes[] = array( |
|
| 173 | + foreach ( $data[ 'taxes' ][ 'total' ] as $tax_rate_id => $tax ) { |
|
| 174 | + $taxes[ ] = array( |
|
| 175 | 175 | 'id' => $tax_rate_id, |
| 176 | 176 | 'total' => $tax, |
| 177 | - 'subtotal' => isset( $data['taxes']['subtotal'][ $tax_rate_id ] ) ? $data['taxes']['subtotal'][ $tax_rate_id ] : '', |
|
| 177 | + 'subtotal' => isset( $data[ 'taxes' ][ 'subtotal' ][ $tax_rate_id ] ) ? $data[ 'taxes' ][ 'subtotal' ][ $tax_rate_id ] : '', |
|
| 178 | 178 | ); |
| 179 | 179 | } |
| 180 | - $data['taxes'] = $taxes; |
|
| 181 | - } elseif ( isset( $data['taxes'] ) ) { |
|
| 182 | - $data['taxes'] = array(); |
|
| 180 | + $data[ 'taxes' ] = $taxes; |
|
| 181 | + } elseif ( isset( $data[ 'taxes' ] ) ) { |
|
| 182 | + $data[ 'taxes' ] = array(); |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | // Remove names for coupons, taxes and shipping. |
| 186 | - if ( isset( $data['code'] ) || isset( $data['rate_code'] ) || isset( $data['method_title'] ) ) { |
|
| 187 | - unset( $data['name'] ); |
|
| 186 | + if ( isset( $data[ 'code' ] ) || isset( $data[ 'rate_code' ] ) || isset( $data[ 'method_title' ] ) ) { |
|
| 187 | + unset( $data[ 'name' ] ); |
|
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | // Remove props we don't want to expose. |
| 191 | - unset( $data['order_id'] ); |
|
| 192 | - unset( $data['type'] ); |
|
| 191 | + unset( $data[ 'order_id' ] ); |
|
| 192 | + unset( $data[ 'type' ] ); |
|
| 193 | 193 | |
| 194 | 194 | return $data; |
| 195 | 195 | } |
@@ -209,7 +209,7 @@ discard block |
||
| 209 | 209 | |
| 210 | 210 | // Format decimal values. |
| 211 | 211 | foreach ( $format_decimal as $key ) { |
| 212 | - $data[ $key ] = wc_format_decimal( $data[ $key ], $this->request['dp'] ); |
|
| 212 | + $data[ $key ] = wc_format_decimal( $data[ $key ], $this->request[ 'dp' ] ); |
|
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | // Format date values. |
@@ -220,7 +220,7 @@ discard block |
||
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | // Format the order status. |
| 223 | - $data['status'] = 'wc-' === substr( $data['status'], 0, 3 ) ? substr( $data['status'], 3 ) : $data['status']; |
|
| 223 | + $data[ 'status' ] = 'wc-' === substr( $data[ 'status' ], 0, 3 ) ? substr( $data[ 'status' ], 3 ) : $data[ 'status' ]; |
|
| 224 | 224 | |
| 225 | 225 | // Format line items. |
| 226 | 226 | foreach ( $format_line_items as $key ) { |
@@ -228,62 +228,62 @@ discard block |
||
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | // Refunds. |
| 231 | - $data['refunds'] = array(); |
|
| 231 | + $data[ 'refunds' ] = array(); |
|
| 232 | 232 | foreach ( $object->get_refunds() as $refund ) { |
| 233 | - $data['refunds'][] = array( |
|
| 233 | + $data[ 'refunds' ][ ] = array( |
|
| 234 | 234 | 'id' => $refund->get_id(), |
| 235 | 235 | 'reason' => $refund->get_reason() ? $refund->get_reason() : '', |
| 236 | - 'total' => '-' . wc_format_decimal( $refund->get_amount(), $this->request['dp'] ), |
|
| 236 | + 'total' => '-' . wc_format_decimal( $refund->get_amount(), $this->request[ 'dp' ] ), |
|
| 237 | 237 | ); |
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | // Currency symbols. |
| 241 | - $currency_symbol = get_woocommerce_currency_symbol( $data['currency'] ); |
|
| 242 | - $data['currency_symbol'] = html_entity_decode( $currency_symbol ); |
|
| 241 | + $currency_symbol = get_woocommerce_currency_symbol( $data[ 'currency' ] ); |
|
| 242 | + $data[ 'currency_symbol' ] = html_entity_decode( $currency_symbol ); |
|
| 243 | 243 | |
| 244 | 244 | return array( |
| 245 | 245 | 'id' => $object->get_id(), |
| 246 | - 'parent_id' => $data['parent_id'], |
|
| 247 | - 'number' => $data['number'], |
|
| 248 | - 'order_key' => $data['order_key'], |
|
| 249 | - 'created_via' => $data['created_via'], |
|
| 250 | - 'version' => $data['version'], |
|
| 251 | - 'status' => $data['status'], |
|
| 252 | - 'currency' => $data['currency'], |
|
| 253 | - 'currency_symbol' => $data['currency_symbol'], |
|
| 254 | - 'date_created' => $data['date_created'], |
|
| 255 | - 'date_created_gmt' => $data['date_created_gmt'], |
|
| 256 | - 'date_modified' => $data['date_modified'], |
|
| 257 | - 'date_modified_gmt' => $data['date_modified_gmt'], |
|
| 258 | - 'discount_total' => $data['discount_total'], |
|
| 259 | - 'discount_tax' => $data['discount_tax'], |
|
| 260 | - 'shipping_total' => $data['shipping_total'], |
|
| 261 | - 'shipping_tax' => $data['shipping_tax'], |
|
| 262 | - 'cart_tax' => $data['cart_tax'], |
|
| 263 | - 'total' => $data['total'], |
|
| 264 | - 'total_tax' => $data['total_tax'], |
|
| 265 | - 'prices_include_tax' => $data['prices_include_tax'], |
|
| 266 | - 'customer_id' => $data['customer_id'], |
|
| 267 | - 'customer_ip_address' => $data['customer_ip_address'], |
|
| 268 | - 'customer_user_agent' => $data['customer_user_agent'], |
|
| 269 | - 'customer_note' => $data['customer_note'], |
|
| 270 | - 'billing' => $data['billing'], |
|
| 271 | - 'shipping' => $data['shipping'], |
|
| 272 | - 'payment_method' => $data['payment_method'], |
|
| 273 | - 'payment_method_title' => $data['payment_method_title'], |
|
| 274 | - 'transaction_id' => $data['transaction_id'], |
|
| 275 | - 'date_paid' => $data['date_paid'], |
|
| 276 | - 'date_paid_gmt' => $data['date_paid_gmt'], |
|
| 277 | - 'date_completed' => $data['date_completed'], |
|
| 278 | - 'date_completed_gmt' => $data['date_completed_gmt'], |
|
| 279 | - 'cart_hash' => $data['cart_hash'], |
|
| 280 | - 'meta_data' => $data['meta_data'], |
|
| 281 | - 'line_items' => $data['line_items'], |
|
| 282 | - 'tax_lines' => $data['tax_lines'], |
|
| 283 | - 'shipping_lines' => $data['shipping_lines'], |
|
| 284 | - 'fee_lines' => $data['fee_lines'], |
|
| 285 | - 'coupon_lines' => $data['coupon_lines'], |
|
| 286 | - 'refunds' => $data['refunds'], |
|
| 246 | + 'parent_id' => $data[ 'parent_id' ], |
|
| 247 | + 'number' => $data[ 'number' ], |
|
| 248 | + 'order_key' => $data[ 'order_key' ], |
|
| 249 | + 'created_via' => $data[ 'created_via' ], |
|
| 250 | + 'version' => $data[ 'version' ], |
|
| 251 | + 'status' => $data[ 'status' ], |
|
| 252 | + 'currency' => $data[ 'currency' ], |
|
| 253 | + 'currency_symbol' => $data[ 'currency_symbol' ], |
|
| 254 | + 'date_created' => $data[ 'date_created' ], |
|
| 255 | + 'date_created_gmt' => $data[ 'date_created_gmt' ], |
|
| 256 | + 'date_modified' => $data[ 'date_modified' ], |
|
| 257 | + 'date_modified_gmt' => $data[ 'date_modified_gmt' ], |
|
| 258 | + 'discount_total' => $data[ 'discount_total' ], |
|
| 259 | + 'discount_tax' => $data[ 'discount_tax' ], |
|
| 260 | + 'shipping_total' => $data[ 'shipping_total' ], |
|
| 261 | + 'shipping_tax' => $data[ 'shipping_tax' ], |
|
| 262 | + 'cart_tax' => $data[ 'cart_tax' ], |
|
| 263 | + 'total' => $data[ 'total' ], |
|
| 264 | + 'total_tax' => $data[ 'total_tax' ], |
|
| 265 | + 'prices_include_tax' => $data[ 'prices_include_tax' ], |
|
| 266 | + 'customer_id' => $data[ 'customer_id' ], |
|
| 267 | + 'customer_ip_address' => $data[ 'customer_ip_address' ], |
|
| 268 | + 'customer_user_agent' => $data[ 'customer_user_agent' ], |
|
| 269 | + 'customer_note' => $data[ 'customer_note' ], |
|
| 270 | + 'billing' => $data[ 'billing' ], |
|
| 271 | + 'shipping' => $data[ 'shipping' ], |
|
| 272 | + 'payment_method' => $data[ 'payment_method' ], |
|
| 273 | + 'payment_method_title' => $data[ 'payment_method_title' ], |
|
| 274 | + 'transaction_id' => $data[ 'transaction_id' ], |
|
| 275 | + 'date_paid' => $data[ 'date_paid' ], |
|
| 276 | + 'date_paid_gmt' => $data[ 'date_paid_gmt' ], |
|
| 277 | + 'date_completed' => $data[ 'date_completed' ], |
|
| 278 | + 'date_completed_gmt' => $data[ 'date_completed_gmt' ], |
|
| 279 | + 'cart_hash' => $data[ 'cart_hash' ], |
|
| 280 | + 'meta_data' => $data[ 'meta_data' ], |
|
| 281 | + 'line_items' => $data[ 'line_items' ], |
|
| 282 | + 'tax_lines' => $data[ 'tax_lines' ], |
|
| 283 | + 'shipping_lines' => $data[ 'shipping_lines' ], |
|
| 284 | + 'fee_lines' => $data[ 'fee_lines' ], |
|
| 285 | + 'coupon_lines' => $data[ 'coupon_lines' ], |
|
| 286 | + 'refunds' => $data[ 'refunds' ], |
|
| 287 | 287 | ); |
| 288 | 288 | } |
| 289 | 289 | |
@@ -297,9 +297,9 @@ discard block |
||
| 297 | 297 | */ |
| 298 | 298 | public function prepare_object_for_response( $object, $request ) { |
| 299 | 299 | $this->request = $request; |
| 300 | - $this->request['dp'] = is_null( $this->request['dp'] ) ? wc_get_price_decimals() : absint( $this->request['dp'] ); |
|
| 300 | + $this->request[ 'dp' ] = is_null( $this->request[ 'dp' ] ) ? wc_get_price_decimals() : absint( $this->request[ 'dp' ] ); |
|
| 301 | 301 | $data = $this->get_formatted_item_data( $object ); |
| 302 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
| 302 | + $context = ! empty( $request[ 'context' ] ) ? $request[ 'context' ] : 'view'; |
|
| 303 | 303 | $data = $this->add_additional_fields_to_object( $data, $request ); |
| 304 | 304 | $data = $this->filter_response_by_context( $data, $context ); |
| 305 | 305 | $response = rest_ensure_response( $data ); |
@@ -336,13 +336,13 @@ discard block |
||
| 336 | 336 | ); |
| 337 | 337 | |
| 338 | 338 | if ( 0 !== (int) $object->get_customer_id() ) { |
| 339 | - $links['customer'] = array( |
|
| 339 | + $links[ 'customer' ] = array( |
|
| 340 | 340 | 'href' => rest_url( sprintf( '/%s/customers/%d', $this->namespace, $object->get_customer_id() ) ), |
| 341 | 341 | ); |
| 342 | 342 | } |
| 343 | 343 | |
| 344 | 344 | if ( 0 !== (int) $object->get_parent_id() ) { |
| 345 | - $links['up'] = array( |
|
| 345 | + $links[ 'up' ] = array( |
|
| 346 | 346 | 'href' => rest_url( sprintf( '/%s/orders/%d', $this->namespace, $object->get_parent_id() ) ), |
| 347 | 347 | ); |
| 348 | 348 | } |
@@ -361,71 +361,71 @@ discard block |
||
| 361 | 361 | global $wpdb; |
| 362 | 362 | |
| 363 | 363 | // This is needed to get around an array to string notice in \WC_REST_Orders_V2_Controller::prepare_objects_query. |
| 364 | - $statuses = $request['status']; |
|
| 365 | - unset( $request['status'] ); |
|
| 364 | + $statuses = $request[ 'status' ]; |
|
| 365 | + unset( $request[ 'status' ] ); |
|
| 366 | 366 | $args = parent::prepare_objects_query( $request ); |
| 367 | 367 | |
| 368 | - $args['post_status'] = array(); |
|
| 368 | + $args[ 'post_status' ] = array(); |
|
| 369 | 369 | foreach ( $statuses as $status ) { |
| 370 | 370 | if ( in_array( $status, $this->get_order_statuses(), true ) ) { |
| 371 | - $args['post_status'][] = 'wc-' . $status; |
|
| 371 | + $args[ 'post_status' ][ ] = 'wc-' . $status; |
|
| 372 | 372 | } elseif ( 'any' === $status ) { |
| 373 | 373 | // Set status to "any" and short-circuit out. |
| 374 | - $args['post_status'] = 'any'; |
|
| 374 | + $args[ 'post_status' ] = 'any'; |
|
| 375 | 375 | break; |
| 376 | 376 | } else { |
| 377 | - $args['post_status'][] = $status; |
|
| 377 | + $args[ 'post_status' ][ ] = $status; |
|
| 378 | 378 | } |
| 379 | 379 | } |
| 380 | 380 | |
| 381 | 381 | // Put the statuses back for further processing (next/prev links, etc). |
| 382 | - $request['status'] = $statuses; |
|
| 382 | + $request[ 'status' ] = $statuses; |
|
| 383 | 383 | |
| 384 | 384 | // Customer. |
| 385 | - if ( isset( $request['customer'] ) ) { |
|
| 386 | - if ( ! empty( $args['meta_query'] ) ) { |
|
| 387 | - $args['meta_query'] = array(); // WPCS: slow query ok. |
|
| 385 | + if ( isset( $request[ 'customer' ] ) ) { |
|
| 386 | + if ( ! empty( $args[ 'meta_query' ] ) ) { |
|
| 387 | + $args[ 'meta_query' ] = array(); // WPCS: slow query ok. |
|
| 388 | 388 | } |
| 389 | 389 | |
| 390 | - $args['meta_query'][] = array( |
|
| 390 | + $args[ 'meta_query' ][ ] = array( |
|
| 391 | 391 | 'key' => '_customer_user', |
| 392 | - 'value' => $request['customer'], |
|
| 392 | + 'value' => $request[ 'customer' ], |
|
| 393 | 393 | 'type' => 'NUMERIC', |
| 394 | 394 | ); |
| 395 | 395 | } |
| 396 | 396 | |
| 397 | 397 | // Search by product. |
| 398 | - if ( ! empty( $request['product'] ) ) { |
|
| 398 | + if ( ! empty( $request[ 'product' ] ) ) { |
|
| 399 | 399 | $order_ids = $wpdb->get_col( |
| 400 | 400 | $wpdb->prepare( |
| 401 | 401 | "SELECT order_id |
| 402 | 402 | FROM {$wpdb->prefix}woocommerce_order_items |
| 403 | 403 | WHERE order_item_id IN ( SELECT order_item_id FROM {$wpdb->prefix}woocommerce_order_itemmeta WHERE meta_key = '_product_id' AND meta_value = %d ) |
| 404 | 404 | AND order_item_type = 'line_item'", |
| 405 | - $request['product'] |
|
| 405 | + $request[ 'product' ] |
|
| 406 | 406 | ) |
| 407 | 407 | ); |
| 408 | 408 | |
| 409 | 409 | // Force WP_Query return empty if don't found any order. |
| 410 | 410 | $order_ids = ! empty( $order_ids ) ? $order_ids : array( 0 ); |
| 411 | 411 | |
| 412 | - $args['post__in'] = $order_ids; |
|
| 412 | + $args[ 'post__in' ] = $order_ids; |
|
| 413 | 413 | } |
| 414 | 414 | |
| 415 | 415 | // Search. |
| 416 | - if ( ! empty( $args['s'] ) ) { |
|
| 417 | - $order_ids = wc_order_search( $args['s'] ); |
|
| 416 | + if ( ! empty( $args[ 's' ] ) ) { |
|
| 417 | + $order_ids = wc_order_search( $args[ 's' ] ); |
|
| 418 | 418 | |
| 419 | 419 | if ( ! empty( $order_ids ) ) { |
| 420 | - unset( $args['s'] ); |
|
| 421 | - $args['post__in'] = array_merge( $order_ids, array( 0 ) ); |
|
| 420 | + unset( $args[ 's' ] ); |
|
| 421 | + $args[ 'post__in' ] = array_merge( $order_ids, array( 0 ) ); |
|
| 422 | 422 | } |
| 423 | 423 | } |
| 424 | 424 | |
| 425 | 425 | // Search by partial order number. |
| 426 | - if ( ! empty( $request['number'] ) ) { |
|
| 427 | - $partial_number = trim( $request['number'] ); |
|
| 428 | - $limit = intval( $args['posts_per_page'] ); |
|
| 426 | + if ( ! empty( $request[ 'number' ] ) ) { |
|
| 427 | + $partial_number = trim( $request[ 'number' ] ); |
|
| 428 | + $limit = intval( $args[ 'posts_per_page' ] ); |
|
| 429 | 429 | $order_ids = $wpdb->get_col( |
| 430 | 430 | $wpdb->prepare( |
| 431 | 431 | "SELECT ID |
@@ -440,7 +440,7 @@ discard block |
||
| 440 | 440 | |
| 441 | 441 | // Force \WP_Query return empty if don't found any order. |
| 442 | 442 | $order_ids = empty( $order_ids ) ? array( 0 ) : $order_ids; |
| 443 | - $args['post__in'] = $order_ids; |
|
| 443 | + $args[ 'post__in' ] = $order_ids; |
|
| 444 | 444 | } |
| 445 | 445 | |
| 446 | 446 | return $args; |
@@ -453,7 +453,7 @@ discard block |
||
| 453 | 453 | * @return bool |
| 454 | 454 | */ |
| 455 | 455 | protected function filter_writable_props( $schema ) { |
| 456 | - return empty( $schema['readonly'] ); |
|
| 456 | + return empty( $schema[ 'readonly' ] ); |
|
| 457 | 457 | } |
| 458 | 458 | |
| 459 | 459 | |
@@ -466,10 +466,10 @@ discard block |
||
| 466 | 466 | * @return \WP_Error|WC_Data |
| 467 | 467 | */ |
| 468 | 468 | protected function prepare_object_for_database( $request, $creating = false ) { |
| 469 | - $id = isset( $request['id'] ) ? absint( $request['id'] ) : 0; |
|
| 469 | + $id = isset( $request[ 'id' ] ) ? absint( $request[ 'id' ] ) : 0; |
|
| 470 | 470 | $order = new \WC_Order( $id ); |
| 471 | 471 | $schema = $this->get_item_schema(); |
| 472 | - $data_keys = array_keys( array_filter( $schema['properties'], array( $this, 'filter_writable_props' ) ) ); |
|
| 472 | + $data_keys = array_keys( array_filter( $schema[ 'properties' ], array( $this, 'filter_writable_props' ) ) ); |
|
| 473 | 473 | |
| 474 | 474 | // Handle all writable props. |
| 475 | 475 | foreach ( $data_keys as $key ) { |
@@ -491,8 +491,8 @@ discard block |
||
| 491 | 491 | if ( is_array( $value ) ) { |
| 492 | 492 | foreach ( $value as $item ) { |
| 493 | 493 | if ( is_array( $item ) ) { |
| 494 | - if ( $this->item_is_null( $item ) || ( isset( $item['quantity'] ) && 0 === $item['quantity'] ) ) { |
|
| 495 | - $order->remove_item( $item['id'] ); |
|
| 494 | + if ( $this->item_is_null( $item ) || ( isset( $item[ 'quantity' ] ) && 0 === $item[ 'quantity' ] ) ) { |
|
| 495 | + $order->remove_item( $item[ 'id' ] ); |
|
| 496 | 496 | } else { |
| 497 | 497 | $this->set_item( $order, $key, $item ); |
| 498 | 498 | } |
@@ -503,7 +503,7 @@ discard block |
||
| 503 | 503 | case 'meta_data': |
| 504 | 504 | if ( is_array( $value ) ) { |
| 505 | 505 | foreach ( $value as $meta ) { |
| 506 | - $order->update_meta_data( $meta['key'], $meta['value'], isset( $meta['id'] ) ? $meta['id'] : '' ); |
|
| 506 | + $order->update_meta_data( $meta[ 'key' ], $meta[ 'value' ], isset( $meta[ 'id' ] ) ? $meta[ 'id' ] : '' ); |
|
| 507 | 507 | } |
| 508 | 508 | } |
| 509 | 509 | break; |
@@ -548,15 +548,15 @@ discard block |
||
| 548 | 548 | // Make sure gateways are loaded so hooks from gateways fire on save/create. |
| 549 | 549 | WC()->payment_gateways(); |
| 550 | 550 | |
| 551 | - if ( ! is_null( $request['customer_id'] ) && 0 !== $request['customer_id'] ) { |
|
| 551 | + if ( ! is_null( $request[ 'customer_id' ] ) && 0 !== $request[ 'customer_id' ] ) { |
|
| 552 | 552 | // Make sure customer exists. |
| 553 | - if ( false === get_user_by( 'id', $request['customer_id'] ) ) { |
|
| 553 | + if ( false === get_user_by( 'id', $request[ 'customer_id' ] ) ) { |
|
| 554 | 554 | throw new \WC_REST_Exception( 'woocommerce_rest_invalid_customer_id', __( 'Customer ID is invalid.', 'woocommerce' ), 400 ); |
| 555 | 555 | } |
| 556 | 556 | |
| 557 | 557 | // Make sure customer is part of blog. |
| 558 | - if ( is_multisite() && ! is_user_member_of_blog( $request['customer_id'] ) ) { |
|
| 559 | - add_user_to_blog( get_current_blog_id(), $request['customer_id'], 'customer' ); |
|
| 558 | + if ( is_multisite() && ! is_user_member_of_blog( $request[ 'customer_id' ] ) ) { |
|
| 559 | + add_user_to_blog( get_current_blog_id(), $request[ 'customer_id' ], 'customer' ); |
|
| 560 | 560 | } |
| 561 | 561 | } |
| 562 | 562 | |
@@ -566,7 +566,7 @@ discard block |
||
| 566 | 566 | $object->calculate_totals(); |
| 567 | 567 | } else { |
| 568 | 568 | // If items have changed, recalculate order totals. |
| 569 | - if ( isset( $request['billing'] ) || isset( $request['shipping'] ) || isset( $request['line_items'] ) || isset( $request['shipping_lines'] ) || isset( $request['fee_lines'] ) || isset( $request['coupon_lines'] ) ) { |
|
| 569 | + if ( isset( $request[ 'billing' ] ) || isset( $request[ 'shipping' ] ) || isset( $request[ 'line_items' ] ) || isset( $request[ 'shipping_lines' ] ) || isset( $request[ 'fee_lines' ] ) || isset( $request[ 'coupon_lines' ] ) ) { |
|
| 570 | 570 | $object->calculate_totals( true ); |
| 571 | 571 | } |
| 572 | 572 | } |
@@ -575,16 +575,16 @@ discard block |
||
| 575 | 575 | $this->calculate_coupons( $request, $object ); |
| 576 | 576 | |
| 577 | 577 | // Set status. |
| 578 | - if ( ! empty( $request['status'] ) ) { |
|
| 579 | - $object->set_status( $request['status'] ); |
|
| 578 | + if ( ! empty( $request[ 'status' ] ) ) { |
|
| 579 | + $object->set_status( $request[ 'status' ] ); |
|
| 580 | 580 | } |
| 581 | 581 | |
| 582 | 582 | $object->save(); |
| 583 | 583 | |
| 584 | 584 | // Actions for after the order is saved. |
| 585 | - if ( true === $request['set_paid'] ) { |
|
| 585 | + if ( true === $request[ 'set_paid' ] ) { |
|
| 586 | 586 | if ( $creating || $object->needs_payment() ) { |
| 587 | - $object->payment_complete( $request['transaction_id'] ); |
|
| 587 | + $object->payment_complete( $request[ 'transaction_id' ] ); |
|
| 588 | 588 | } |
| 589 | 589 | } |
| 590 | 590 | |
@@ -619,12 +619,12 @@ discard block |
||
| 619 | 619 | * @throws \WC_REST_Exception When SKU or ID is not valid. |
| 620 | 620 | */ |
| 621 | 621 | protected function get_product_id( $posted ) { |
| 622 | - if ( ! empty( $posted['sku'] ) ) { |
|
| 623 | - $product_id = (int) wc_get_product_id_by_sku( $posted['sku'] ); |
|
| 624 | - } elseif ( ! empty( $posted['product_id'] ) && empty( $posted['variation_id'] ) ) { |
|
| 625 | - $product_id = (int) $posted['product_id']; |
|
| 626 | - } elseif ( ! empty( $posted['variation_id'] ) ) { |
|
| 627 | - $product_id = (int) $posted['variation_id']; |
|
| 622 | + if ( ! empty( $posted[ 'sku' ] ) ) { |
|
| 623 | + $product_id = (int) wc_get_product_id_by_sku( $posted[ 'sku' ] ); |
|
| 624 | + } elseif ( ! empty( $posted[ 'product_id' ] ) && empty( $posted[ 'variation_id' ] ) ) { |
|
| 625 | + $product_id = (int) $posted[ 'product_id' ]; |
|
| 626 | + } elseif ( ! empty( $posted[ 'variation_id' ] ) ) { |
|
| 627 | + $product_id = (int) $posted[ 'variation_id' ]; |
|
| 628 | 628 | } else { |
| 629 | 629 | throw new \WC_REST_Exception( 'woocommerce_rest_required_product_reference', __( 'Product ID or SKU is required.', 'woocommerce' ), 400 ); |
| 630 | 630 | } |
@@ -664,11 +664,11 @@ discard block |
||
| 664 | 664 | * @param array $posted Request data. |
| 665 | 665 | */ |
| 666 | 666 | protected function maybe_set_item_meta_data( $item, $posted ) { |
| 667 | - if ( ! empty( $posted['meta_data'] ) && is_array( $posted['meta_data'] ) ) { |
|
| 668 | - foreach ( $posted['meta_data'] as $meta ) { |
|
| 669 | - if ( isset( $meta['key'] ) ) { |
|
| 670 | - $value = isset( $meta['value'] ) ? $meta['value'] : null; |
|
| 671 | - $item->update_meta_data( $meta['key'], $value, isset( $meta['id'] ) ? $meta['id'] : '' ); |
|
| 667 | + if ( ! empty( $posted[ 'meta_data' ] ) && is_array( $posted[ 'meta_data' ] ) ) { |
|
| 668 | + foreach ( $posted[ 'meta_data' ] as $meta ) { |
|
| 669 | + if ( isset( $meta[ 'key' ] ) ) { |
|
| 670 | + $value = isset( $meta[ 'value' ] ) ? $meta[ 'value' ] : null; |
|
| 671 | + $item->update_meta_data( $meta[ 'key' ], $value, isset( $meta[ 'id' ] ) ? $meta[ 'id' ] : '' ); |
|
| 672 | 672 | } |
| 673 | 673 | } |
| 674 | 674 | } |
@@ -684,14 +684,14 @@ discard block |
||
| 684 | 684 | * @throws WC_REST_Exception Invalid data, server error. |
| 685 | 685 | */ |
| 686 | 686 | protected function prepare_line_items( $posted, $action = 'create', $item = null ) { |
| 687 | - $item = is_null( $item ) ? new \WC_Order_Item_Product( ! empty( $posted['id'] ) ? $posted['id'] : '' ) : $item; |
|
| 687 | + $item = is_null( $item ) ? new \WC_Order_Item_Product( ! empty( $posted[ 'id' ] ) ? $posted[ 'id' ] : '' ) : $item; |
|
| 688 | 688 | $product = wc_get_product( $this->get_product_id( $posted ) ); |
| 689 | 689 | |
| 690 | 690 | if ( $product !== $item->get_product() ) { |
| 691 | 691 | $item->set_product( $product ); |
| 692 | 692 | |
| 693 | 693 | if ( 'create' === $action ) { |
| 694 | - $quantity = isset( $posted['quantity'] ) ? $posted['quantity'] : 1; |
|
| 694 | + $quantity = isset( $posted[ 'quantity' ] ) ? $posted[ 'quantity' ] : 1; |
|
| 695 | 695 | $total = wc_get_price_excluding_tax( $product, array( 'qty' => $quantity ) ); |
| 696 | 696 | $item->set_total( $total ); |
| 697 | 697 | $item->set_subtotal( $total ); |
@@ -714,10 +714,10 @@ discard block |
||
| 714 | 714 | * @throws \WC_REST_Exception Invalid data, server error. |
| 715 | 715 | */ |
| 716 | 716 | protected function prepare_shipping_lines( $posted, $action = 'create', $item = null ) { |
| 717 | - $item = is_null( $item ) ? new \WC_Order_Item_Shipping( ! empty( $posted['id'] ) ? $posted['id'] : '' ) : $item; |
|
| 717 | + $item = is_null( $item ) ? new \WC_Order_Item_Shipping( ! empty( $posted[ 'id' ] ) ? $posted[ 'id' ] : '' ) : $item; |
|
| 718 | 718 | |
| 719 | 719 | if ( 'create' === $action ) { |
| 720 | - if ( empty( $posted['method_id'] ) ) { |
|
| 720 | + if ( empty( $posted[ 'method_id' ] ) ) { |
|
| 721 | 721 | throw new \WC_REST_Exception( 'woocommerce_rest_invalid_shipping_item', __( 'Shipping method ID is required.', 'woocommerce' ), 400 ); |
| 722 | 722 | } |
| 723 | 723 | } |
@@ -738,10 +738,10 @@ discard block |
||
| 738 | 738 | * @throws \WC_REST_Exception Invalid data, server error. |
| 739 | 739 | */ |
| 740 | 740 | protected function prepare_fee_lines( $posted, $action = 'create', $item = null ) { |
| 741 | - $item = is_null( $item ) ? new \WC_Order_Item_Fee( ! empty( $posted['id'] ) ? $posted['id'] : '' ) : $item; |
|
| 741 | + $item = is_null( $item ) ? new \WC_Order_Item_Fee( ! empty( $posted[ 'id' ] ) ? $posted[ 'id' ] : '' ) : $item; |
|
| 742 | 742 | |
| 743 | 743 | if ( 'create' === $action ) { |
| 744 | - if ( empty( $posted['name'] ) ) { |
|
| 744 | + if ( empty( $posted[ 'name' ] ) ) { |
|
| 745 | 745 | throw new \WC_REST_Exception( 'woocommerce_rest_invalid_fee_item', __( 'Fee name is required.', 'woocommerce' ), 400 ); |
| 746 | 746 | } |
| 747 | 747 | } |
@@ -762,10 +762,10 @@ discard block |
||
| 762 | 762 | * @throws \WC_REST_Exception Invalid data, server error. |
| 763 | 763 | */ |
| 764 | 764 | protected function prepare_coupon_lines( $posted, $action = 'create', $item = null ) { |
| 765 | - $item = is_null( $item ) ? new \WC_Order_Item_Coupon( ! empty( $posted['id'] ) ? $posted['id'] : '' ) : $item; |
|
| 765 | + $item = is_null( $item ) ? new \WC_Order_Item_Coupon( ! empty( $posted[ 'id' ] ) ? $posted[ 'id' ] : '' ) : $item; |
|
| 766 | 766 | |
| 767 | 767 | if ( 'create' === $action ) { |
| 768 | - if ( empty( $posted['code'] ) ) { |
|
| 768 | + if ( empty( $posted[ 'code' ] ) ) { |
|
| 769 | 769 | throw new \WC_REST_Exception( 'woocommerce_rest_invalid_coupon_coupon', __( 'Coupon code is required.', 'woocommerce' ), 400 ); |
| 770 | 770 | } |
| 771 | 771 | } |
@@ -789,7 +789,7 @@ discard block |
||
| 789 | 789 | protected function set_item( $order, $item_type, $posted ) { |
| 790 | 790 | global $wpdb; |
| 791 | 791 | |
| 792 | - if ( ! empty( $posted['id'] ) ) { |
|
| 792 | + if ( ! empty( $posted[ 'id' ] ) ) { |
|
| 793 | 793 | $action = 'update'; |
| 794 | 794 | } else { |
| 795 | 795 | $action = 'create'; |
@@ -800,7 +800,7 @@ discard block |
||
| 800 | 800 | |
| 801 | 801 | // Verify provided line item ID is associated with order. |
| 802 | 802 | if ( 'update' === $action ) { |
| 803 | - $item = $order->get_item( absint( $posted['id'] ), false ); |
|
| 803 | + $item = $order->get_item( absint( $posted[ 'id' ] ), false ); |
|
| 804 | 804 | |
| 805 | 805 | if ( ! $item ) { |
| 806 | 806 | throw new \WC_REST_Exception( 'woocommerce_rest_invalid_item_id', __( 'Order item ID provided is not associated with order.', 'woocommerce' ), 400 ); |
@@ -848,7 +848,7 @@ discard block |
||
| 848 | 848 | $order_statuses = array(); |
| 849 | 849 | |
| 850 | 850 | foreach ( array_keys( wc_get_order_statuses() ) as $status ) { |
| 851 | - $order_statuses[] = str_replace( 'wc-', '', $status ); |
|
| 851 | + $order_statuses[ ] = str_replace( 'wc-', '', $status ); |
|
| 852 | 852 | } |
| 853 | 853 | |
| 854 | 854 | return $order_statuses; |
@@ -1707,7 +1707,7 @@ discard block |
||
| 1707 | 1707 | public function get_collection_params() { |
| 1708 | 1708 | $params = parent::get_collection_params(); |
| 1709 | 1709 | |
| 1710 | - $params['status'] = array( |
|
| 1710 | + $params[ 'status' ] = array( |
|
| 1711 | 1711 | 'default' => 'any', |
| 1712 | 1712 | 'description' => __( 'Limit result set to orders which have specific statuses.', 'woocommerce' ), |
| 1713 | 1713 | 'type' => 'array', |
@@ -1717,19 +1717,19 @@ discard block |
||
| 1717 | 1717 | ), |
| 1718 | 1718 | 'validate_callback' => 'rest_validate_request_arg', |
| 1719 | 1719 | ); |
| 1720 | - $params['customer'] = array( |
|
| 1720 | + $params[ 'customer' ] = array( |
|
| 1721 | 1721 | 'description' => __( 'Limit result set to orders assigned a specific customer.', 'woocommerce' ), |
| 1722 | 1722 | 'type' => 'integer', |
| 1723 | 1723 | 'sanitize_callback' => 'absint', |
| 1724 | 1724 | 'validate_callback' => 'rest_validate_request_arg', |
| 1725 | 1725 | ); |
| 1726 | - $params['product'] = array( |
|
| 1726 | + $params[ 'product' ] = array( |
|
| 1727 | 1727 | 'description' => __( 'Limit result set to orders assigned a specific product.', 'woocommerce' ), |
| 1728 | 1728 | 'type' => 'integer', |
| 1729 | 1729 | 'sanitize_callback' => 'absint', |
| 1730 | 1730 | 'validate_callback' => 'rest_validate_request_arg', |
| 1731 | 1731 | ); |
| 1732 | - $params['dp'] = array( |
|
| 1732 | + $params[ 'dp' ] = array( |
|
| 1733 | 1733 | 'default' => wc_get_price_decimals(), |
| 1734 | 1734 | 'description' => __( 'Number of decimal points to use in each resource.', 'woocommerce' ), |
| 1735 | 1735 | 'type' => 'integer', |
@@ -1737,7 +1737,7 @@ discard block |
||
| 1737 | 1737 | 'validate_callback' => 'rest_validate_request_arg', |
| 1738 | 1738 | ); |
| 1739 | 1739 | // This needs to remain a string to support extensions that filter Order Number. |
| 1740 | - $params['number'] = array( |
|
| 1740 | + $params[ 'number' ] = array( |
|
| 1741 | 1741 | 'description' => __( 'Limit result set to orders matching part of an order number.', 'woocommerce' ), |
| 1742 | 1742 | 'type' => 'string', |
| 1743 | 1743 | 'validate_callback' => 'rest_validate_request_arg', |
@@ -1756,7 +1756,7 @@ discard block |
||
| 1756 | 1756 | * @return bool |
| 1757 | 1757 | */ |
| 1758 | 1758 | protected function calculate_coupons( $request, $order ) { |
| 1759 | - if ( ! isset( $request['coupon_lines'] ) || ! is_array( $request['coupon_lines'] ) ) { |
|
| 1759 | + if ( ! isset( $request[ 'coupon_lines' ] ) || ! is_array( $request[ 'coupon_lines' ] ) ) { |
|
| 1760 | 1760 | return false; |
| 1761 | 1761 | } |
| 1762 | 1762 | |
@@ -1765,14 +1765,14 @@ discard block |
||
| 1765 | 1765 | $order->remove_coupon( $coupon->get_code() ); |
| 1766 | 1766 | } |
| 1767 | 1767 | |
| 1768 | - foreach ( $request['coupon_lines'] as $item ) { |
|
| 1768 | + foreach ( $request[ 'coupon_lines' ] as $item ) { |
|
| 1769 | 1769 | if ( is_array( $item ) ) { |
| 1770 | - if ( empty( $item['id'] ) ) { |
|
| 1771 | - if ( empty( $item['code'] ) ) { |
|
| 1770 | + if ( empty( $item[ 'id' ] ) ) { |
|
| 1771 | + if ( empty( $item[ 'code' ] ) ) { |
|
| 1772 | 1772 | throw new \WC_REST_Exception( 'woocommerce_rest_invalid_coupon', __( 'Coupon code is required.', 'woocommerce' ), 400 ); |
| 1773 | 1773 | } |
| 1774 | 1774 | |
| 1775 | - $results = $order->apply_coupon( wc_clean( $item['code'] ) ); |
|
| 1775 | + $results = $order->apply_coupon( wc_clean( $item[ 'code' ] ) ); |
|
| 1776 | 1776 | |
| 1777 | 1777 | if ( is_wp_error( $results ) ) { |
| 1778 | 1778 | throw new \WC_REST_Exception( 'woocommerce_rest_' . $results->get_error_code(), $results->get_error_message(), 400 ); |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | foreach ( $wc_shipping->get_shipping_methods() as $id => $shipping_method ) { |
| 104 | 104 | $method = $this->prepare_item_for_response( $shipping_method, $request ); |
| 105 | 105 | $method = $this->prepare_response_for_collection( $method ); |
| 106 | - $response[] = $method; |
|
| 106 | + $response[ ] = $method; |
|
| 107 | 107 | } |
| 108 | 108 | return rest_ensure_response( $response ); |
| 109 | 109 | } |
@@ -117,11 +117,11 @@ discard block |
||
| 117 | 117 | public function get_item( $request ) { |
| 118 | 118 | $wc_shipping = \WC_Shipping::instance(); |
| 119 | 119 | $methods = $wc_shipping->get_shipping_methods(); |
| 120 | - if ( empty( $methods[ $request['id'] ] ) ) { |
|
| 120 | + if ( empty( $methods[ $request[ 'id' ] ] ) ) { |
|
| 121 | 121 | return new \WP_Error( 'woocommerce_rest_shipping_method_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) ); |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | - $method = $methods[ $request['id'] ]; |
|
| 124 | + $method = $methods[ $request[ 'id' ] ]; |
|
| 125 | 125 | $response = $this->prepare_item_for_response( $method, $request ); |
| 126 | 126 | |
| 127 | 127 | return rest_ensure_response( $response ); |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | 'description' => $method->method_description, |
| 142 | 142 | ); |
| 143 | 143 | |
| 144 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
| 144 | + $context = ! empty( $request[ 'context' ] ) ? $request[ 'context' ] : 'view'; |
|
| 145 | 145 | $data = $this->add_additional_fields_to_object( $data, $request ); |
| 146 | 146 | $data = $this->filter_response_by_context( $data, $context ); |
| 147 | 147 | |
@@ -52,26 +52,26 @@ discard block |
||
| 52 | 52 | * @return array |
| 53 | 53 | */ |
| 54 | 54 | protected function add_additional_fields_schema( $schema ) { |
| 55 | - if ( empty( $schema['title'] ) ) { |
|
| 55 | + if ( empty( $schema[ 'title' ] ) ) { |
|
| 56 | 56 | return $schema; |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | /** |
| 60 | 60 | * Can't use $this->get_object_type otherwise we cause an inf loop. |
| 61 | 61 | */ |
| 62 | - $object_type = $schema['title']; |
|
| 62 | + $object_type = $schema[ 'title' ]; |
|
| 63 | 63 | |
| 64 | 64 | $additional_fields = $this->get_additional_fields( $object_type ); |
| 65 | 65 | |
| 66 | 66 | foreach ( $additional_fields as $field_name => $field_options ) { |
| 67 | - if ( ! $field_options['schema'] ) { |
|
| 67 | + if ( ! $field_options[ 'schema' ] ) { |
|
| 68 | 68 | continue; |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | - $schema['properties'][ $field_name ] = $field_options['schema']; |
|
| 71 | + $schema[ 'properties' ][ $field_name ] = $field_options[ 'schema' ]; |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - $schema['properties'] = apply_filters( 'woocommerce_rest_' . $object_type . '_schema', $schema['properties'] ); |
|
| 74 | + $schema[ 'properties' ] = apply_filters( 'woocommerce_rest_' . $object_type . '_schema', $schema[ 'properties' ] ); |
|
| 75 | 75 | |
| 76 | 76 | return $schema; |
| 77 | 77 | } |
@@ -95,16 +95,16 @@ discard block |
||
| 95 | 95 | $limit = apply_filters( 'woocommerce_rest_batch_items_limit', 100, $this->get_normalized_rest_base() ); |
| 96 | 96 | $total = 0; |
| 97 | 97 | |
| 98 | - if ( ! empty( $items['create'] ) ) { |
|
| 99 | - $total += count( $items['create'] ); |
|
| 98 | + if ( ! empty( $items[ 'create' ] ) ) { |
|
| 99 | + $total += count( $items[ 'create' ] ); |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | - if ( ! empty( $items['update'] ) ) { |
|
| 103 | - $total += count( $items['update'] ); |
|
| 102 | + if ( ! empty( $items[ 'update' ] ) ) { |
|
| 103 | + $total += count( $items[ 'update' ] ); |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | - if ( ! empty( $items['delete'] ) ) { |
|
| 107 | - $total += count( $items['delete'] ); |
|
| 106 | + if ( ! empty( $items[ 'delete' ] ) ) { |
|
| 107 | + $total += count( $items[ 'delete' ] ); |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | if ( $total > $limit ) { |
@@ -139,16 +139,16 @@ discard block |
||
| 139 | 139 | return $limit; |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | - if ( ! empty( $items['create'] ) ) { |
|
| 143 | - foreach ( $items['create'] as $item ) { |
|
| 142 | + if ( ! empty( $items[ 'create' ] ) ) { |
|
| 143 | + foreach ( $items[ 'create' ] as $item ) { |
|
| 144 | 144 | $_item = new \WP_REST_Request( 'POST' ); |
| 145 | 145 | |
| 146 | 146 | // Default parameters. |
| 147 | 147 | $defaults = array(); |
| 148 | 148 | $schema = $this->get_public_item_schema(); |
| 149 | - foreach ( $schema['properties'] as $arg => $options ) { |
|
| 150 | - if ( isset( $options['default'] ) ) { |
|
| 151 | - $defaults[ $arg ] = $options['default']; |
|
| 149 | + foreach ( $schema[ 'properties' ] as $arg => $options ) { |
|
| 150 | + if ( isset( $options[ 'default' ] ) ) { |
|
| 151 | + $defaults[ $arg ] = $options[ 'default' ]; |
|
| 152 | 152 | } |
| 153 | 153 | } |
| 154 | 154 | $_item->set_default_params( $defaults ); |
@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | $_response = $this->create_item( $_item ); |
| 159 | 159 | |
| 160 | 160 | if ( is_wp_error( $_response ) ) { |
| 161 | - $response['create'][] = array( |
|
| 161 | + $response[ 'create' ][ ] = array( |
|
| 162 | 162 | 'id' => 0, |
| 163 | 163 | 'error' => array( |
| 164 | 164 | 'code' => $_response->get_error_code(), |
@@ -167,20 +167,20 @@ discard block |
||
| 167 | 167 | ), |
| 168 | 168 | ); |
| 169 | 169 | } else { |
| 170 | - $response['create'][] = $wp_rest_server->response_to_data( $_response, '' ); |
|
| 170 | + $response[ 'create' ][ ] = $wp_rest_server->response_to_data( $_response, '' ); |
|
| 171 | 171 | } |
| 172 | 172 | } |
| 173 | 173 | } |
| 174 | 174 | |
| 175 | - if ( ! empty( $items['update'] ) ) { |
|
| 176 | - foreach ( $items['update'] as $item ) { |
|
| 175 | + if ( ! empty( $items[ 'update' ] ) ) { |
|
| 176 | + foreach ( $items[ 'update' ] as $item ) { |
|
| 177 | 177 | $_item = new \WP_REST_Request( 'PUT' ); |
| 178 | 178 | $_item->set_body_params( $item ); |
| 179 | 179 | $_response = $this->update_item( $_item ); |
| 180 | 180 | |
| 181 | 181 | if ( is_wp_error( $_response ) ) { |
| 182 | - $response['update'][] = array( |
|
| 183 | - 'id' => $item['id'], |
|
| 182 | + $response[ 'update' ][ ] = array( |
|
| 183 | + 'id' => $item[ 'id' ], |
|
| 184 | 184 | 'error' => array( |
| 185 | 185 | 'code' => $_response->get_error_code(), |
| 186 | 186 | 'message' => $_response->get_error_message(), |
@@ -188,13 +188,13 @@ discard block |
||
| 188 | 188 | ), |
| 189 | 189 | ); |
| 190 | 190 | } else { |
| 191 | - $response['update'][] = $wp_rest_server->response_to_data( $_response, '' ); |
|
| 191 | + $response[ 'update' ][ ] = $wp_rest_server->response_to_data( $_response, '' ); |
|
| 192 | 192 | } |
| 193 | 193 | } |
| 194 | 194 | } |
| 195 | 195 | |
| 196 | - if ( ! empty( $items['delete'] ) ) { |
|
| 197 | - foreach ( $items['delete'] as $id ) { |
|
| 196 | + if ( ! empty( $items[ 'delete' ] ) ) { |
|
| 197 | + foreach ( $items[ 'delete' ] as $id ) { |
|
| 198 | 198 | $id = (int) $id; |
| 199 | 199 | |
| 200 | 200 | if ( 0 === $id ) { |
@@ -211,7 +211,7 @@ discard block |
||
| 211 | 211 | $_response = $this->delete_item( $_item ); |
| 212 | 212 | |
| 213 | 213 | if ( is_wp_error( $_response ) ) { |
| 214 | - $response['delete'][] = array( |
|
| 214 | + $response[ 'delete' ][ ] = array( |
|
| 215 | 215 | 'id' => $id, |
| 216 | 216 | 'error' => array( |
| 217 | 217 | 'code' => $_response->get_error_code(), |
@@ -220,7 +220,7 @@ discard block |
||
| 220 | 220 | ), |
| 221 | 221 | ); |
| 222 | 222 | } else { |
| 223 | - $response['delete'][] = $wp_rest_server->response_to_data( $_response, '' ); |
|
| 223 | + $response[ 'delete' ][ ] = $wp_rest_server->response_to_data( $_response, '' ); |
|
| 224 | 224 | } |
| 225 | 225 | } |
| 226 | 226 | } |
@@ -250,7 +250,7 @@ discard block |
||
| 250 | 250 | * @return string|\WP_Error |
| 251 | 251 | */ |
| 252 | 252 | public function validate_setting_select_field( $value, $setting ) { |
| 253 | - if ( array_key_exists( $value, $setting['options'] ) ) { |
|
| 253 | + if ( array_key_exists( $value, $setting[ 'options' ] ) ) { |
|
| 254 | 254 | return $value; |
| 255 | 255 | } else { |
| 256 | 256 | return new \WP_Error( 'rest_setting_value_invalid', __( 'An invalid setting value was passed.', 'woocommerce' ), array( 'status' => 400 ) ); |
@@ -276,8 +276,8 @@ discard block |
||
| 276 | 276 | |
| 277 | 277 | $final_values = array(); |
| 278 | 278 | foreach ( $values as $value ) { |
| 279 | - if ( array_key_exists( $value, $setting['options'] ) ) { |
|
| 280 | - $final_values[] = $value; |
|
| 279 | + if ( array_key_exists( $value, $setting[ 'options' ] ) ) { |
|
| 280 | + $final_values[ ] = $value; |
|
| 281 | 281 | } |
| 282 | 282 | } |
| 283 | 283 | |
@@ -297,15 +297,15 @@ discard block |
||
| 297 | 297 | return new \WP_Error( 'rest_setting_value_invalid', __( 'An invalid setting value was passed.', 'woocommerce' ), array( 'status' => 400 ) ); |
| 298 | 298 | } |
| 299 | 299 | |
| 300 | - $current = $setting['value']; |
|
| 301 | - if ( isset( $values['width'] ) ) { |
|
| 302 | - $current['width'] = intval( $values['width'] ); |
|
| 300 | + $current = $setting[ 'value' ]; |
|
| 301 | + if ( isset( $values[ 'width' ] ) ) { |
|
| 302 | + $current[ 'width' ] = intval( $values[ 'width' ] ); |
|
| 303 | 303 | } |
| 304 | - if ( isset( $values['height'] ) ) { |
|
| 305 | - $current['height'] = intval( $values['height'] ); |
|
| 304 | + if ( isset( $values[ 'height' ] ) ) { |
|
| 305 | + $current[ 'height' ] = intval( $values[ 'height' ] ); |
|
| 306 | 306 | } |
| 307 | - if ( isset( $values['crop'] ) ) { |
|
| 308 | - $current['crop'] = (bool) $values['crop']; |
|
| 307 | + if ( isset( $values[ 'crop' ] ) ) { |
|
| 308 | + $current[ 'crop' ] = (bool) $values[ 'crop' ]; |
|
| 309 | 309 | } |
| 310 | 310 | return $current; |
| 311 | 311 | } |
@@ -334,7 +334,7 @@ discard block |
||
| 334 | 334 | if ( in_array( $value, array( 'yes', 'no' ), true ) ) { |
| 335 | 335 | return $value; |
| 336 | 336 | } elseif ( empty( $value ) ) { |
| 337 | - $value = isset( $setting['default'] ) ? $setting['default'] : 'no'; |
|
| 337 | + $value = isset( $setting[ 'default' ] ) ? $setting[ 'default' ] : 'no'; |
|
| 338 | 338 | return $value; |
| 339 | 339 | } else { |
| 340 | 340 | return new \WP_Error( 'rest_setting_value_invalid', __( 'An invalid setting value was passed.', 'woocommerce' ), array( 'status' => 400 ) ); |
@@ -376,13 +376,13 @@ discard block |
||
| 376 | 376 | * @return array |
| 377 | 377 | */ |
| 378 | 378 | protected function add_meta_query( $args, $meta_query ) { |
| 379 | - if ( empty( $args['meta_query'] ) ) { |
|
| 380 | - $args['meta_query'] = []; // phpcs:ignore |
|
| 379 | + if ( empty( $args[ 'meta_query' ] ) ) { |
|
| 380 | + $args[ 'meta_query' ] = [ ]; // phpcs:ignore |
|
| 381 | 381 | } |
| 382 | 382 | |
| 383 | - $args['meta_query'][] = $meta_query; |
|
| 383 | + $args[ 'meta_query' ][ ] = $meta_query; |
|
| 384 | 384 | |
| 385 | - return $args['meta_query']; |
|
| 385 | + return $args[ 'meta_query' ]; |
|
| 386 | 386 | } |
| 387 | 387 | |
| 388 | 388 | /** |
@@ -437,21 +437,21 @@ discard block |
||
| 437 | 437 | */ |
| 438 | 438 | public function get_fields_for_response( $request ) { |
| 439 | 439 | $schema = $this->get_item_schema(); |
| 440 | - $fields = isset( $schema['properties'] ) ? array_keys( $schema['properties'] ) : array(); |
|
| 440 | + $fields = isset( $schema[ 'properties' ] ) ? array_keys( $schema[ 'properties' ] ) : array(); |
|
| 441 | 441 | |
| 442 | 442 | $additional_fields = $this->get_additional_fields(); |
| 443 | 443 | foreach ( $additional_fields as $field_name => $field_options ) { |
| 444 | 444 | // For back-compat, include any field with an empty schema |
| 445 | 445 | // because it won't be present in $this->get_item_schema(). |
| 446 | - if ( is_null( $field_options['schema'] ) ) { |
|
| 447 | - $fields[] = $field_name; |
|
| 446 | + if ( is_null( $field_options[ 'schema' ] ) ) { |
|
| 447 | + $fields[ ] = $field_name; |
|
| 448 | 448 | } |
| 449 | 449 | } |
| 450 | 450 | |
| 451 | - if ( ! isset( $request['_fields'] ) ) { |
|
| 451 | + if ( ! isset( $request[ '_fields' ] ) ) { |
|
| 452 | 452 | return $fields; |
| 453 | 453 | } |
| 454 | - $requested_fields = is_array( $request['_fields'] ) ? $request['_fields'] : preg_split( '/[\s,]+/', $request['_fields'] ); |
|
| 454 | + $requested_fields = is_array( $request[ '_fields' ] ) ? $request[ '_fields' ] : preg_split( '/[\s,]+/', $request[ '_fields' ] ); |
|
| 455 | 455 | if ( 0 === count( $requested_fields ) ) { |
| 456 | 456 | return $fields; |
| 457 | 457 | } |
@@ -459,7 +459,7 @@ discard block |
||
| 459 | 459 | $requested_fields = array_map( 'trim', $requested_fields ); |
| 460 | 460 | // Always persist 'id', because it can be needed for add_additional_fields_to_object(). |
| 461 | 461 | if ( in_array( 'id', $fields, true ) ) { |
| 462 | - $requested_fields[] = 'id'; |
|
| 462 | + $requested_fields[ ] = 'id'; |
|
| 463 | 463 | } |
| 464 | 464 | return array_intersect( $fields, $requested_fields ); |
| 465 | 465 | } |
@@ -230,7 +230,7 @@ discard block |
||
| 230 | 230 | foreach ( $attributes as $attribute_obj ) { |
| 231 | 231 | $attribute = $this->prepare_item_for_response( $attribute_obj, $request ); |
| 232 | 232 | $attribute = $this->prepare_response_for_collection( $attribute ); |
| 233 | - $data[] = $attribute; |
|
| 233 | + $data[ ] = $attribute; |
|
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | return rest_ensure_response( $data ); |
@@ -247,11 +247,11 @@ discard block |
||
| 247 | 247 | |
| 248 | 248 | $id = wc_create_attribute( |
| 249 | 249 | array( |
| 250 | - 'name' => $request['name'], |
|
| 251 | - 'slug' => wc_sanitize_taxonomy_name( stripslashes( $request['slug'] ) ), |
|
| 252 | - 'type' => ! empty( $request['type'] ) ? $request['type'] : 'select', |
|
| 253 | - 'order_by' => ! empty( $request['order_by'] ) ? $request['order_by'] : 'menu_order', |
|
| 254 | - 'has_archives' => true === $request['has_archives'], |
|
| 250 | + 'name' => $request[ 'name' ], |
|
| 251 | + 'slug' => wc_sanitize_taxonomy_name( stripslashes( $request[ 'slug' ] ) ), |
|
| 252 | + 'type' => ! empty( $request[ 'type' ] ) ? $request[ 'type' ] : 'select', |
|
| 253 | + 'order_by' => ! empty( $request[ 'order_by' ] ) ? $request[ 'order_by' ] : 'menu_order', |
|
| 254 | + 'has_archives' => true === $request[ 'has_archives' ], |
|
| 255 | 255 | ) |
| 256 | 256 | ); |
| 257 | 257 | |
@@ -293,7 +293,7 @@ discard block |
||
| 293 | 293 | * @return \WP_REST_Request|\WP_Error |
| 294 | 294 | */ |
| 295 | 295 | public function get_item( $request ) { |
| 296 | - $attribute = $this->get_attribute( (int) $request['id'] ); |
|
| 296 | + $attribute = $this->get_attribute( (int) $request[ 'id' ] ); |
|
| 297 | 297 | |
| 298 | 298 | if ( is_wp_error( $attribute ) ) { |
| 299 | 299 | return $attribute; |
@@ -313,15 +313,15 @@ discard block |
||
| 313 | 313 | public function update_item( $request ) { |
| 314 | 314 | global $wpdb; |
| 315 | 315 | |
| 316 | - $id = (int) $request['id']; |
|
| 316 | + $id = (int) $request[ 'id' ]; |
|
| 317 | 317 | $edited = wc_update_attribute( |
| 318 | 318 | $id, |
| 319 | 319 | array( |
| 320 | - 'name' => $request['name'], |
|
| 321 | - 'slug' => wc_sanitize_taxonomy_name( stripslashes( $request['slug'] ) ), |
|
| 322 | - 'type' => $request['type'], |
|
| 323 | - 'order_by' => $request['order_by'], |
|
| 324 | - 'has_archives' => $request['has_archives'], |
|
| 320 | + 'name' => $request[ 'name' ], |
|
| 321 | + 'slug' => wc_sanitize_taxonomy_name( stripslashes( $request[ 'slug' ] ) ), |
|
| 322 | + 'type' => $request[ 'type' ], |
|
| 323 | + 'order_by' => $request[ 'order_by' ], |
|
| 324 | + 'has_archives' => $request[ 'has_archives' ], |
|
| 325 | 325 | ) |
| 326 | 326 | ); |
| 327 | 327 | |
@@ -360,14 +360,14 @@ discard block |
||
| 360 | 360 | * @return \WP_REST_Response|\WP_Error |
| 361 | 361 | */ |
| 362 | 362 | public function delete_item( $request ) { |
| 363 | - $force = isset( $request['force'] ) ? (bool) $request['force'] : false; |
|
| 363 | + $force = isset( $request[ 'force' ] ) ? (bool) $request[ 'force' ] : false; |
|
| 364 | 364 | |
| 365 | 365 | // We don't support trashing for this type, error out. |
| 366 | 366 | if ( ! $force ) { |
| 367 | 367 | return new \WP_Error( 'woocommerce_rest_trash_not_supported', __( 'Resource does not support trashing.', 'woocommerce' ), array( 'status' => 501 ) ); |
| 368 | 368 | } |
| 369 | 369 | |
| 370 | - $attribute = $this->get_attribute( (int) $request['id'] ); |
|
| 370 | + $attribute = $this->get_attribute( (int) $request[ 'id' ] ); |
|
| 371 | 371 | |
| 372 | 372 | if ( is_wp_error( $attribute ) ) { |
| 373 | 373 | return $attribute; |
@@ -418,7 +418,7 @@ discard block |
||
| 418 | 418 | 'has_archives' => (bool) $item->attribute_public, |
| 419 | 419 | ); |
| 420 | 420 | |
| 421 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
| 421 | + $context = ! empty( $request[ 'context' ] ) ? $request[ 'context' ] : 'view'; |
|
| 422 | 422 | $data = $this->add_additional_fields_to_object( $data, $request ); |
| 423 | 423 | $data = $this->filter_response_by_context( $data, $context ); |
| 424 | 424 | |
@@ -524,7 +524,7 @@ discard block |
||
| 524 | 524 | */ |
| 525 | 525 | public function get_collection_params() { |
| 526 | 526 | $params = array(); |
| 527 | - $params['context'] = $this->get_context_param( array( 'default' => 'view' ) ); |
|
| 527 | + $params[ 'context' ] = $this->get_context_param( array( 'default' => 'view' ) ); |
|
| 528 | 528 | |
| 529 | 529 | return $params; |
| 530 | 530 | } |
@@ -540,8 +540,8 @@ discard block |
||
| 540 | 540 | return $this->attribute; |
| 541 | 541 | } |
| 542 | 542 | |
| 543 | - if ( $request['id'] ) { |
|
| 544 | - $name = wc_attribute_taxonomy_name_by_id( (int) $request['id'] ); |
|
| 543 | + if ( $request[ 'id' ] ) { |
|
| 544 | + $name = wc_attribute_taxonomy_name_by_id( (int) $request[ 'id' ] ); |
|
| 545 | 545 | |
| 546 | 546 | $this->attribute = $name; |
| 547 | 547 | } |
@@ -27,7 +27,7 @@ |
||
| 27 | 27 | * |
| 28 | 28 | * @var array |
| 29 | 29 | */ |
| 30 | - protected static $classmap = []; |
|
| 30 | + protected static $classmap = [ ]; |
|
| 31 | 31 | |
| 32 | 32 | /** |
| 33 | 33 | * Register the autoloader. |