@@ -132,32 +132,32 @@ discard block |
||
| 132 | 132 | public function get_items( $request ) { |
| 133 | 133 | $taxonomy = $this->get_taxonomy( $request ); |
| 134 | 134 | $prepared_args = array( |
| 135 | - 'exclude' => $request['exclude'], |
|
| 136 | - 'include' => $request['include'], |
|
| 137 | - 'order' => $request['order'], |
|
| 138 | - 'orderby' => $request['orderby'], |
|
| 139 | - 'product' => $request['product'], |
|
| 140 | - 'hide_empty' => $request['hide_empty'], |
|
| 141 | - 'number' => $request['per_page'], |
|
| 142 | - 'search' => $request['search'], |
|
| 143 | - 'slug' => $request['slug'], |
|
| 135 | + 'exclude' => $request[ 'exclude' ], |
|
| 136 | + 'include' => $request[ 'include' ], |
|
| 137 | + 'order' => $request[ 'order' ], |
|
| 138 | + 'orderby' => $request[ 'orderby' ], |
|
| 139 | + 'product' => $request[ 'product' ], |
|
| 140 | + 'hide_empty' => $request[ 'hide_empty' ], |
|
| 141 | + 'number' => $request[ 'per_page' ], |
|
| 142 | + 'search' => $request[ 'search' ], |
|
| 143 | + 'slug' => $request[ 'slug' ], |
|
| 144 | 144 | ); |
| 145 | 145 | |
| 146 | - if ( ! empty( $request['offset'] ) ) { |
|
| 147 | - $prepared_args['offset'] = $request['offset']; |
|
| 146 | + if ( ! empty( $request[ 'offset' ] ) ) { |
|
| 147 | + $prepared_args[ 'offset' ] = $request[ 'offset' ]; |
|
| 148 | 148 | } else { |
| 149 | - $prepared_args['offset'] = ( $request['page'] - 1 ) * $prepared_args['number']; |
|
| 149 | + $prepared_args[ 'offset' ] = ( $request[ 'page' ] - 1 ) * $prepared_args[ 'number' ]; |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | $taxonomy_obj = get_taxonomy( $taxonomy ); |
| 153 | 153 | |
| 154 | - if ( $taxonomy_obj->hierarchical && isset( $request['parent'] ) ) { |
|
| 155 | - if ( 0 === $request['parent'] ) { |
|
| 154 | + if ( $taxonomy_obj->hierarchical && isset( $request[ 'parent' ] ) ) { |
|
| 155 | + if ( 0 === $request[ 'parent' ] ) { |
|
| 156 | 156 | // Only query top-level terms. |
| 157 | - $prepared_args['parent'] = 0; |
|
| 157 | + $prepared_args[ 'parent' ] = 0; |
|
| 158 | 158 | } else { |
| 159 | - if ( $request['parent'] ) { |
|
| 160 | - $prepared_args['parent'] = $request['parent']; |
|
| 159 | + if ( $request[ 'parent' ] ) { |
|
| 160 | + $prepared_args[ 'parent' ] = $request[ 'parent' ]; |
|
| 161 | 161 | } |
| 162 | 162 | } |
| 163 | 163 | } |
@@ -176,20 +176,20 @@ discard block |
||
| 176 | 176 | */ |
| 177 | 177 | $prepared_args = apply_filters( "woocommerce_rest_{$taxonomy}_query", $prepared_args, $request ); |
| 178 | 178 | |
| 179 | - if ( ! empty( $prepared_args['product'] ) ) { |
|
| 179 | + if ( ! empty( $prepared_args[ 'product' ] ) ) { |
|
| 180 | 180 | $query_result = $this->get_terms_for_product( $prepared_args, $request ); |
| 181 | 181 | $total_terms = $this->total_terms; |
| 182 | 182 | } else { |
| 183 | 183 | $query_result = get_terms( $taxonomy, $prepared_args ); |
| 184 | 184 | |
| 185 | 185 | $count_args = $prepared_args; |
| 186 | - unset( $count_args['number'] ); |
|
| 187 | - unset( $count_args['offset'] ); |
|
| 186 | + unset( $count_args[ 'number' ] ); |
|
| 187 | + unset( $count_args[ 'offset' ] ); |
|
| 188 | 188 | $total_terms = wp_count_terms( $taxonomy, $count_args ); |
| 189 | 189 | |
| 190 | 190 | // Ensure we don't return results when offset is out of bounds. |
| 191 | 191 | // See https://core.trac.wordpress.org/ticket/35935. |
| 192 | - if ( $prepared_args['offset'] && $prepared_args['offset'] >= $total_terms ) { |
|
| 192 | + if ( $prepared_args[ 'offset' ] && $prepared_args[ 'offset' ] >= $total_terms ) { |
|
| 193 | 193 | $query_result = array(); |
| 194 | 194 | } |
| 195 | 195 | |
@@ -201,11 +201,11 @@ discard block |
||
| 201 | 201 | $response = array(); |
| 202 | 202 | foreach ( $query_result as $term ) { |
| 203 | 203 | $data = $this->prepare_item_for_response( $term, $request ); |
| 204 | - $response[] = $this->prepare_response_for_collection( $data ); |
|
| 204 | + $response[ ] = $this->prepare_response_for_collection( $data ); |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | // Store pagination values for headers then unset for count query. |
| 208 | - $per_page = (int) $prepared_args['number']; |
|
| 208 | + $per_page = (int) $prepared_args[ 'number' ]; |
|
| 209 | 209 | $max_pages = ceil( $total_terms / $per_page ); |
| 210 | 210 | |
| 211 | 211 | $response = rest_ensure_response( $response ); |
@@ -222,21 +222,21 @@ discard block |
||
| 222 | 222 | */ |
| 223 | 223 | public function create_item( $request ) { |
| 224 | 224 | $taxonomy = $this->get_taxonomy( $request ); |
| 225 | - $name = $request['name']; |
|
| 225 | + $name = $request[ 'name' ]; |
|
| 226 | 226 | $args = array(); |
| 227 | 227 | $schema = $this->get_item_schema(); |
| 228 | 228 | |
| 229 | - if ( ! empty( $schema['properties']['description'] ) && isset( $request['description'] ) ) { |
|
| 230 | - $args['description'] = $request['description']; |
|
| 229 | + if ( ! empty( $schema[ 'properties' ][ 'description' ] ) && isset( $request[ 'description' ] ) ) { |
|
| 230 | + $args[ 'description' ] = $request[ 'description' ]; |
|
| 231 | 231 | } |
| 232 | - if ( isset( $request['slug'] ) ) { |
|
| 233 | - $args['slug'] = $request['slug']; |
|
| 232 | + if ( isset( $request[ 'slug' ] ) ) { |
|
| 233 | + $args[ 'slug' ] = $request[ 'slug' ]; |
|
| 234 | 234 | } |
| 235 | - if ( isset( $request['parent'] ) ) { |
|
| 235 | + if ( isset( $request[ 'parent' ] ) ) { |
|
| 236 | 236 | if ( ! is_taxonomy_hierarchical( $taxonomy ) ) { |
| 237 | 237 | return new \WP_Error( 'woocommerce_rest_taxonomy_not_hierarchical', __( 'Can not set resource parent, taxonomy is not hierarchical.', 'woocommerce-rest-api' ), array( 'status' => 400 ) ); |
| 238 | 238 | } |
| 239 | - $args['parent'] = $request['parent']; |
|
| 239 | + $args[ 'parent' ] = $request[ 'parent' ]; |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | $term = wp_insert_term( $name, $taxonomy, $args ); |
@@ -247,13 +247,13 @@ discard block |
||
| 247 | 247 | // give them the identifier they can actually use. |
| 248 | 248 | $term_id = $term->get_error_data( 'term_exists' ); |
| 249 | 249 | if ( $term_id ) { |
| 250 | - $error_data['resource_id'] = $term_id; |
|
| 250 | + $error_data[ 'resource_id' ] = $term_id; |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | return new \WP_Error( $term->get_error_code(), $term->get_error_message(), $error_data ); |
| 254 | 254 | } |
| 255 | 255 | |
| 256 | - $term = get_term( $term['term_id'], $taxonomy ); |
|
| 256 | + $term = get_term( $term[ 'term_id' ], $taxonomy ); |
|
| 257 | 257 | |
| 258 | 258 | $this->update_additional_fields_for_object( $term, $request ); |
| 259 | 259 | |
@@ -280,8 +280,8 @@ discard block |
||
| 280 | 280 | $response->set_status( 201 ); |
| 281 | 281 | |
| 282 | 282 | $base = '/' . $this->namespace . '/' . $this->rest_base; |
| 283 | - if ( ! empty( $request['attribute_id'] ) ) { |
|
| 284 | - $base = str_replace( '(?P<attribute_id>[\d]+)', (int) $request['attribute_id'], $base ); |
|
| 283 | + if ( ! empty( $request[ 'attribute_id' ] ) ) { |
|
| 284 | + $base = str_replace( '(?P<attribute_id>[\d]+)', (int) $request[ 'attribute_id' ], $base ); |
|
| 285 | 285 | } |
| 286 | 286 | |
| 287 | 287 | $response->header( 'Location', rest_url( $base . '/' . $term->term_id ) ); |
@@ -297,7 +297,7 @@ discard block |
||
| 297 | 297 | */ |
| 298 | 298 | public function get_item( $request ) { |
| 299 | 299 | $taxonomy = $this->get_taxonomy( $request ); |
| 300 | - $term = get_term( (int) $request['id'], $taxonomy ); |
|
| 300 | + $term = get_term( (int) $request[ 'id' ], $taxonomy ); |
|
| 301 | 301 | |
| 302 | 302 | if ( is_wp_error( $term ) ) { |
| 303 | 303 | return $term; |
@@ -316,24 +316,24 @@ discard block |
||
| 316 | 316 | */ |
| 317 | 317 | public function update_item( $request ) { |
| 318 | 318 | $taxonomy = $this->get_taxonomy( $request ); |
| 319 | - $term = get_term( (int) $request['id'], $taxonomy ); |
|
| 319 | + $term = get_term( (int) $request[ 'id' ], $taxonomy ); |
|
| 320 | 320 | $schema = $this->get_item_schema(); |
| 321 | 321 | $prepared_args = array(); |
| 322 | 322 | |
| 323 | - if ( isset( $request['name'] ) ) { |
|
| 324 | - $prepared_args['name'] = $request['name']; |
|
| 323 | + if ( isset( $request[ 'name' ] ) ) { |
|
| 324 | + $prepared_args[ 'name' ] = $request[ 'name' ]; |
|
| 325 | 325 | } |
| 326 | - if ( ! empty( $schema['properties']['description'] ) && isset( $request['description'] ) ) { |
|
| 327 | - $prepared_args['description'] = $request['description']; |
|
| 326 | + if ( ! empty( $schema[ 'properties' ][ 'description' ] ) && isset( $request[ 'description' ] ) ) { |
|
| 327 | + $prepared_args[ 'description' ] = $request[ 'description' ]; |
|
| 328 | 328 | } |
| 329 | - if ( isset( $request['slug'] ) ) { |
|
| 330 | - $prepared_args['slug'] = $request['slug']; |
|
| 329 | + if ( isset( $request[ 'slug' ] ) ) { |
|
| 330 | + $prepared_args[ 'slug' ] = $request[ 'slug' ]; |
|
| 331 | 331 | } |
| 332 | - if ( isset( $request['parent'] ) ) { |
|
| 332 | + if ( isset( $request[ 'parent' ] ) ) { |
|
| 333 | 333 | if ( ! is_taxonomy_hierarchical( $taxonomy ) ) { |
| 334 | 334 | return new \WP_Error( 'woocommerce_rest_taxonomy_not_hierarchical', __( 'Can not set resource parent, taxonomy is not hierarchical.', 'woocommerce-rest-api' ), array( 'status' => 400 ) ); |
| 335 | 335 | } |
| 336 | - $prepared_args['parent'] = $request['parent']; |
|
| 336 | + $prepared_args[ 'parent' ] = $request[ 'parent' ]; |
|
| 337 | 337 | } |
| 338 | 338 | |
| 339 | 339 | // Only update the term if we haz something to update. |
@@ -344,7 +344,7 @@ discard block |
||
| 344 | 344 | } |
| 345 | 345 | } |
| 346 | 346 | |
| 347 | - $term = get_term( (int) $request['id'], $taxonomy ); |
|
| 347 | + $term = get_term( (int) $request[ 'id' ], $taxonomy ); |
|
| 348 | 348 | |
| 349 | 349 | $this->update_additional_fields_for_object( $term, $request ); |
| 350 | 350 | |
@@ -376,19 +376,19 @@ discard block |
||
| 376 | 376 | */ |
| 377 | 377 | public function delete_item( $request ) { |
| 378 | 378 | $taxonomy = $this->get_taxonomy( $request ); |
| 379 | - $force = isset( $request['force'] ) ? (bool) $request['force'] : false; |
|
| 379 | + $force = isset( $request[ 'force' ] ) ? (bool) $request[ 'force' ] : false; |
|
| 380 | 380 | |
| 381 | 381 | // We don't support trashing for this type, error out. |
| 382 | 382 | if ( ! $force ) { |
| 383 | 383 | return new \WP_Error( 'woocommerce_rest_trash_not_supported', __( 'Resource does not support trashing.', 'woocommerce-rest-api' ), array( 'status' => 501 ) ); |
| 384 | 384 | } |
| 385 | 385 | |
| 386 | - $term = get_term( (int) $request['id'], $taxonomy ); |
|
| 386 | + $term = get_term( (int) $request[ 'id' ], $taxonomy ); |
|
| 387 | 387 | // Get default category id. |
| 388 | 388 | $default_category_id = absint( get_option( 'default_product_cat', 0 ) ); |
| 389 | 389 | |
| 390 | 390 | // Prevent deleting the default product category. |
| 391 | - if ( $default_category_id === (int) $request['id'] ) { |
|
| 391 | + if ( $default_category_id === (int) $request[ 'id' ] ) { |
|
| 392 | 392 | return new \WP_Error( 'woocommerce_rest_cannot_delete', __( 'Default product category cannot be deleted.', 'woocommerce-rest-api' ), array( 'status' => 500 ) ); |
| 393 | 393 | } |
| 394 | 394 | |
@@ -422,8 +422,8 @@ discard block |
||
| 422 | 422 | protected function prepare_links( $item, $request ) { |
| 423 | 423 | $base = '/' . $this->namespace . '/' . $this->rest_base; |
| 424 | 424 | |
| 425 | - if ( ! empty( $request['attribute_id'] ) ) { |
|
| 426 | - $base = str_replace( '(?P<attribute_id>[\d]+)', (int) $request['attribute_id'], $base ); |
|
| 425 | + if ( ! empty( $request[ 'attribute_id' ] ) ) { |
|
| 426 | + $base = str_replace( '(?P<attribute_id>[\d]+)', (int) $request[ 'attribute_id' ], $base ); |
|
| 427 | 427 | } |
| 428 | 428 | |
| 429 | 429 | $links = array( |
@@ -438,7 +438,7 @@ discard block |
||
| 438 | 438 | if ( $item->parent ) { |
| 439 | 439 | $parent_term = get_term( (int) $item->parent, $item->taxonomy ); |
| 440 | 440 | if ( $parent_term ) { |
| 441 | - $links['up'] = array( |
|
| 441 | + $links[ 'up' ] = array( |
|
| 442 | 442 | 'href' => rest_url( trailingslashit( $base ) . $parent_term->term_id ), |
| 443 | 443 | ); |
| 444 | 444 | } |
@@ -473,7 +473,7 @@ discard block |
||
| 473 | 473 | protected function get_terms_for_product( $prepared_args, $request ) { |
| 474 | 474 | $taxonomy = $this->get_taxonomy( $request ); |
| 475 | 475 | |
| 476 | - $query_result = get_the_terms( $prepared_args['product'], $taxonomy ); |
|
| 476 | + $query_result = get_the_terms( $prepared_args[ 'product' ], $taxonomy ); |
|
| 477 | 477 | if ( empty( $query_result ) ) { |
| 478 | 478 | $this->total_terms = 0; |
| 479 | 479 | return array(); |
@@ -481,8 +481,8 @@ discard block |
||
| 481 | 481 | |
| 482 | 482 | // get_items() verifies that we don't have `include` set, and default. |
| 483 | 483 | // ordering is by `name`. |
| 484 | - if ( ! in_array( $prepared_args['orderby'], array( 'name', 'none', 'include' ), true ) ) { |
|
| 485 | - switch ( $prepared_args['orderby'] ) { |
|
| 484 | + if ( ! in_array( $prepared_args[ 'orderby' ], array( 'name', 'none', 'include' ), true ) ) { |
|
| 485 | + switch ( $prepared_args[ 'orderby' ] ) { |
|
| 486 | 486 | case 'id': |
| 487 | 487 | $this->sort_column = 'term_id'; |
| 488 | 488 | break; |
@@ -490,18 +490,18 @@ discard block |
||
| 490 | 490 | case 'term_group': |
| 491 | 491 | case 'description': |
| 492 | 492 | case 'count': |
| 493 | - $this->sort_column = $prepared_args['orderby']; |
|
| 493 | + $this->sort_column = $prepared_args[ 'orderby' ]; |
|
| 494 | 494 | break; |
| 495 | 495 | } |
| 496 | 496 | usort( $query_result, array( $this, 'compare_terms' ) ); |
| 497 | 497 | } |
| 498 | - if ( strtolower( $prepared_args['order'] ) !== 'asc' ) { |
|
| 498 | + if ( strtolower( $prepared_args[ 'order' ] ) !== 'asc' ) { |
|
| 499 | 499 | $query_result = array_reverse( $query_result ); |
| 500 | 500 | } |
| 501 | 501 | |
| 502 | 502 | // Pagination. |
| 503 | 503 | $this->total_terms = count( $query_result ); |
| 504 | - $query_result = array_slice( $query_result, $prepared_args['offset'], $prepared_args['number'] ); |
|
| 504 | + $query_result = array_slice( $query_result, $prepared_args[ 'offset' ], $prepared_args[ 'number' ] ); |
|
| 505 | 505 | |
| 506 | 506 | return $query_result; |
| 507 | 507 | } |
@@ -542,9 +542,9 @@ discard block |
||
| 542 | 542 | $taxonomy->hierarchical = true; |
| 543 | 543 | } |
| 544 | 544 | |
| 545 | - $params['context']['default'] = 'view'; |
|
| 545 | + $params[ 'context' ][ 'default' ] = 'view'; |
|
| 546 | 546 | |
| 547 | - $params['exclude'] = array( |
|
| 547 | + $params[ 'exclude' ] = array( |
|
| 548 | 548 | 'description' => __( 'Ensure result set excludes specific IDs.', 'woocommerce-rest-api' ), |
| 549 | 549 | 'type' => 'array', |
| 550 | 550 | 'items' => array( |
@@ -553,7 +553,7 @@ discard block |
||
| 553 | 553 | 'default' => array(), |
| 554 | 554 | 'sanitize_callback' => 'wp_parse_id_list', |
| 555 | 555 | ); |
| 556 | - $params['include'] = array( |
|
| 556 | + $params[ 'include' ] = array( |
|
| 557 | 557 | 'description' => __( 'Limit result set to specific ids.', 'woocommerce-rest-api' ), |
| 558 | 558 | 'type' => 'array', |
| 559 | 559 | 'items' => array( |
@@ -563,14 +563,14 @@ discard block |
||
| 563 | 563 | 'sanitize_callback' => 'wp_parse_id_list', |
| 564 | 564 | ); |
| 565 | 565 | if ( ! $taxonomy->hierarchical ) { |
| 566 | - $params['offset'] = array( |
|
| 566 | + $params[ 'offset' ] = array( |
|
| 567 | 567 | 'description' => __( 'Offset the result set by a specific number of items.', 'woocommerce-rest-api' ), |
| 568 | 568 | 'type' => 'integer', |
| 569 | 569 | 'sanitize_callback' => 'absint', |
| 570 | 570 | 'validate_callback' => 'rest_validate_request_arg', |
| 571 | 571 | ); |
| 572 | 572 | } |
| 573 | - $params['order'] = array( |
|
| 573 | + $params[ 'order' ] = array( |
|
| 574 | 574 | 'description' => __( 'Order sort attribute ascending or descending.', 'woocommerce-rest-api' ), |
| 575 | 575 | 'type' => 'string', |
| 576 | 576 | 'sanitize_callback' => 'sanitize_key', |
@@ -581,7 +581,7 @@ discard block |
||
| 581 | 581 | ), |
| 582 | 582 | 'validate_callback' => 'rest_validate_request_arg', |
| 583 | 583 | ); |
| 584 | - $params['orderby'] = array( |
|
| 584 | + $params[ 'orderby' ] = array( |
|
| 585 | 585 | 'description' => __( 'Sort collection by resource attribute.', 'woocommerce-rest-api' ), |
| 586 | 586 | 'type' => 'string', |
| 587 | 587 | 'sanitize_callback' => 'sanitize_key', |
@@ -597,27 +597,27 @@ discard block |
||
| 597 | 597 | ), |
| 598 | 598 | 'validate_callback' => 'rest_validate_request_arg', |
| 599 | 599 | ); |
| 600 | - $params['hide_empty'] = array( |
|
| 600 | + $params[ 'hide_empty' ] = array( |
|
| 601 | 601 | 'description' => __( 'Whether to hide resources not assigned to any products.', 'woocommerce-rest-api' ), |
| 602 | 602 | 'type' => 'boolean', |
| 603 | 603 | 'default' => false, |
| 604 | 604 | 'validate_callback' => 'rest_validate_request_arg', |
| 605 | 605 | ); |
| 606 | 606 | if ( $taxonomy->hierarchical ) { |
| 607 | - $params['parent'] = array( |
|
| 607 | + $params[ 'parent' ] = array( |
|
| 608 | 608 | 'description' => __( 'Limit result set to resources assigned to a specific parent.', 'woocommerce-rest-api' ), |
| 609 | 609 | 'type' => 'integer', |
| 610 | 610 | 'sanitize_callback' => 'absint', |
| 611 | 611 | 'validate_callback' => 'rest_validate_request_arg', |
| 612 | 612 | ); |
| 613 | 613 | } |
| 614 | - $params['product'] = array( |
|
| 614 | + $params[ 'product' ] = array( |
|
| 615 | 615 | 'description' => __( 'Limit result set to resources assigned to a specific product.', 'woocommerce-rest-api' ), |
| 616 | 616 | 'type' => 'integer', |
| 617 | 617 | 'default' => null, |
| 618 | 618 | 'validate_callback' => 'rest_validate_request_arg', |
| 619 | 619 | ); |
| 620 | - $params['slug'] = array( |
|
| 620 | + $params[ 'slug' ] = array( |
|
| 621 | 621 | 'description' => __( 'Limit result set to resources with a specific slug.', 'woocommerce-rest-api' ), |
| 622 | 622 | 'type' => 'string', |
| 623 | 623 | 'validate_callback' => 'rest_validate_request_arg', |
@@ -639,8 +639,8 @@ discard block |
||
| 639 | 639 | return $this->taxonomy; |
| 640 | 640 | } |
| 641 | 641 | |
| 642 | - if ( ! empty( $request['attribute_id'] ) ) { |
|
| 643 | - $taxonomy = wc_attribute_taxonomy_name_by_id( (int) $request['attribute_id'] ); |
|
| 642 | + if ( ! empty( $request[ 'attribute_id' ] ) ) { |
|
| 643 | + $taxonomy = wc_attribute_taxonomy_name_by_id( (int) $request[ 'attribute_id' ] ); |
|
| 644 | 644 | |
| 645 | 645 | $this->taxonomy = $taxonomy; |
| 646 | 646 | } |
@@ -140,18 +140,18 @@ discard block |
||
| 140 | 140 | */ |
| 141 | 141 | public function get_items( $request ) { |
| 142 | 142 | $args = array(); |
| 143 | - $args['order'] = $request['order']; |
|
| 144 | - $args['orderby'] = $request['orderby']; |
|
| 145 | - $args['status'] = 'all' === $request['status'] ? '' : $request['status']; |
|
| 146 | - $args['include'] = implode( ',', $request['include'] ); |
|
| 147 | - $args['exclude'] = implode( ',', $request['exclude'] ); |
|
| 148 | - $args['limit'] = $request['per_page']; |
|
| 149 | - $args['search'] = $request['search']; |
|
| 150 | - $args['before'] = $request['before']; |
|
| 151 | - $args['after'] = $request['after']; |
|
| 152 | - |
|
| 153 | - if ( empty( $request['offset'] ) ) { |
|
| 154 | - $args['offset'] = 1 < $request['page'] ? ( $request['page'] - 1 ) * $args['limit'] : 0; |
|
| 143 | + $args[ 'order' ] = $request[ 'order' ]; |
|
| 144 | + $args[ 'orderby' ] = $request[ 'orderby' ]; |
|
| 145 | + $args[ 'status' ] = 'all' === $request[ 'status' ] ? '' : $request[ 'status' ]; |
|
| 146 | + $args[ 'include' ] = implode( ',', $request[ 'include' ] ); |
|
| 147 | + $args[ 'exclude' ] = implode( ',', $request[ 'exclude' ] ); |
|
| 148 | + $args[ 'limit' ] = $request[ 'per_page' ]; |
|
| 149 | + $args[ 'search' ] = $request[ 'search' ]; |
|
| 150 | + $args[ 'before' ] = $request[ 'before' ]; |
|
| 151 | + $args[ 'after' ] = $request[ 'after' ]; |
|
| 152 | + |
|
| 153 | + if ( empty( $request[ 'offset' ] ) ) { |
|
| 154 | + $args[ 'offset' ] = 1 < $request[ 'page' ] ? ( $request[ 'page' ] - 1 ) * $args[ 'limit' ] : 0; |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | /** |
@@ -161,8 +161,8 @@ discard block |
||
| 161 | 161 | * @param \WP_REST_Request $request The current request. |
| 162 | 162 | */ |
| 163 | 163 | $prepared_args = apply_filters( 'woocommerce_rest_webhook_query', $args, $request ); |
| 164 | - unset( $prepared_args['page'] ); |
|
| 165 | - $prepared_args['paginate'] = true; |
|
| 164 | + unset( $prepared_args[ 'page' ] ); |
|
| 165 | + $prepared_args[ 'paginate' ] = true; |
|
| 166 | 166 | |
| 167 | 167 | // Get the webhooks. |
| 168 | 168 | $webhooks = array(); |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | $data = $this->prepare_item_for_response( $object, $request ); |
| 181 | - $webhooks[] = $this->prepare_response_for_collection( $data ); |
|
| 181 | + $webhooks[ ] = $this->prepare_response_for_collection( $data ); |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | * @return \WP_Error|\WP_REST_Response |
| 214 | 214 | */ |
| 215 | 215 | public function get_item( $request ) { |
| 216 | - $object = $this->get_object( (int) $request['id'] ); |
|
| 216 | + $object = $this->get_object( (int) $request[ 'id' ] ); |
|
| 217 | 217 | |
| 218 | 218 | if ( ! $object || 0 === $object->get_id() ) { |
| 219 | 219 | return new \WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'Invalid ID.', 'woocommerce-rest-api' ), array( 'status' => 404 ) ); |
@@ -229,18 +229,18 @@ discard block |
||
| 229 | 229 | * @return \WP_Error|\WP_REST_Response |
| 230 | 230 | */ |
| 231 | 231 | public function create_item( $request ) { |
| 232 | - if ( ! empty( $request['id'] ) ) { |
|
| 232 | + if ( ! empty( $request[ 'id' ] ) ) { |
|
| 233 | 233 | /* translators: %s: post type */ |
| 234 | 234 | return new \WP_Error( "woocommerce_rest_{$this->post_type}_exists", sprintf( __( 'Cannot create existing %s.', 'woocommerce-rest-api' ), $this->post_type ), array( 'status' => 400 ) ); |
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | // Validate topic. |
| 238 | - if ( empty( $request['topic'] ) || ! wc_is_webhook_valid_topic( strtolower( $request['topic'] ) ) ) { |
|
| 238 | + if ( empty( $request[ 'topic' ] ) || ! wc_is_webhook_valid_topic( strtolower( $request[ 'topic' ] ) ) ) { |
|
| 239 | 239 | return new \WP_Error( "woocommerce_rest_{$this->post_type}_invalid_topic", __( 'Webhook topic is required and must be valid.', 'woocommerce-rest-api' ), array( 'status' => 400 ) ); |
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | // Validate delivery URL. |
| 243 | - if ( empty( $request['delivery_url'] ) || ! wc_is_valid_url( $request['delivery_url'] ) ) { |
|
| 243 | + if ( empty( $request[ 'delivery_url' ] ) || ! wc_is_valid_url( $request[ 'delivery_url' ] ) ) { |
|
| 244 | 244 | 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-rest-api' ), array( 'status' => 400 ) ); |
| 245 | 245 | } |
| 246 | 246 | |
@@ -253,9 +253,9 @@ discard block |
||
| 253 | 253 | $webhook->set_name( $post->post_title ); |
| 254 | 254 | $webhook->set_user_id( $post->post_author ); |
| 255 | 255 | $webhook->set_status( 'publish' === $post->post_status ? 'active' : 'disabled' ); |
| 256 | - $webhook->set_topic( $request['topic'] ); |
|
| 257 | - $webhook->set_delivery_url( $request['delivery_url'] ); |
|
| 258 | - $webhook->set_secret( ! empty( $request['secret'] ) ? $request['secret'] : wp_generate_password( 50, true, true ) ); |
|
| 256 | + $webhook->set_topic( $request[ 'topic' ] ); |
|
| 257 | + $webhook->set_delivery_url( $request[ 'delivery_url' ] ); |
|
| 258 | + $webhook->set_secret( ! empty( $request[ 'secret' ] ) ? $request[ 'secret' ] : wp_generate_password( 50, true, true ) ); |
|
| 259 | 259 | $webhook->set_api_version( $this->get_default_api_version() ); |
| 260 | 260 | $webhook->save(); |
| 261 | 261 | |
@@ -289,7 +289,7 @@ discard block |
||
| 289 | 289 | * @return \WP_Error|\WP_REST_Response |
| 290 | 290 | */ |
| 291 | 291 | public function update_item( $request ) { |
| 292 | - $id = (int) $request['id']; |
|
| 292 | + $id = (int) $request[ 'id' ]; |
|
| 293 | 293 | $webhook = wc_get_webhook( $id ); |
| 294 | 294 | |
| 295 | 295 | if ( empty( $webhook ) || is_null( $webhook ) ) { |
@@ -297,32 +297,32 @@ discard block |
||
| 297 | 297 | } |
| 298 | 298 | |
| 299 | 299 | // Update topic. |
| 300 | - if ( ! empty( $request['topic'] ) ) { |
|
| 301 | - if ( wc_is_webhook_valid_topic( strtolower( $request['topic'] ) ) ) { |
|
| 302 | - $webhook->set_topic( $request['topic'] ); |
|
| 300 | + if ( ! empty( $request[ 'topic' ] ) ) { |
|
| 301 | + if ( wc_is_webhook_valid_topic( strtolower( $request[ 'topic' ] ) ) ) { |
|
| 302 | + $webhook->set_topic( $request[ 'topic' ] ); |
|
| 303 | 303 | } else { |
| 304 | 304 | return new \WP_Error( "woocommerce_rest_{$this->post_type}_invalid_topic", __( 'Webhook topic must be valid.', 'woocommerce-rest-api' ), array( 'status' => 400 ) ); |
| 305 | 305 | } |
| 306 | 306 | } |
| 307 | 307 | |
| 308 | 308 | // Update delivery URL. |
| 309 | - if ( ! empty( $request['delivery_url'] ) ) { |
|
| 310 | - if ( wc_is_valid_url( $request['delivery_url'] ) ) { |
|
| 311 | - $webhook->set_delivery_url( $request['delivery_url'] ); |
|
| 309 | + if ( ! empty( $request[ 'delivery_url' ] ) ) { |
|
| 310 | + if ( wc_is_valid_url( $request[ 'delivery_url' ] ) ) { |
|
| 311 | + $webhook->set_delivery_url( $request[ 'delivery_url' ] ); |
|
| 312 | 312 | } else { |
| 313 | 313 | 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-rest-api' ), array( 'status' => 400 ) ); |
| 314 | 314 | } |
| 315 | 315 | } |
| 316 | 316 | |
| 317 | 317 | // Update secret. |
| 318 | - if ( ! empty( $request['secret'] ) ) { |
|
| 319 | - $webhook->set_secret( $request['secret'] ); |
|
| 318 | + if ( ! empty( $request[ 'secret' ] ) ) { |
|
| 319 | + $webhook->set_secret( $request[ 'secret' ] ); |
|
| 320 | 320 | } |
| 321 | 321 | |
| 322 | 322 | // Update status. |
| 323 | - if ( ! empty( $request['status'] ) ) { |
|
| 324 | - if ( wc_is_webhook_valid_status( strtolower( $request['status'] ) ) ) { |
|
| 325 | - $webhook->set_status( $request['status'] ); |
|
| 323 | + if ( ! empty( $request[ 'status' ] ) ) { |
|
| 324 | + if ( wc_is_webhook_valid_status( strtolower( $request[ 'status' ] ) ) ) { |
|
| 325 | + $webhook->set_status( $request[ 'status' ] ); |
|
| 326 | 326 | } else { |
| 327 | 327 | return new \WP_Error( "woocommerce_rest_{$this->post_type}_invalid_status", __( 'Webhook status must be valid.', 'woocommerce-rest-api' ), array( 'status' => 400 ) ); |
| 328 | 328 | } |
@@ -363,8 +363,8 @@ discard block |
||
| 363 | 363 | * @return \WP_REST_Response|\WP_Error |
| 364 | 364 | */ |
| 365 | 365 | public function delete_item( $request ) { |
| 366 | - $id = (int) $request['id']; |
|
| 367 | - $force = isset( $request['force'] ) ? (bool) $request['force'] : false; |
|
| 366 | + $id = (int) $request[ 'id' ]; |
|
| 367 | + $force = isset( $request[ 'force' ] ) ? (bool) $request[ 'force' ] : false; |
|
| 368 | 368 | |
| 369 | 369 | // We don't support trashing for this type, error out. |
| 370 | 370 | if ( ! $force ) { |
@@ -414,13 +414,13 @@ discard block |
||
| 414 | 414 | $data = new \stdClass(); |
| 415 | 415 | |
| 416 | 416 | // Post ID. |
| 417 | - if ( isset( $request['id'] ) ) { |
|
| 418 | - $data->ID = absint( $request['id'] ); |
|
| 417 | + if ( isset( $request[ 'id' ] ) ) { |
|
| 418 | + $data->ID = absint( $request[ 'id' ] ); |
|
| 419 | 419 | } |
| 420 | 420 | |
| 421 | 421 | // Validate required POST fields. |
| 422 | 422 | if ( 'POST' === $request->get_method() && empty( $data->ID ) ) { |
| 423 | - $data->post_title = ! empty( $request['name'] ) ? $request['name'] : sprintf( __( 'Webhook created on %s', 'woocommerce-rest-api' ), strftime( _x( '%b %d, %Y @ %I:%M %p', 'Webhook created on date parsed by strftime', 'woocommerce-rest-api' ) ) ); // @codingStandardsIgnoreLine |
|
| 423 | + $data->post_title = ! empty( $request[ 'name' ] ) ? $request[ 'name' ] : sprintf( __( 'Webhook created on %s', 'woocommerce-rest-api' ), strftime( _x( '%b %d, %Y @ %I:%M %p', 'Webhook created on date parsed by strftime', 'woocommerce-rest-api' ) ) ); // @codingStandardsIgnoreLine |
|
| 424 | 424 | |
| 425 | 425 | // Post author. |
| 426 | 426 | $data->post_author = get_current_user_id(); |
@@ -433,8 +433,8 @@ discard block |
||
| 433 | 433 | } else { |
| 434 | 434 | |
| 435 | 435 | // Allow edit post title. |
| 436 | - if ( ! empty( $request['name'] ) ) { |
|
| 437 | - $data->post_title = $request['name']; |
|
| 436 | + if ( ! empty( $request[ 'name' ] ) ) { |
|
| 437 | + $data->post_title = $request[ 'name' ]; |
|
| 438 | 438 | } |
| 439 | 439 | } |
| 440 | 440 | |
@@ -606,21 +606,21 @@ discard block |
||
| 606 | 606 | public function get_collection_params() { |
| 607 | 607 | $params = parent::get_collection_params(); |
| 608 | 608 | |
| 609 | - $params['context']['default'] = 'view'; |
|
| 609 | + $params[ 'context' ][ 'default' ] = 'view'; |
|
| 610 | 610 | |
| 611 | - $params['after'] = array( |
|
| 611 | + $params[ 'after' ] = array( |
|
| 612 | 612 | 'description' => __( 'Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce-rest-api' ), |
| 613 | 613 | 'type' => 'string', |
| 614 | 614 | 'format' => 'date-time', |
| 615 | 615 | 'validate_callback' => 'rest_validate_request_arg', |
| 616 | 616 | ); |
| 617 | - $params['before'] = array( |
|
| 617 | + $params[ 'before' ] = array( |
|
| 618 | 618 | 'description' => __( 'Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce-rest-api' ), |
| 619 | 619 | 'type' => 'string', |
| 620 | 620 | 'format' => 'date-time', |
| 621 | 621 | 'validate_callback' => 'rest_validate_request_arg', |
| 622 | 622 | ); |
| 623 | - $params['exclude'] = array( |
|
| 623 | + $params[ 'exclude' ] = array( |
|
| 624 | 624 | 'description' => __( 'Ensure result set excludes specific IDs.', 'woocommerce-rest-api' ), |
| 625 | 625 | 'type' => 'array', |
| 626 | 626 | 'items' => array( |
@@ -629,7 +629,7 @@ discard block |
||
| 629 | 629 | 'default' => array(), |
| 630 | 630 | 'sanitize_callback' => 'wp_parse_id_list', |
| 631 | 631 | ); |
| 632 | - $params['include'] = array( |
|
| 632 | + $params[ 'include' ] = array( |
|
| 633 | 633 | 'description' => __( 'Limit result set to specific ids.', 'woocommerce-rest-api' ), |
| 634 | 634 | 'type' => 'array', |
| 635 | 635 | 'items' => array( |
@@ -638,20 +638,20 @@ discard block |
||
| 638 | 638 | 'default' => array(), |
| 639 | 639 | 'sanitize_callback' => 'wp_parse_id_list', |
| 640 | 640 | ); |
| 641 | - $params['offset'] = array( |
|
| 641 | + $params[ 'offset' ] = array( |
|
| 642 | 642 | 'description' => __( 'Offset the result set by a specific number of items.', 'woocommerce-rest-api' ), |
| 643 | 643 | 'type' => 'integer', |
| 644 | 644 | 'sanitize_callback' => 'absint', |
| 645 | 645 | 'validate_callback' => 'rest_validate_request_arg', |
| 646 | 646 | ); |
| 647 | - $params['order'] = array( |
|
| 647 | + $params[ 'order' ] = array( |
|
| 648 | 648 | 'description' => __( 'Order sort attribute ascending or descending.', 'woocommerce-rest-api' ), |
| 649 | 649 | 'type' => 'string', |
| 650 | 650 | 'default' => 'desc', |
| 651 | 651 | 'enum' => array( 'asc', 'desc' ), |
| 652 | 652 | 'validate_callback' => 'rest_validate_request_arg', |
| 653 | 653 | ); |
| 654 | - $params['orderby'] = array( |
|
| 654 | + $params[ 'orderby' ] = array( |
|
| 655 | 655 | 'description' => __( 'Sort collection by object attribute.', 'woocommerce-rest-api' ), |
| 656 | 656 | 'type' => 'string', |
| 657 | 657 | 'default' => 'date', |
@@ -662,7 +662,7 @@ discard block |
||
| 662 | 662 | ), |
| 663 | 663 | 'validate_callback' => 'rest_validate_request_arg', |
| 664 | 664 | ); |
| 665 | - $params['status'] = array( |
|
| 665 | + $params[ 'status' ] = array( |
|
| 666 | 666 | 'default' => 'all', |
| 667 | 667 | 'description' => __( 'Limit result set to webhooks assigned a specific status.', 'woocommerce-rest-api' ), |
| 668 | 668 | 'type' => 'string', |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | * @return \WP_Error|\WP_REST_Response |
| 66 | 66 | */ |
| 67 | 67 | public function get_item( $request ) { |
| 68 | - $object = $this->get_object( (int) $request['id'] ); |
|
| 68 | + $object = $this->get_object( (int) $request[ 'id' ] ); |
|
| 69 | 69 | |
| 70 | 70 | if ( ! $object || 0 === $object->get_id() ) { |
| 71 | 71 | return new \WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'Invalid ID.', 'woocommerce-rest-api' ), array( 'status' => 404 ) ); |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | * @return \WP_Error|\WP_REST_Response |
| 111 | 111 | */ |
| 112 | 112 | public function create_item( $request ) { |
| 113 | - if ( ! empty( $request['id'] ) ) { |
|
| 113 | + if ( ! empty( $request[ 'id' ] ) ) { |
|
| 114 | 114 | /* translators: %s: post type */ |
| 115 | 115 | return new \WP_Error( "woocommerce_rest_{$this->post_type}_exists", sprintf( __( 'Cannot create existing %s.', 'woocommerce-rest-api' ), $this->post_type ), array( 'status' => 400 ) ); |
| 116 | 116 | } |
@@ -156,7 +156,7 @@ discard block |
||
| 156 | 156 | * @return \WP_Error|\WP_REST_Response |
| 157 | 157 | */ |
| 158 | 158 | public function update_item( $request ) { |
| 159 | - $object = $this->get_object( (int) $request['id'] ); |
|
| 159 | + $object = $this->get_object( (int) $request[ 'id' ] ); |
|
| 160 | 160 | |
| 161 | 161 | if ( ! $object || 0 === $object->get_id() ) { |
| 162 | 162 | return new \WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'Invalid ID.', 'woocommerce-rest-api' ), array( 'status' => 404 ) ); |
@@ -199,42 +199,42 @@ discard block |
||
| 199 | 199 | */ |
| 200 | 200 | protected function prepare_objects_query( $request ) { |
| 201 | 201 | $args = array(); |
| 202 | - $args['offset'] = $request['offset']; |
|
| 203 | - $args['order'] = $request['order']; |
|
| 204 | - $args['orderby'] = $request['orderby']; |
|
| 205 | - $args['paged'] = $request['page']; |
|
| 206 | - $args['post__in'] = $request['include']; |
|
| 207 | - $args['post__not_in'] = $request['exclude']; |
|
| 208 | - $args['posts_per_page'] = $request['per_page']; |
|
| 209 | - $args['name'] = $request['slug']; |
|
| 210 | - $args['post_parent__in'] = $request['parent']; |
|
| 211 | - $args['post_parent__not_in'] = $request['parent_exclude']; |
|
| 212 | - $args['s'] = $request['search']; |
|
| 213 | - $args['fields'] = 'ids'; |
|
| 214 | - |
|
| 215 | - if ( 'date' === $args['orderby'] ) { |
|
| 216 | - $args['orderby'] = 'date ID'; |
|
| 202 | + $args[ 'offset' ] = $request[ 'offset' ]; |
|
| 203 | + $args[ 'order' ] = $request[ 'order' ]; |
|
| 204 | + $args[ 'orderby' ] = $request[ 'orderby' ]; |
|
| 205 | + $args[ 'paged' ] = $request[ 'page' ]; |
|
| 206 | + $args[ 'post__in' ] = $request[ 'include' ]; |
|
| 207 | + $args[ 'post__not_in' ] = $request[ 'exclude' ]; |
|
| 208 | + $args[ 'posts_per_page' ] = $request[ 'per_page' ]; |
|
| 209 | + $args[ 'name' ] = $request[ 'slug' ]; |
|
| 210 | + $args[ 'post_parent__in' ] = $request[ 'parent' ]; |
|
| 211 | + $args[ 'post_parent__not_in' ] = $request[ 'parent_exclude' ]; |
|
| 212 | + $args[ 's' ] = $request[ 'search' ]; |
|
| 213 | + $args[ 'fields' ] = 'ids'; |
|
| 214 | + |
|
| 215 | + if ( 'date' === $args[ 'orderby' ] ) { |
|
| 216 | + $args[ 'orderby' ] = 'date ID'; |
|
| 217 | 217 | } |
| 218 | 218 | |
| 219 | - $args['date_query'] = array(); |
|
| 219 | + $args[ 'date_query' ] = array(); |
|
| 220 | 220 | |
| 221 | 221 | // Set before into date query. Date query must be specified as an array of an array. |
| 222 | - if ( isset( $request['before'] ) ) { |
|
| 223 | - $args['date_query'][0]['before'] = $request['before']; |
|
| 222 | + if ( isset( $request[ 'before' ] ) ) { |
|
| 223 | + $args[ 'date_query' ][ 0 ][ 'before' ] = $request[ 'before' ]; |
|
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | // Set after into date query. Date query must be specified as an array of an array. |
| 227 | - if ( isset( $request['after'] ) ) { |
|
| 228 | - $args['date_query'][0]['after'] = $request['after']; |
|
| 227 | + if ( isset( $request[ 'after' ] ) ) { |
|
| 228 | + $args[ 'date_query' ][ 0 ][ 'after' ] = $request[ 'after' ]; |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | // Set date query colummn. Defaults to post_date. |
| 232 | - if ( isset( $request['date_column'] ) && ! empty( $args['date_query'][0] ) ) { |
|
| 233 | - $args['date_query'][0]['column'] = 'post_' . $request['date_column']; |
|
| 232 | + if ( isset( $request[ 'date_column' ] ) && ! empty( $args[ 'date_query' ][ 0 ] ) ) { |
|
| 233 | + $args[ 'date_query' ][ 0 ][ 'column' ] = 'post_' . $request[ 'date_column' ]; |
|
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | // Force the post_type argument, since it's not a user input variable. |
| 237 | - $args['post_type'] = $this->post_type; |
|
| 237 | + $args[ 'post_type' ] = $this->post_type; |
|
| 238 | 238 | |
| 239 | 239 | /** |
| 240 | 240 | * Filter the query arguments for a request. |
@@ -264,7 +264,7 @@ discard block |
||
| 264 | 264 | $total_posts = $query->found_posts; |
| 265 | 265 | if ( $total_posts < 1 ) { |
| 266 | 266 | // Out-of-bounds, run the query again without LIMIT for total count. |
| 267 | - unset( $query_args['paged'] ); |
|
| 267 | + unset( $query_args[ 'paged' ] ); |
|
| 268 | 268 | $count_query = new \WP_Query(); |
| 269 | 269 | $count_query->query( $query_args ); |
| 270 | 270 | $total_posts = $count_query->found_posts; |
@@ -273,7 +273,7 @@ discard block |
||
| 273 | 273 | return array( |
| 274 | 274 | 'objects' => array_map( array( $this, 'get_object' ), $result ), |
| 275 | 275 | 'total' => (int) $total_posts, |
| 276 | - 'pages' => (int) ceil( $total_posts / (int) $query->query_vars['posts_per_page'] ), |
|
| 276 | + 'pages' => (int) ceil( $total_posts / (int) $query->query_vars[ 'posts_per_page' ] ), |
|
| 277 | 277 | ); |
| 278 | 278 | } |
| 279 | 279 | |
@@ -288,17 +288,17 @@ discard block |
||
| 288 | 288 | $query_results = $this->get_objects( $query_args ); |
| 289 | 289 | |
| 290 | 290 | $objects = array(); |
| 291 | - foreach ( $query_results['objects'] as $object ) { |
|
| 291 | + foreach ( $query_results[ 'objects' ] as $object ) { |
|
| 292 | 292 | if ( ! Permissions::user_can_read( $this->post_type, $object->get_id() ) ) { |
| 293 | 293 | continue; |
| 294 | 294 | } |
| 295 | 295 | |
| 296 | 296 | $data = $this->prepare_item_for_response( $object, $request ); |
| 297 | - $objects[] = $this->prepare_response_for_collection( $data ); |
|
| 297 | + $objects[ ] = $this->prepare_response_for_collection( $data ); |
|
| 298 | 298 | } |
| 299 | 299 | |
| 300 | - $total = $query_results['total']; |
|
| 301 | - $max_pages = $query_results['pages']; |
|
| 300 | + $total = $query_results[ 'total' ]; |
|
| 301 | + $max_pages = $query_results[ 'pages' ]; |
|
| 302 | 302 | |
| 303 | 303 | $response = rest_ensure_response( $objects ); |
| 304 | 304 | $response = Pagination::add_pagination_headers( $response, $request, $total, $max_pages ); |
@@ -313,8 +313,8 @@ discard block |
||
| 313 | 313 | * @return \WP_REST_Response|\WP_Error |
| 314 | 314 | */ |
| 315 | 315 | public function delete_item( $request ) { |
| 316 | - $force = (bool) $request['force']; |
|
| 317 | - $object = $this->get_object( (int) $request['id'] ); |
|
| 316 | + $force = (bool) $request[ 'force' ]; |
|
| 317 | + $object = $this->get_object( (int) $request[ 'id' ] ); |
|
| 318 | 318 | $result = false; |
| 319 | 319 | |
| 320 | 320 | if ( ! $object || 0 === $object->get_id() ) { |
@@ -424,10 +424,10 @@ discard block |
||
| 424 | 424 | */ |
| 425 | 425 | public function get_collection_params() { |
| 426 | 426 | $params = array(); |
| 427 | - $params['context'] = $this->get_context_param(); |
|
| 428 | - $params['context']['default'] = 'view'; |
|
| 427 | + $params[ 'context' ] = $this->get_context_param(); |
|
| 428 | + $params[ 'context' ][ 'default' ] = 'view'; |
|
| 429 | 429 | |
| 430 | - $params['page'] = array( |
|
| 430 | + $params[ 'page' ] = array( |
|
| 431 | 431 | 'description' => __( 'Current page of the collection.', 'woocommerce-rest-api' ), |
| 432 | 432 | 'type' => 'integer', |
| 433 | 433 | 'default' => 1, |
@@ -436,7 +436,7 @@ discard block |
||
| 436 | 436 | 'minimum' => 1, |
| 437 | 437 | ); |
| 438 | 438 | |
| 439 | - $params['per_page'] = array( |
|
| 439 | + $params[ 'per_page' ] = array( |
|
| 440 | 440 | 'description' => __( 'Maximum number of items to be returned in result set.', 'woocommerce-rest-api' ), |
| 441 | 441 | 'type' => 'integer', |
| 442 | 442 | 'default' => 10, |
@@ -446,28 +446,28 @@ discard block |
||
| 446 | 446 | 'validate_callback' => 'rest_validate_request_arg', |
| 447 | 447 | ); |
| 448 | 448 | |
| 449 | - $params['search'] = array( |
|
| 449 | + $params[ 'search' ] = array( |
|
| 450 | 450 | 'description' => __( 'Limit results to those matching a string.', 'woocommerce-rest-api' ), |
| 451 | 451 | 'type' => 'string', |
| 452 | 452 | 'sanitize_callback' => 'sanitize_text_field', |
| 453 | 453 | 'validate_callback' => 'rest_validate_request_arg', |
| 454 | 454 | ); |
| 455 | 455 | |
| 456 | - $params['after'] = array( |
|
| 456 | + $params[ 'after' ] = array( |
|
| 457 | 457 | 'description' => __( 'Limit response to resources created after a given ISO8601 compliant date.', 'woocommerce-rest-api' ), |
| 458 | 458 | 'type' => 'string', |
| 459 | 459 | 'format' => 'date-time', |
| 460 | 460 | 'validate_callback' => 'rest_validate_request_arg', |
| 461 | 461 | ); |
| 462 | 462 | |
| 463 | - $params['before'] = array( |
|
| 463 | + $params[ 'before' ] = array( |
|
| 464 | 464 | 'description' => __( 'Limit response to resources created before a given ISO8601 compliant date.', 'woocommerce-rest-api' ), |
| 465 | 465 | 'type' => 'string', |
| 466 | 466 | 'format' => 'date-time', |
| 467 | 467 | 'validate_callback' => 'rest_validate_request_arg', |
| 468 | 468 | ); |
| 469 | 469 | |
| 470 | - $params['date_column'] = array( |
|
| 470 | + $params[ 'date_column' ] = array( |
|
| 471 | 471 | 'description' => __( 'When limiting response using after/before, which date column to compare against.', 'woocommerce-rest-api' ), |
| 472 | 472 | 'type' => 'string', |
| 473 | 473 | 'default' => 'date', |
@@ -480,14 +480,14 @@ discard block |
||
| 480 | 480 | 'validate_callback' => 'rest_validate_request_arg', |
| 481 | 481 | ); |
| 482 | 482 | |
| 483 | - $params['modified_before'] = array( |
|
| 483 | + $params[ 'modified_before' ] = array( |
|
| 484 | 484 | 'description' => __( 'Limit response to resources modified before a given ISO8601 compliant date.', 'woocommerce-rest-api' ), |
| 485 | 485 | 'type' => 'string', |
| 486 | 486 | 'format' => 'date-time', |
| 487 | 487 | 'validate_callback' => 'rest_validate_request_arg', |
| 488 | 488 | ); |
| 489 | 489 | |
| 490 | - $params['exclude'] = array( |
|
| 490 | + $params[ 'exclude' ] = array( |
|
| 491 | 491 | 'description' => __( 'Ensure result set excludes specific IDs.', 'woocommerce-rest-api' ), |
| 492 | 492 | 'type' => 'array', |
| 493 | 493 | 'items' => array( |
@@ -497,7 +497,7 @@ discard block |
||
| 497 | 497 | 'sanitize_callback' => 'wp_parse_id_list', |
| 498 | 498 | ); |
| 499 | 499 | |
| 500 | - $params['include'] = array( |
|
| 500 | + $params[ 'include' ] = array( |
|
| 501 | 501 | 'description' => __( 'Limit result set to specific ids.', 'woocommerce-rest-api' ), |
| 502 | 502 | 'type' => 'array', |
| 503 | 503 | 'items' => array( |
@@ -507,14 +507,14 @@ discard block |
||
| 507 | 507 | 'sanitize_callback' => 'wp_parse_id_list', |
| 508 | 508 | ); |
| 509 | 509 | |
| 510 | - $params['offset'] = array( |
|
| 510 | + $params[ 'offset' ] = array( |
|
| 511 | 511 | 'description' => __( 'Offset the result set by a specific number of items.', 'woocommerce-rest-api' ), |
| 512 | 512 | 'type' => 'integer', |
| 513 | 513 | 'sanitize_callback' => 'absint', |
| 514 | 514 | 'validate_callback' => 'rest_validate_request_arg', |
| 515 | 515 | ); |
| 516 | 516 | |
| 517 | - $params['order'] = array( |
|
| 517 | + $params[ 'order' ] = array( |
|
| 518 | 518 | 'description' => __( 'Order sort attribute ascending or descending.', 'woocommerce-rest-api' ), |
| 519 | 519 | 'type' => 'string', |
| 520 | 520 | 'default' => 'desc', |
@@ -522,7 +522,7 @@ discard block |
||
| 522 | 522 | 'validate_callback' => 'rest_validate_request_arg', |
| 523 | 523 | ); |
| 524 | 524 | |
| 525 | - $params['orderby'] = array( |
|
| 525 | + $params[ 'orderby' ] = array( |
|
| 526 | 526 | 'description' => __( 'Sort collection by object attribute.', 'woocommerce-rest-api' ), |
| 527 | 527 | 'type' => 'string', |
| 528 | 528 | 'default' => 'date', |
@@ -538,7 +538,7 @@ discard block |
||
| 538 | 538 | ); |
| 539 | 539 | |
| 540 | 540 | if ( $this->hierarchical ) { |
| 541 | - $params['parent'] = array( |
|
| 541 | + $params[ 'parent' ] = array( |
|
| 542 | 542 | 'description' => __( 'Limit result set to those of particular parent IDs.', 'woocommerce-rest-api' ), |
| 543 | 543 | 'type' => 'array', |
| 544 | 544 | 'items' => array( |
@@ -548,7 +548,7 @@ discard block |
||
| 548 | 548 | 'default' => array(), |
| 549 | 549 | ); |
| 550 | 550 | |
| 551 | - $params['parent_exclude'] = array( |
|
| 551 | + $params[ 'parent_exclude' ] = array( |
|
| 552 | 552 | 'description' => __( 'Limit result set to all items except those of a particular parent ID.', 'woocommerce-rest-api' ), |
| 553 | 553 | 'type' => 'array', |
| 554 | 554 | 'items' => array( |
@@ -599,14 +599,14 @@ discard block |
||
| 599 | 599 | } |
| 600 | 600 | } |
| 601 | 601 | |
| 602 | - $query_args['ignore_sticky_posts'] = true; |
|
| 602 | + $query_args[ 'ignore_sticky_posts' ] = true; |
|
| 603 | 603 | |
| 604 | - if ( 'include' === $query_args['orderby'] ) { |
|
| 605 | - $query_args['orderby'] = 'post__in'; |
|
| 606 | - } elseif ( 'id' === $query_args['orderby'] ) { |
|
| 607 | - $query_args['orderby'] = 'ID'; // ID must be capitalized. |
|
| 608 | - } elseif ( 'slug' === $query_args['orderby'] ) { |
|
| 609 | - $query_args['orderby'] = 'name'; |
|
| 604 | + if ( 'include' === $query_args[ 'orderby' ] ) { |
|
| 605 | + $query_args[ 'orderby' ] = 'post__in'; |
|
| 606 | + } elseif ( 'id' === $query_args[ 'orderby' ] ) { |
|
| 607 | + $query_args[ 'orderby' ] = 'ID'; // ID must be capitalized. |
|
| 608 | + } elseif ( 'slug' === $query_args[ 'orderby' ] ) { |
|
| 609 | + $query_args[ 'orderby' ] = 'name'; |
|
| 610 | 610 | } |
| 611 | 611 | |
| 612 | 612 | return $query_args; |
@@ -694,13 +694,13 @@ discard block |
||
| 694 | 694 | * @return array |
| 695 | 695 | */ |
| 696 | 696 | protected function add_meta_query( $args, $meta_query ) { |
| 697 | - if ( empty( $args['meta_query'] ) ) { |
|
| 698 | - $args['meta_query'] = []; // phpcs:ignore |
|
| 697 | + if ( empty( $args[ 'meta_query' ] ) ) { |
|
| 698 | + $args[ 'meta_query' ] = [ ]; // phpcs:ignore |
|
| 699 | 699 | } |
| 700 | 700 | |
| 701 | - $args['meta_query'][] = $meta_query; |
|
| 701 | + $args[ 'meta_query' ][ ] = $meta_query; |
|
| 702 | 702 | |
| 703 | - return $args['meta_query']; |
|
| 703 | + return $args[ 'meta_query' ]; |
|
| 704 | 704 | } |
| 705 | 705 | |
| 706 | 706 | /** |
@@ -136,16 +136,16 @@ discard block |
||
| 136 | 136 | */ |
| 137 | 137 | public function get_items( $request ) { |
| 138 | 138 | $prepared_args = array( |
| 139 | - 'exclude' => $request['exclude'], |
|
| 140 | - 'include' => $request['include'], |
|
| 141 | - 'order' => $request['order'], |
|
| 142 | - 'number' => $request['per_page'], |
|
| 139 | + 'exclude' => $request[ 'exclude' ], |
|
| 140 | + 'include' => $request[ 'include' ], |
|
| 141 | + 'order' => $request[ 'order' ], |
|
| 142 | + 'number' => $request[ 'per_page' ], |
|
| 143 | 143 | ); |
| 144 | 144 | |
| 145 | - if ( ! empty( $request['offset'] ) ) { |
|
| 146 | - $prepared_args['offset'] = $request['offset']; |
|
| 145 | + if ( ! empty( $request[ 'offset' ] ) ) { |
|
| 146 | + $prepared_args[ 'offset' ] = $request[ 'offset' ]; |
|
| 147 | 147 | } else { |
| 148 | - $prepared_args['offset'] = ( $request['page'] - 1 ) * $prepared_args['number']; |
|
| 148 | + $prepared_args[ 'offset' ] = ( $request[ 'page' ] - 1 ) * $prepared_args[ 'number' ]; |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | $orderby_possibles = array( |
@@ -154,22 +154,22 @@ discard block |
||
| 154 | 154 | 'name' => 'display_name', |
| 155 | 155 | 'registered_date' => 'registered', |
| 156 | 156 | ); |
| 157 | - $prepared_args['orderby'] = $orderby_possibles[ $request['orderby'] ]; |
|
| 158 | - $prepared_args['search'] = $request['search']; |
|
| 157 | + $prepared_args[ 'orderby' ] = $orderby_possibles[ $request[ 'orderby' ] ]; |
|
| 158 | + $prepared_args[ 'search' ] = $request[ 'search' ]; |
|
| 159 | 159 | |
| 160 | - if ( '' !== $prepared_args['search'] ) { |
|
| 161 | - $prepared_args['search'] = '*' . $prepared_args['search'] . '*'; |
|
| 160 | + if ( '' !== $prepared_args[ 'search' ] ) { |
|
| 161 | + $prepared_args[ 'search' ] = '*' . $prepared_args[ 'search' ] . '*'; |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | // Filter by email. |
| 165 | - if ( ! empty( $request['email'] ) ) { |
|
| 166 | - $prepared_args['search'] = $request['email']; |
|
| 167 | - $prepared_args['search_columns'] = array( 'user_email' ); |
|
| 165 | + if ( ! empty( $request[ 'email' ] ) ) { |
|
| 166 | + $prepared_args[ 'search' ] = $request[ 'email' ]; |
|
| 167 | + $prepared_args[ 'search_columns' ] = array( 'user_email' ); |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | // Filter by role. |
| 171 | - if ( 'all' !== $request['role'] ) { |
|
| 172 | - $prepared_args['role'] = $request['role']; |
|
| 171 | + if ( 'all' !== $request[ 'role' ] ) { |
|
| 172 | + $prepared_args[ 'role' ] = $request[ 'role' ]; |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | /** |
@@ -188,21 +188,21 @@ discard block |
||
| 188 | 188 | foreach ( $query->results as $user ) { |
| 189 | 189 | $customer = new \WC_Customer( $user->ID ); |
| 190 | 190 | $data = $this->prepare_item_for_response( $customer, $request ); |
| 191 | - $users[] = $this->prepare_response_for_collection( $data ); |
|
| 191 | + $users[ ] = $this->prepare_response_for_collection( $data ); |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | // Store pagination values for headers then unset for count query. |
| 195 | - $per_page = (int) $prepared_args['number']; |
|
| 196 | - $page = ceil( ( ( (int) $prepared_args['offset'] ) / $per_page ) + 1 ); |
|
| 195 | + $per_page = (int) $prepared_args[ 'number' ]; |
|
| 196 | + $page = ceil( ( ( (int) $prepared_args[ 'offset' ] ) / $per_page ) + 1 ); |
|
| 197 | 197 | |
| 198 | - $prepared_args['fields'] = 'ID'; |
|
| 198 | + $prepared_args[ 'fields' ] = 'ID'; |
|
| 199 | 199 | |
| 200 | 200 | $total_users = $query->get_total(); |
| 201 | 201 | |
| 202 | 202 | if ( $total_users < 1 ) { |
| 203 | 203 | // Out-of-bounds, run the query again without LIMIT for total count. |
| 204 | - unset( $prepared_args['number'] ); |
|
| 205 | - unset( $prepared_args['offset'] ); |
|
| 204 | + unset( $prepared_args[ 'number' ] ); |
|
| 205 | + unset( $prepared_args[ 'offset' ] ); |
|
| 206 | 206 | $count_query = new \ WP_User_Query( $prepared_args ); |
| 207 | 207 | $total_users = $count_query->get_total(); |
| 208 | 208 | } |
@@ -222,7 +222,7 @@ discard block |
||
| 222 | 222 | */ |
| 223 | 223 | public function create_item( $request ) { |
| 224 | 224 | try { |
| 225 | - if ( ! empty( $request['id'] ) ) { |
|
| 225 | + if ( ! empty( $request[ 'id' ] ) ) { |
|
| 226 | 226 | throw new \WC_REST_Exception( 'woocommerce_rest_customer_exists', __( 'Cannot create existing resource.', 'woocommerce-rest-api' ), 400 ); |
| 227 | 227 | } |
| 228 | 228 | |
@@ -264,7 +264,7 @@ discard block |
||
| 264 | 264 | * @return \WP_Error|\WP_REST_Response |
| 265 | 265 | */ |
| 266 | 266 | public function get_item( $request ) { |
| 267 | - $id = (int) $request['id']; |
|
| 267 | + $id = (int) $request[ 'id' ]; |
|
| 268 | 268 | $customer = new \WC_Customer( $id ); |
| 269 | 269 | |
| 270 | 270 | if ( empty( $id ) || ! $customer->get_id() ) { |
@@ -322,9 +322,9 @@ discard block |
||
| 322 | 322 | * @return \WP_Error|\WP_REST_Response |
| 323 | 323 | */ |
| 324 | 324 | public function delete_item( $request ) { |
| 325 | - $id = (int) $request['id']; |
|
| 326 | - $reassign = isset( $request['reassign'] ) ? absint( $request['reassign'] ) : null; |
|
| 327 | - $force = isset( $request['force'] ) ? (bool) $request['force'] : false; |
|
| 325 | + $id = (int) $request[ 'id' ]; |
|
| 326 | + $reassign = isset( $request[ 'reassign' ] ) ? absint( $request[ 'reassign' ] ) : null; |
|
| 327 | + $force = isset( $request[ 'force' ] ) ? (bool) $request[ 'force' ] : false; |
|
| 328 | 328 | |
| 329 | 329 | // We don't support trashing for this type, error out. |
| 330 | 330 | if ( ! $force ) { |
@@ -663,9 +663,9 @@ discard block |
||
| 663 | 663 | public function get_collection_params() { |
| 664 | 664 | $params = parent::get_collection_params(); |
| 665 | 665 | |
| 666 | - $params['context']['default'] = 'view'; |
|
| 666 | + $params[ 'context' ][ 'default' ] = 'view'; |
|
| 667 | 667 | |
| 668 | - $params['exclude'] = array( |
|
| 668 | + $params[ 'exclude' ] = array( |
|
| 669 | 669 | 'description' => __( 'Ensure result set excludes specific IDs.', 'woocommerce-rest-api' ), |
| 670 | 670 | 'type' => 'array', |
| 671 | 671 | 'items' => array( |
@@ -674,7 +674,7 @@ discard block |
||
| 674 | 674 | 'default' => array(), |
| 675 | 675 | 'sanitize_callback' => 'wp_parse_id_list', |
| 676 | 676 | ); |
| 677 | - $params['include'] = array( |
|
| 677 | + $params[ 'include' ] = array( |
|
| 678 | 678 | 'description' => __( 'Limit result set to specific IDs.', 'woocommerce-rest-api' ), |
| 679 | 679 | 'type' => 'array', |
| 680 | 680 | 'items' => array( |
@@ -683,13 +683,13 @@ discard block |
||
| 683 | 683 | 'default' => array(), |
| 684 | 684 | 'sanitize_callback' => 'wp_parse_id_list', |
| 685 | 685 | ); |
| 686 | - $params['offset'] = array( |
|
| 686 | + $params[ 'offset' ] = array( |
|
| 687 | 687 | 'description' => __( 'Offset the result set by a specific number of items.', 'woocommerce-rest-api' ), |
| 688 | 688 | 'type' => 'integer', |
| 689 | 689 | 'sanitize_callback' => 'absint', |
| 690 | 690 | 'validate_callback' => 'rest_validate_request_arg', |
| 691 | 691 | ); |
| 692 | - $params['order'] = array( |
|
| 692 | + $params[ 'order' ] = array( |
|
| 693 | 693 | 'default' => 'asc', |
| 694 | 694 | 'description' => __( 'Order sort attribute ascending or descending.', 'woocommerce-rest-api' ), |
| 695 | 695 | 'enum' => array( 'asc', 'desc' ), |
@@ -697,7 +697,7 @@ discard block |
||
| 697 | 697 | 'type' => 'string', |
| 698 | 698 | 'validate_callback' => 'rest_validate_request_arg', |
| 699 | 699 | ); |
| 700 | - $params['orderby'] = array( |
|
| 700 | + $params[ 'orderby' ] = array( |
|
| 701 | 701 | 'default' => 'name', |
| 702 | 702 | 'description' => __( 'Sort collection by object attribute.', 'woocommerce-rest-api' ), |
| 703 | 703 | 'enum' => array( |
@@ -710,13 +710,13 @@ discard block |
||
| 710 | 710 | 'type' => 'string', |
| 711 | 711 | 'validate_callback' => 'rest_validate_request_arg', |
| 712 | 712 | ); |
| 713 | - $params['email'] = array( |
|
| 713 | + $params[ 'email' ] = array( |
|
| 714 | 714 | 'description' => __( 'Limit result set to resources with a specific email.', 'woocommerce-rest-api' ), |
| 715 | 715 | 'type' => 'string', |
| 716 | 716 | 'format' => 'email', |
| 717 | 717 | 'validate_callback' => 'rest_validate_request_arg', |
| 718 | 718 | ); |
| 719 | - $params['role'] = array( |
|
| 719 | + $params[ 'role' ] = array( |
|
| 720 | 720 | 'description' => __( 'Limit result set to resources with a specific role.', 'woocommerce-rest-api' ), |
| 721 | 721 | 'type' => 'string', |
| 722 | 722 | 'default' => 'customer', |
@@ -46,31 +46,31 @@ discard block |
||
| 46 | 46 | public function get_public_item_schema() { |
| 47 | 47 | $schema = parent::get_public_item_schema(); |
| 48 | 48 | |
| 49 | - $schema['properties']['blog'] = array( |
|
| 49 | + $schema[ 'properties' ][ 'blog' ] = array( |
|
| 50 | 50 | 'description' => __( 'Blog id of the record on the multisite.', 'woocommerce-rest-api' ), |
| 51 | 51 | 'type' => 'integer', |
| 52 | 52 | 'context' => array( 'view' ), |
| 53 | 53 | 'readonly' => true, |
| 54 | 54 | ); |
| 55 | - $schema['properties']['edit_url'] = array( |
|
| 55 | + $schema[ 'properties' ][ 'edit_url' ] = array( |
|
| 56 | 56 | 'description' => __( 'URL to edit the order', 'woocommerce-rest-api' ), |
| 57 | 57 | 'type' => 'string', |
| 58 | 58 | 'context' => array( 'view' ), |
| 59 | 59 | 'readonly' => true, |
| 60 | 60 | ); |
| 61 | - $schema['properties']['customer'][] = array( |
|
| 61 | + $schema[ 'properties' ][ 'customer' ][ ] = array( |
|
| 62 | 62 | 'description' => __( 'Name of the customer for the order', 'woocommerce-rest-api' ), |
| 63 | 63 | 'type' => 'string', |
| 64 | 64 | 'context' => array( 'view' ), |
| 65 | 65 | 'readonly' => true, |
| 66 | 66 | ); |
| 67 | - $schema['properties']['status_name'][] = array( |
|
| 67 | + $schema[ 'properties' ][ 'status_name' ][ ] = array( |
|
| 68 | 68 | 'description' => __( 'Order Status', 'woocommerce-rest-api' ), |
| 69 | 69 | 'type' => 'string', |
| 70 | 70 | 'context' => array( 'view' ), |
| 71 | 71 | 'readonly' => true, |
| 72 | 72 | ); |
| 73 | - $schema['properties']['formatted_total'][] = array( |
|
| 73 | + $schema[ 'properties' ][ 'formatted_total' ][ ] = array( |
|
| 74 | 74 | 'description' => __( 'Order total formatted for locale', 'woocommerce-rest-api' ), |
| 75 | 75 | 'type' => 'string', |
| 76 | 76 | 'context' => array( 'view' ), |
@@ -133,14 +133,14 @@ discard block |
||
| 133 | 133 | remove_filter( 'woocommerce_rest_orders_prepare_object_query', array( $this, 'network_orders_filter_args' ) ); |
| 134 | 134 | |
| 135 | 135 | foreach ( $items->data as &$current_order ) { |
| 136 | - $order = wc_get_order( $current_order['id'] ); |
|
| 136 | + $order = wc_get_order( $current_order[ 'id' ] ); |
|
| 137 | 137 | |
| 138 | - $current_order['blog'] = get_blog_details( get_current_blog_id() ); |
|
| 139 | - $current_order['edit_url'] = get_admin_url( $blog_id, 'post.php?post=' . absint( $order->get_id() ) . '&action=edit' ); |
|
| 138 | + $current_order[ 'blog' ] = get_blog_details( get_current_blog_id() ); |
|
| 139 | + $current_order[ 'edit_url' ] = get_admin_url( $blog_id, 'post.php?post=' . absint( $order->get_id() ) . '&action=edit' ); |
|
| 140 | 140 | /* translators: 1: first name 2: last name */ |
| 141 | - $current_order['customer'] = trim( sprintf( _x( '%1$s %2$s', 'full name', 'woocommerce-rest-api' ), $order->get_billing_first_name(), $order->get_billing_last_name() ) ); |
|
| 142 | - $current_order['status_name'] = wc_get_order_status_name( $order->get_status() ); |
|
| 143 | - $current_order['formatted_total'] = $order->get_formatted_order_total(); |
|
| 141 | + $current_order[ 'customer' ] = trim( sprintf( _x( '%1$s %2$s', 'full name', 'woocommerce-rest-api' ), $order->get_billing_first_name(), $order->get_billing_last_name() ) ); |
|
| 142 | + $current_order[ 'status_name' ] = wc_get_order_status_name( $order->get_status() ); |
|
| 143 | + $current_order[ 'formatted_total' ] = $order->get_formatted_order_total(); |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | restore_current_blog(); |
@@ -156,7 +156,7 @@ discard block |
||
| 156 | 156 | * @return array |
| 157 | 157 | */ |
| 158 | 158 | public function network_orders_filter_args( $args ) { |
| 159 | - $args['post_status'] = array( |
|
| 159 | + $args[ 'post_status' ] = array( |
|
| 160 | 160 | 'wc-on-hold', |
| 161 | 161 | 'wc-processing', |
| 162 | 162 | ); |
@@ -680,13 +680,13 @@ discard block |
||
| 680 | 680 | public function get_collection_params() { |
| 681 | 681 | $params = parent::get_collection_params(); |
| 682 | 682 | |
| 683 | - $params['slug'] = array( |
|
| 683 | + $params[ 'slug' ] = array( |
|
| 684 | 684 | 'description' => __( 'Limit result set to products with a specific slug.', 'woocommerce-rest-api' ), |
| 685 | 685 | 'type' => 'string', |
| 686 | 686 | 'validate_callback' => 'rest_validate_request_arg', |
| 687 | 687 | ); |
| 688 | 688 | |
| 689 | - $params['status'] = array( |
|
| 689 | + $params[ 'status' ] = array( |
|
| 690 | 690 | 'default' => 'any', |
| 691 | 691 | 'description' => __( 'Limit result set to products assigned a specific status.', 'woocommerce-rest-api' ), |
| 692 | 692 | 'type' => 'string', |
@@ -695,7 +695,7 @@ discard block |
||
| 695 | 695 | 'validate_callback' => 'rest_validate_request_arg', |
| 696 | 696 | ); |
| 697 | 697 | |
| 698 | - $params['type'] = array( |
|
| 698 | + $params[ 'type' ] = array( |
|
| 699 | 699 | 'description' => __( 'Limit result set to products assigned a specific type.', 'woocommerce-rest-api' ), |
| 700 | 700 | 'type' => 'string', |
| 701 | 701 | 'enum' => array_keys( wc_get_product_types() ), |
@@ -703,49 +703,49 @@ discard block |
||
| 703 | 703 | 'validate_callback' => 'rest_validate_request_arg', |
| 704 | 704 | ); |
| 705 | 705 | |
| 706 | - $params['sku'] = array( |
|
| 706 | + $params[ 'sku' ] = array( |
|
| 707 | 707 | 'description' => __( 'Limit result set to products with specific SKU(s). Use commas to separate.', 'woocommerce-rest-api' ), |
| 708 | 708 | 'type' => 'string', |
| 709 | 709 | 'sanitize_callback' => 'sanitize_text_field', |
| 710 | 710 | 'validate_callback' => 'rest_validate_request_arg', |
| 711 | 711 | ); |
| 712 | 712 | |
| 713 | - $params['featured'] = array( |
|
| 713 | + $params[ 'featured' ] = array( |
|
| 714 | 714 | 'description' => __( 'Limit result set to featured products.', 'woocommerce-rest-api' ), |
| 715 | 715 | 'type' => 'boolean', |
| 716 | 716 | 'sanitize_callback' => 'wc_string_to_bool', |
| 717 | 717 | 'validate_callback' => 'rest_validate_request_arg', |
| 718 | 718 | ); |
| 719 | 719 | |
| 720 | - $params['category'] = array( |
|
| 720 | + $params[ 'category' ] = array( |
|
| 721 | 721 | 'description' => __( 'Limit result set to products assigned a specific category ID.', 'woocommerce-rest-api' ), |
| 722 | 722 | 'type' => 'string', |
| 723 | 723 | 'sanitize_callback' => 'wp_parse_id_list', |
| 724 | 724 | 'validate_callback' => 'rest_validate_request_arg', |
| 725 | 725 | ); |
| 726 | 726 | |
| 727 | - $params['tag'] = array( |
|
| 727 | + $params[ 'tag' ] = array( |
|
| 728 | 728 | 'description' => __( 'Limit result set to products assigned a specific tag ID.', 'woocommerce-rest-api' ), |
| 729 | 729 | 'type' => 'string', |
| 730 | 730 | 'sanitize_callback' => 'wp_parse_id_list', |
| 731 | 731 | 'validate_callback' => 'rest_validate_request_arg', |
| 732 | 732 | ); |
| 733 | 733 | |
| 734 | - $params['shipping_class'] = array( |
|
| 734 | + $params[ 'shipping_class' ] = array( |
|
| 735 | 735 | 'description' => __( 'Limit result set to products assigned a specific shipping class ID.', 'woocommerce-rest-api' ), |
| 736 | 736 | 'type' => 'string', |
| 737 | 737 | 'sanitize_callback' => 'wp_parse_id_list', |
| 738 | 738 | 'validate_callback' => 'rest_validate_request_arg', |
| 739 | 739 | ); |
| 740 | 740 | |
| 741 | - $params['attribute'] = array( |
|
| 741 | + $params[ 'attribute' ] = array( |
|
| 742 | 742 | 'description' => __( 'Limit result set to products with a specific attribute. Use the taxonomy name/attribute slug.', 'woocommerce-rest-api' ), |
| 743 | 743 | 'type' => 'string', |
| 744 | 744 | 'sanitize_callback' => 'sanitize_text_field', |
| 745 | 745 | 'validate_callback' => 'rest_validate_request_arg', |
| 746 | 746 | ); |
| 747 | 747 | |
| 748 | - $params['attribute_term'] = array( |
|
| 748 | + $params[ 'attribute_term' ] = array( |
|
| 749 | 749 | 'description' => __( 'Limit result set to products with a specific attribute term ID (required an assigned attribute).', 'woocommerce-rest-api' ), |
| 750 | 750 | 'type' => 'string', |
| 751 | 751 | 'sanitize_callback' => 'wp_parse_id_list', |
@@ -753,7 +753,7 @@ discard block |
||
| 753 | 753 | ); |
| 754 | 754 | |
| 755 | 755 | if ( wc_tax_enabled() ) { |
| 756 | - $params['tax_class'] = array( |
|
| 756 | + $params[ 'tax_class' ] = array( |
|
| 757 | 757 | 'description' => __( 'Limit result set to products with a specific tax class.', 'woocommerce-rest-api' ), |
| 758 | 758 | 'type' => 'string', |
| 759 | 759 | 'enum' => array_merge( array( 'standard' ), \WC_Tax::get_tax_class_slugs() ), |
@@ -762,28 +762,28 @@ discard block |
||
| 762 | 762 | ); |
| 763 | 763 | } |
| 764 | 764 | |
| 765 | - $params['on_sale'] = array( |
|
| 765 | + $params[ 'on_sale' ] = array( |
|
| 766 | 766 | 'description' => __( 'Limit result set to products on sale.', 'woocommerce-rest-api' ), |
| 767 | 767 | 'type' => 'boolean', |
| 768 | 768 | 'sanitize_callback' => 'wc_string_to_bool', |
| 769 | 769 | 'validate_callback' => 'rest_validate_request_arg', |
| 770 | 770 | ); |
| 771 | 771 | |
| 772 | - $params['min_price'] = array( |
|
| 772 | + $params[ 'min_price' ] = array( |
|
| 773 | 773 | 'description' => __( 'Limit result set to products based on a minimum price.', 'woocommerce-rest-api' ), |
| 774 | 774 | 'type' => 'string', |
| 775 | 775 | 'sanitize_callback' => 'sanitize_text_field', |
| 776 | 776 | 'validate_callback' => 'rest_validate_request_arg', |
| 777 | 777 | ); |
| 778 | 778 | |
| 779 | - $params['max_price'] = array( |
|
| 779 | + $params[ 'max_price' ] = array( |
|
| 780 | 780 | 'description' => __( 'Limit result set to products based on a maximum price.', 'woocommerce-rest-api' ), |
| 781 | 781 | 'type' => 'string', |
| 782 | 782 | 'sanitize_callback' => 'sanitize_text_field', |
| 783 | 783 | 'validate_callback' => 'rest_validate_request_arg', |
| 784 | 784 | ); |
| 785 | 785 | |
| 786 | - $params['stock_status'] = array( |
|
| 786 | + $params[ 'stock_status' ] = array( |
|
| 787 | 787 | 'description' => __( 'Limit result set to products with specified stock status.', 'woocommerce-rest-api' ), |
| 788 | 788 | 'type' => 'string', |
| 789 | 789 | 'enum' => array_keys( wc_get_product_stock_status_options() ), |
@@ -791,20 +791,20 @@ discard block |
||
| 791 | 791 | 'validate_callback' => 'rest_validate_request_arg', |
| 792 | 792 | ); |
| 793 | 793 | |
| 794 | - $params['low_in_stock'] = array( |
|
| 794 | + $params[ 'low_in_stock' ] = array( |
|
| 795 | 795 | 'description' => __( 'Limit result set to products that are low or out of stock.', 'woocommerce-rest-api' ), |
| 796 | 796 | 'type' => 'boolean', |
| 797 | 797 | 'default' => false, |
| 798 | 798 | 'sanitize_callback' => 'wc_string_to_bool', |
| 799 | 799 | ); |
| 800 | 800 | |
| 801 | - $params['search'] = array( |
|
| 801 | + $params[ 'search' ] = array( |
|
| 802 | 802 | 'description' => __( 'Search by similar product name or sku.', 'woocommerce-rest-api' ), |
| 803 | 803 | 'type' => 'string', |
| 804 | 804 | 'validate_callback' => 'rest_validate_request_arg', |
| 805 | 805 | ); |
| 806 | 806 | |
| 807 | - $params['orderby']['enum'] = array_merge( $params['orderby']['enum'], array( 'price', 'popularity', 'rating' ) ); |
|
| 807 | + $params[ 'orderby' ][ 'enum' ] = array_merge( $params[ 'orderby' ][ 'enum' ], array( 'price', 'popularity', 'rating' ) ); |
|
| 808 | 808 | |
| 809 | 809 | return $params; |
| 810 | 810 | } |
@@ -887,40 +887,40 @@ discard block |
||
| 887 | 887 | |
| 888 | 888 | if ( $wp_query->get( 'search' ) ) { |
| 889 | 889 | $search = "'%" . $wpdb->esc_like( $wp_query->get( 'search' ) ) . "%'"; |
| 890 | - $args['join'] = $this->append_product_sorting_table_join( $args['join'] ); |
|
| 891 | - $args['where'] .= " AND ({$wpdb->posts}.post_title LIKE {$search}"; |
|
| 892 | - $args['where'] .= wc_product_sku_enabled() ? ' OR wc_product_meta_lookup.sku LIKE ' . $search . ')' : ')'; |
|
| 890 | + $args[ 'join' ] = $this->append_product_sorting_table_join( $args[ 'join' ] ); |
|
| 891 | + $args[ 'where' ] .= " AND ({$wpdb->posts}.post_title LIKE {$search}"; |
|
| 892 | + $args[ 'where' ] .= wc_product_sku_enabled() ? ' OR wc_product_meta_lookup.sku LIKE ' . $search . ')' : ')'; |
|
| 893 | 893 | } |
| 894 | 894 | |
| 895 | 895 | if ( $wp_query->get( 'sku' ) ) { |
| 896 | 896 | $skus = explode( ',', $wp_query->get( 'sku' ) ); |
| 897 | 897 | // Include the current string as a SKU too. |
| 898 | 898 | if ( 1 < count( $skus ) ) { |
| 899 | - $skus[] = $wp_query->get( 'sku' ); |
|
| 899 | + $skus[ ] = $wp_query->get( 'sku' ); |
|
| 900 | 900 | } |
| 901 | - $args['join'] = $this->append_product_sorting_table_join( $args['join'] ); |
|
| 902 | - $args['where'] .= ' AND wc_product_meta_lookup.sku IN ("' . implode( '","', array_map( 'esc_sql', $skus ) ) . '")'; |
|
| 901 | + $args[ 'join' ] = $this->append_product_sorting_table_join( $args[ 'join' ] ); |
|
| 902 | + $args[ 'where' ] .= ' AND wc_product_meta_lookup.sku IN ("' . implode( '","', array_map( 'esc_sql', $skus ) ) . '")'; |
|
| 903 | 903 | } |
| 904 | 904 | |
| 905 | 905 | if ( $wp_query->get( 'min_price' ) ) { |
| 906 | - $args['join'] = $this->append_product_sorting_table_join( $args['join'] ); |
|
| 907 | - $args['where'] .= $wpdb->prepare( ' AND wc_product_meta_lookup.min_price >= %f ', floatval( $wp_query->get( 'min_price' ) ) ); |
|
| 906 | + $args[ 'join' ] = $this->append_product_sorting_table_join( $args[ 'join' ] ); |
|
| 907 | + $args[ 'where' ] .= $wpdb->prepare( ' AND wc_product_meta_lookup.min_price >= %f ', floatval( $wp_query->get( 'min_price' ) ) ); |
|
| 908 | 908 | } |
| 909 | 909 | |
| 910 | 910 | if ( $wp_query->get( 'max_price' ) ) { |
| 911 | - $args['join'] = $this->append_product_sorting_table_join( $args['join'] ); |
|
| 912 | - $args['where'] .= $wpdb->prepare( ' AND wc_product_meta_lookup.max_price <= %f ', floatval( $wp_query->get( 'max_price' ) ) ); |
|
| 911 | + $args[ 'join' ] = $this->append_product_sorting_table_join( $args[ 'join' ] ); |
|
| 912 | + $args[ 'where' ] .= $wpdb->prepare( ' AND wc_product_meta_lookup.max_price <= %f ', floatval( $wp_query->get( 'max_price' ) ) ); |
|
| 913 | 913 | } |
| 914 | 914 | |
| 915 | 915 | if ( $wp_query->get( 'stock_status' ) ) { |
| 916 | - $args['join'] = $this->append_product_sorting_table_join( $args['join'] ); |
|
| 917 | - $args['where'] .= $wpdb->prepare( ' AND wc_product_meta_lookup.stock_status = %s ', $wp_query->get( 'stock_status' ) ); |
|
| 916 | + $args[ 'join' ] = $this->append_product_sorting_table_join( $args[ 'join' ] ); |
|
| 917 | + $args[ 'where' ] .= $wpdb->prepare( ' AND wc_product_meta_lookup.stock_status = %s ', $wp_query->get( 'stock_status' ) ); |
|
| 918 | 918 | } |
| 919 | 919 | |
| 920 | 920 | if ( $wp_query->get( 'low_in_stock' ) ) { |
| 921 | 921 | $low_stock = absint( max( get_option( 'woocommerce_notify_low_stock_amount' ), 1 ) ); |
| 922 | - $args['join'] = $this->append_product_sorting_table_join( $args['join'] ); |
|
| 923 | - $args['where'] .= $wpdb->prepare( ' AND wc_product_meta_lookup.stock_quantity <= %d', $low_stock ); |
|
| 922 | + $args[ 'join' ] = $this->append_product_sorting_table_join( $args[ 'join' ] ); |
|
| 923 | + $args[ 'where' ] .= $wpdb->prepare( ' AND wc_product_meta_lookup.stock_quantity <= %d', $low_stock ); |
|
| 924 | 924 | } |
| 925 | 925 | |
| 926 | 926 | return $args; |
@@ -952,7 +952,7 @@ discard block |
||
| 952 | 952 | $args = parent::prepare_objects_query( $request ); |
| 953 | 953 | |
| 954 | 954 | // Set post_status. |
| 955 | - $args['post_status'] = $request['status']; |
|
| 955 | + $args[ 'post_status' ] = $request[ 'status' ]; |
|
| 956 | 956 | |
| 957 | 957 | // Set custom args to handle later during clauses. |
| 958 | 958 | $custom_keys = array( |
@@ -982,7 +982,7 @@ discard block |
||
| 982 | 982 | // Set tax_query for each passed arg. |
| 983 | 983 | foreach ( $taxonomies as $taxonomy => $key ) { |
| 984 | 984 | if ( ! empty( $request[ $key ] ) ) { |
| 985 | - $tax_query[] = array( |
|
| 985 | + $tax_query[ ] = array( |
|
| 986 | 986 | 'taxonomy' => $taxonomy, |
| 987 | 987 | 'field' => 'term_id', |
| 988 | 988 | 'terms' => $request[ $key ], |
@@ -991,58 +991,58 @@ discard block |
||
| 991 | 991 | } |
| 992 | 992 | |
| 993 | 993 | // Filter product type by slug. |
| 994 | - if ( ! empty( $request['type'] ) ) { |
|
| 995 | - $tax_query[] = array( |
|
| 994 | + if ( ! empty( $request[ 'type' ] ) ) { |
|
| 995 | + $tax_query[ ] = array( |
|
| 996 | 996 | 'taxonomy' => 'product_type', |
| 997 | 997 | 'field' => 'slug', |
| 998 | - 'terms' => $request['type'], |
|
| 998 | + 'terms' => $request[ 'type' ], |
|
| 999 | 999 | ); |
| 1000 | 1000 | } |
| 1001 | 1001 | |
| 1002 | 1002 | // Filter by attribute and term. |
| 1003 | - if ( ! empty( $request['attribute'] ) && ! empty( $request['attribute_term'] ) ) { |
|
| 1004 | - if ( in_array( $request['attribute'], wc_get_attribute_taxonomy_names(), true ) ) { |
|
| 1005 | - $tax_query[] = array( |
|
| 1006 | - 'taxonomy' => $request['attribute'], |
|
| 1003 | + if ( ! empty( $request[ 'attribute' ] ) && ! empty( $request[ 'attribute_term' ] ) ) { |
|
| 1004 | + if ( in_array( $request[ 'attribute' ], wc_get_attribute_taxonomy_names(), true ) ) { |
|
| 1005 | + $tax_query[ ] = array( |
|
| 1006 | + 'taxonomy' => $request[ 'attribute' ], |
|
| 1007 | 1007 | 'field' => 'term_id', |
| 1008 | - 'terms' => $request['attribute_term'], |
|
| 1008 | + 'terms' => $request[ 'attribute_term' ], |
|
| 1009 | 1009 | ); |
| 1010 | 1010 | } |
| 1011 | 1011 | } |
| 1012 | 1012 | |
| 1013 | 1013 | // Build tax_query if taxonomies are set. |
| 1014 | 1014 | if ( ! empty( $tax_query ) ) { |
| 1015 | - if ( ! empty( $args['tax_query'] ) ) { |
|
| 1016 | - $args['tax_query'] = array_merge( $tax_query, $args['tax_query'] ); // WPCS: slow query ok. |
|
| 1015 | + if ( ! empty( $args[ 'tax_query' ] ) ) { |
|
| 1016 | + $args[ 'tax_query' ] = array_merge( $tax_query, $args[ 'tax_query' ] ); // WPCS: slow query ok. |
|
| 1017 | 1017 | } else { |
| 1018 | - $args['tax_query'] = $tax_query; // WPCS: slow query ok. |
|
| 1018 | + $args[ 'tax_query' ] = $tax_query; // WPCS: slow query ok. |
|
| 1019 | 1019 | } |
| 1020 | 1020 | } |
| 1021 | 1021 | |
| 1022 | 1022 | // Filter featured. |
| 1023 | - if ( is_bool( $request['featured'] ) ) { |
|
| 1024 | - $args['tax_query'][] = array( |
|
| 1023 | + if ( is_bool( $request[ 'featured' ] ) ) { |
|
| 1024 | + $args[ 'tax_query' ][ ] = array( |
|
| 1025 | 1025 | 'taxonomy' => 'product_visibility', |
| 1026 | 1026 | 'field' => 'name', |
| 1027 | 1027 | 'terms' => 'featured', |
| 1028 | - 'operator' => true === $request['featured'] ? 'IN' : 'NOT IN', |
|
| 1028 | + 'operator' => true === $request[ 'featured' ] ? 'IN' : 'NOT IN', |
|
| 1029 | 1029 | ); |
| 1030 | 1030 | } |
| 1031 | 1031 | |
| 1032 | 1032 | // Filter by tax class. |
| 1033 | - if ( ! empty( $request['tax_class'] ) ) { |
|
| 1034 | - $args['meta_query'] = $this->add_meta_query( // WPCS: slow query ok. |
|
| 1033 | + if ( ! empty( $request[ 'tax_class' ] ) ) { |
|
| 1034 | + $args[ 'meta_query' ] = $this->add_meta_query( // WPCS: slow query ok. |
|
| 1035 | 1035 | $args, |
| 1036 | 1036 | array( |
| 1037 | 1037 | 'key' => '_tax_class', |
| 1038 | - 'value' => 'standard' !== $request['tax_class'] ? $request['tax_class'] : '', |
|
| 1038 | + 'value' => 'standard' !== $request[ 'tax_class' ] ? $request[ 'tax_class' ] : '', |
|
| 1039 | 1039 | ) |
| 1040 | 1040 | ); |
| 1041 | 1041 | } |
| 1042 | 1042 | |
| 1043 | 1043 | // Filter by on sale products. |
| 1044 | - if ( is_bool( $request['on_sale'] ) ) { |
|
| 1045 | - $on_sale_key = $request['on_sale'] ? 'post__in' : 'post__not_in'; |
|
| 1044 | + if ( is_bool( $request[ 'on_sale' ] ) ) { |
|
| 1045 | + $on_sale_key = $request[ 'on_sale' ] ? 'post__in' : 'post__not_in'; |
|
| 1046 | 1046 | $on_sale_ids = wc_get_product_ids_on_sale(); |
| 1047 | 1047 | |
| 1048 | 1048 | // Use 0 when there's no on sale products to avoid return all products. |
@@ -1052,20 +1052,20 @@ discard block |
||
| 1052 | 1052 | } |
| 1053 | 1053 | |
| 1054 | 1054 | // Force the post_type argument, since it's not a user input variable. |
| 1055 | - if ( ! empty( $request['sku'] ) ) { |
|
| 1056 | - $args['post_type'] = array( 'product', 'product_variation' ); |
|
| 1055 | + if ( ! empty( $request[ 'sku' ] ) ) { |
|
| 1056 | + $args[ 'post_type' ] = array( 'product', 'product_variation' ); |
|
| 1057 | 1057 | } else { |
| 1058 | - $args['post_type'] = $this->post_type; |
|
| 1058 | + $args[ 'post_type' ] = $this->post_type; |
|
| 1059 | 1059 | } |
| 1060 | 1060 | |
| 1061 | 1061 | $orderby = $request->get_param( 'orderby' ); |
| 1062 | 1062 | $order = $request->get_param( 'order' ); |
| 1063 | 1063 | |
| 1064 | 1064 | $ordering_args = WC()->query->get_catalog_ordering_args( $orderby, $order ); |
| 1065 | - $args['orderby'] = $ordering_args['orderby']; |
|
| 1066 | - $args['order'] = $ordering_args['order']; |
|
| 1067 | - if ( $ordering_args['meta_key'] ) { |
|
| 1068 | - $args['meta_key'] = $ordering_args['meta_key']; // WPCS: slow query ok. |
|
| 1065 | + $args[ 'orderby' ] = $ordering_args[ 'orderby' ]; |
|
| 1066 | + $args[ 'order' ] = $ordering_args[ 'order' ]; |
|
| 1067 | + if ( $ordering_args[ 'meta_key' ] ) { |
|
| 1068 | + $args[ 'meta_key' ] = $ordering_args[ 'meta_key' ]; // WPCS: slow query ok. |
|
| 1069 | 1069 | } |
| 1070 | 1070 | |
| 1071 | 1071 | return $args; |
@@ -1081,16 +1081,16 @@ discard block |
||
| 1081 | 1081 | protected function prepare_links( $item, $request ) { |
| 1082 | 1082 | $links = array( |
| 1083 | 1083 | 'self' => array( |
| 1084 | - 'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $item->get_id() ) ), // @codingStandardsIgnoreLine. |
|
| 1084 | + 'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $item->get_id() ) ), // @codingStandardsIgnoreLine. |
|
| 1085 | 1085 | ), |
| 1086 | 1086 | 'collection' => array( |
| 1087 | - 'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ), // @codingStandardsIgnoreLine. |
|
| 1087 | + 'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ), // @codingStandardsIgnoreLine. |
|
| 1088 | 1088 | ), |
| 1089 | 1089 | ); |
| 1090 | 1090 | |
| 1091 | 1091 | if ( $item->get_parent_id() ) { |
| 1092 | - $links['up'] = array( |
|
| 1093 | - 'href' => rest_url( sprintf( '/%s/products/%d', $this->namespace, $item->get_parent_id() ) ), // @codingStandardsIgnoreLine. |
|
| 1092 | + $links[ 'up' ] = array( |
|
| 1093 | + 'href' => rest_url( sprintf( '/%s/products/%d', $this->namespace, $item->get_parent_id() ) ), // @codingStandardsIgnoreLine. |
|
| 1094 | 1094 | ); |
| 1095 | 1095 | } |
| 1096 | 1096 | |
@@ -1105,9 +1105,9 @@ discard block |
||
| 1105 | 1105 | * @return \WP_REST_Response|\WP_Error |
| 1106 | 1106 | */ |
| 1107 | 1107 | public function delete_item( $request ) { |
| 1108 | - $id = (int) $request['id']; |
|
| 1109 | - $force = (bool) $request['force']; |
|
| 1110 | - $object = $this->get_object( (int) $request['id'] ); |
|
| 1108 | + $id = (int) $request[ 'id' ]; |
|
| 1109 | + $force = (bool) $request[ 'force' ]; |
|
| 1110 | + $object = $this->get_object( (int) $request[ 'id' ] ); |
|
| 1111 | 1111 | $result = false; |
| 1112 | 1112 | |
| 1113 | 1113 | if ( ! $object || 0 === $object->get_id() ) { |
@@ -522,17 +522,17 @@ discard block |
||
| 522 | 522 | $params = parent::get_collection_params(); |
| 523 | 523 | |
| 524 | 524 | unset( |
| 525 | - $params['in_stock'], |
|
| 526 | - $params['type'], |
|
| 527 | - $params['featured'], |
|
| 528 | - $params['category'], |
|
| 529 | - $params['tag'], |
|
| 530 | - $params['shipping_class'], |
|
| 531 | - $params['attribute'], |
|
| 532 | - $params['attribute_term'] |
|
| 525 | + $params[ 'in_stock' ], |
|
| 526 | + $params[ 'type' ], |
|
| 527 | + $params[ 'featured' ], |
|
| 528 | + $params[ 'category' ], |
|
| 529 | + $params[ 'tag' ], |
|
| 530 | + $params[ 'shipping_class' ], |
|
| 531 | + $params[ 'attribute' ], |
|
| 532 | + $params[ 'attribute_term' ] |
|
| 533 | 533 | ); |
| 534 | 534 | |
| 535 | - $params['stock_status'] = array( |
|
| 535 | + $params[ 'stock_status' ] = array( |
|
| 536 | 536 | 'description' => __( 'Limit result set to products with specified stock status.', 'woocommerce-rest-api' ), |
| 537 | 537 | 'type' => 'string', |
| 538 | 538 | 'enum' => array_keys( wc_get_product_stock_status_options() ), |
@@ -540,7 +540,7 @@ discard block |
||
| 540 | 540 | 'validate_callback' => 'rest_validate_request_arg', |
| 541 | 541 | ); |
| 542 | 542 | |
| 543 | - $params['search'] = array( |
|
| 543 | + $params[ 'search' ] = array( |
|
| 544 | 544 | 'description' => __( 'Search by similar product name or sku.', 'woocommerce-rest-api' ), |
| 545 | 545 | 'type' => 'string', |
| 546 | 546 | 'validate_callback' => 'rest_validate_request_arg', |
@@ -575,7 +575,7 @@ discard block |
||
| 575 | 575 | } |
| 576 | 576 | |
| 577 | 577 | // Check if variation belongs to the correct parent product. |
| 578 | - if ( $object && 0 !== $object->get_parent_id() && absint( $request['product_id'] ) !== $object->get_parent_id() ) { |
|
| 578 | + if ( $object && 0 !== $object->get_parent_id() && absint( $request[ 'product_id' ] ) !== $object->get_parent_id() ) { |
|
| 579 | 579 | return new \WP_Error( 'woocommerce_rest_cannot_edit', __( 'Parent product does not match current variation.', 'woocommerce-rest-api' ), array( 'status' => rest_authorization_required_code() ) ); |
| 580 | 580 | } |
| 581 | 581 | return true; |
@@ -653,7 +653,7 @@ discard block |
||
| 653 | 653 | $args = parent::prepare_objects_query( $request ); |
| 654 | 654 | |
| 655 | 655 | // Set post_status. |
| 656 | - $args['post_status'] = $request['status']; |
|
| 656 | + $args[ 'post_status' ] = $request[ 'status' ]; |
|
| 657 | 657 | |
| 658 | 658 | // Set custom args to handle later during clauses. |
| 659 | 659 | $custom_keys = array( |
@@ -670,19 +670,19 @@ discard block |
||
| 670 | 670 | } |
| 671 | 671 | |
| 672 | 672 | // Filter by tax class. |
| 673 | - if ( ! empty( $request['tax_class'] ) ) { |
|
| 674 | - $args['meta_query'] = $this->add_meta_query( // WPCS: slow query ok. |
|
| 673 | + if ( ! empty( $request[ 'tax_class' ] ) ) { |
|
| 674 | + $args[ 'meta_query' ] = $this->add_meta_query( // WPCS: slow query ok. |
|
| 675 | 675 | $args, |
| 676 | 676 | array( |
| 677 | 677 | 'key' => '_tax_class', |
| 678 | - 'value' => 'standard' !== $request['tax_class'] ? $request['tax_class'] : '', |
|
| 678 | + 'value' => 'standard' !== $request[ 'tax_class' ] ? $request[ 'tax_class' ] : '', |
|
| 679 | 679 | ) |
| 680 | 680 | ); |
| 681 | 681 | } |
| 682 | 682 | |
| 683 | 683 | // Filter by on sale products. |
| 684 | - if ( is_bool( $request['on_sale'] ) ) { |
|
| 685 | - $on_sale_key = $request['on_sale'] ? 'post__in' : 'post__not_in'; |
|
| 684 | + if ( is_bool( $request[ 'on_sale' ] ) ) { |
|
| 685 | + $on_sale_key = $request[ 'on_sale' ] ? 'post__in' : 'post__not_in'; |
|
| 686 | 686 | $on_sale_ids = wc_get_product_ids_on_sale(); |
| 687 | 687 | |
| 688 | 688 | // Use 0 when there's no on sale products to avoid return all products. |
@@ -692,17 +692,17 @@ discard block |
||
| 692 | 692 | } |
| 693 | 693 | |
| 694 | 694 | // Force the post_type argument, since it's not a user input variable. |
| 695 | - if ( ! empty( $request['sku'] ) ) { |
|
| 696 | - $args['post_type'] = array( 'product', 'product_variation' ); |
|
| 695 | + if ( ! empty( $request[ 'sku' ] ) ) { |
|
| 696 | + $args[ 'post_type' ] = array( 'product', 'product_variation' ); |
|
| 697 | 697 | } else { |
| 698 | - $args['post_type'] = $this->post_type; |
|
| 698 | + $args[ 'post_type' ] = $this->post_type; |
|
| 699 | 699 | } |
| 700 | 700 | |
| 701 | - $args['post_parent'] = $request['product_id']; |
|
| 701 | + $args[ 'post_parent' ] = $request[ 'product_id' ]; |
|
| 702 | 702 | |
| 703 | - if ( ! empty( $request['search'] ) ) { |
|
| 704 | - $args['search'] = $request['search']; |
|
| 705 | - unset( $args['s'] ); |
|
| 703 | + if ( ! empty( $request[ 'search' ] ) ) { |
|
| 704 | + $args[ 'search' ] = $request[ 'search' ]; |
|
| 705 | + unset( $args[ 's' ] ); |
|
| 706 | 706 | } |
| 707 | 707 | |
| 708 | 708 | return $args; |
@@ -745,8 +745,8 @@ discard block |
||
| 745 | 745 | * @return bool|\WP_Error|\WP_REST_Response |
| 746 | 746 | */ |
| 747 | 747 | public function delete_item( $request ) { |
| 748 | - $force = (bool) $request['force']; |
|
| 749 | - $object = $this->get_object( (int) $request['id'] ); |
|
| 748 | + $force = (bool) $request[ 'force' ]; |
|
| 749 | + $object = $this->get_object( (int) $request[ 'id' ] ); |
|
| 750 | 750 | $result = false; |
| 751 | 751 | |
| 752 | 752 | if ( ! $object || 0 === $object->get_id() ) { |
@@ -854,7 +854,7 @@ discard block |
||
| 854 | 854 | protected function get_batch_of_items_from_request( $request, $batch_type ) { |
| 855 | 855 | $params = $request->get_params(); |
| 856 | 856 | $url_params = $request->get_url_params(); |
| 857 | - $product_id = $url_params['product_id']; |
|
| 857 | + $product_id = $url_params[ 'product_id' ]; |
|
| 858 | 858 | |
| 859 | 859 | if ( ! isset( $params[ $batch_type ] ) ) { |
| 860 | 860 | return array(); |
@@ -884,7 +884,7 @@ discard block |
||
| 884 | 884 | * @return array |
| 885 | 885 | */ |
| 886 | 886 | protected function prepare_links( $item, $request ) { |
| 887 | - $product_id = (int) $request['product_id']; |
|
| 887 | + $product_id = (int) $request[ 'product_id' ]; |
|
| 888 | 888 | $base = str_replace( '(?P<product_id>[\d]+)', $product_id, $this->rest_base ); |
| 889 | 889 | $links = array( |
| 890 | 890 | 'self' => array( |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | * @return \WP_Error|boolean |
| 47 | 47 | */ |
| 48 | 48 | public function get_items_permissions_check( $request ) { |
| 49 | - $customer = get_user_by( 'id', (int) $request['customer_id'] ); |
|
| 49 | + $customer = get_user_by( 'id', (int) $request[ 'customer_id' ] ); |
|
| 50 | 50 | |
| 51 | 51 | if ( ! $customer ) { |
| 52 | 52 | return new \WP_Error( 'woocommerce_rest_customer_invalid', __( 'Resource does not exist.', 'woocommerce-rest-api' ), array( 'status' => 404 ) ); |
@@ -66,13 +66,13 @@ discard block |
||
| 66 | 66 | * @return array |
| 67 | 67 | */ |
| 68 | 68 | public function get_items( $request ) { |
| 69 | - $downloads = wc_get_customer_available_downloads( (int) $request['customer_id'] ); |
|
| 69 | + $downloads = wc_get_customer_available_downloads( (int) $request[ 'customer_id' ] ); |
|
| 70 | 70 | |
| 71 | 71 | $data = array(); |
| 72 | 72 | foreach ( $downloads as $download_data ) { |
| 73 | 73 | $download = $this->prepare_item_for_response( (object) $download_data, $request ); |
| 74 | 74 | $download = $this->prepare_response_for_collection( $download ); |
| 75 | - $data[] = $download; |
|
| 75 | + $data[ ] = $download; |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | return rest_ensure_response( $data ); |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | * @return array |
| 110 | 110 | */ |
| 111 | 111 | protected function prepare_links( $item, $request ) { |
| 112 | - $base = str_replace( '(?P<customer_id>[\d]+)', $request['customer_id'], $this->rest_base ); |
|
| 112 | + $base = str_replace( '(?P<customer_id>[\d]+)', $request[ 'customer_id' ], $this->rest_base ); |
|
| 113 | 113 | $links = array( |
| 114 | 114 | 'collection' => array( |
| 115 | 115 | 'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $base ) ), |
@@ -55,13 +55,13 @@ discard block |
||
| 55 | 55 | public function get_items( $request ) { |
| 56 | 56 | global $wpdb; |
| 57 | 57 | |
| 58 | - if ( isset( $request['match'] ) ) { |
|
| 58 | + if ( isset( $request[ 'match' ] ) ) { |
|
| 59 | 59 | $downloads = $wpdb->get_results( |
| 60 | 60 | $wpdb->prepare( |
| 61 | 61 | "SELECT DISTINCT( user_ip_address ) FROM {$wpdb->prefix}wc_download_log |
| 62 | 62 | WHERE user_ip_address LIKE %s |
| 63 | 63 | LIMIT 10", |
| 64 | - $request['match'] . '%' |
|
| 64 | + $request[ 'match' ] . '%' |
|
| 65 | 65 | ) |
| 66 | 66 | ); |
| 67 | 67 | } else { |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | if ( ! empty( $downloads ) ) { |
| 74 | 74 | foreach ( $downloads as $download ) { |
| 75 | 75 | $response = $this->prepare_item_for_response( (array) $download, $request ); |
| 76 | - $data[] = $this->prepare_response_for_collection( $response ); |
|
| 76 | + $data[ ] = $this->prepare_response_for_collection( $response ); |
|
| 77 | 77 | } |
| 78 | 78 | } |
| 79 | 79 | |
@@ -114,8 +114,8 @@ discard block |
||
| 114 | 114 | */ |
| 115 | 115 | public function get_collection_params() { |
| 116 | 116 | $params = array(); |
| 117 | - $params['context'] = $this->get_context_param( array( 'default' => 'view' ) ); |
|
| 118 | - $params['match'] = array( |
|
| 117 | + $params[ 'context' ] = $this->get_context_param( array( 'default' => 'view' ) ); |
|
| 118 | + $params[ 'match' ] = array( |
|
| 119 | 119 | 'description' => __( 'A partial IP address can be passed and matching results will be returned.', 'woocommerce-rest-api' ), |
| 120 | 120 | 'type' => 'string', |
| 121 | 121 | 'validate_callback' => 'rest_validate_request_arg', |