@@ -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', |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | foreach ( array_keys( $currencies ) as $code ) { |
| 109 | 109 | $currency = $this->get_currency( $code, $request ); |
| 110 | 110 | $response = $this->prepare_item_for_response( $currency, $request ); |
| 111 | - $data[] = $this->prepare_response_for_collection( $response ); |
|
| 111 | + $data[ ] = $this->prepare_response_for_collection( $response ); |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | return rest_ensure_response( $data ); |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | * @return \WP_Error|\WP_REST_Response |
| 122 | 122 | */ |
| 123 | 123 | public function get_item( $request ) { |
| 124 | - $data = $this->get_currency( strtoupper( $request['currency'] ), $request ); |
|
| 124 | + $data = $this->get_currency( strtoupper( $request[ 'currency' ] ), $request ); |
|
| 125 | 125 | if ( empty( $data ) ) { |
| 126 | 126 | return new \WP_Error( 'woocommerce_rest_data_invalid_currency', __( 'There are no currencies matching these parameters.', 'woocommerce-rest-api' ), array( 'status' => 404 ) ); |
| 127 | 127 | } |
@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | * @return array |
| 159 | 159 | */ |
| 160 | 160 | protected function prepare_links( $item, $request ) { |
| 161 | - $code = strtoupper( $item['code'] ); |
|
| 161 | + $code = strtoupper( $item[ 'code' ] ); |
|
| 162 | 162 | $links = array( |
| 163 | 163 | 'self' => array( |
| 164 | 164 | 'href' => rest_url( sprintf( '/%s/%s/%s', $this->namespace, $this->rest_base, $code ) ), |
@@ -86,11 +86,11 @@ discard block |
||
| 86 | 86 | |
| 87 | 87 | $continent = array( |
| 88 | 88 | 'code' => $continent_code, |
| 89 | - 'name' => $continent_list['name'], |
|
| 89 | + 'name' => $continent_list[ 'name' ], |
|
| 90 | 90 | ); |
| 91 | 91 | |
| 92 | 92 | $local_countries = array(); |
| 93 | - foreach ( $continent_list['countries'] as $country_code ) { |
|
| 93 | + foreach ( $continent_list[ 'countries' ] as $country_code ) { |
|
| 94 | 94 | if ( isset( $countries[ $country_code ] ) ) { |
| 95 | 95 | $country = array( |
| 96 | 96 | 'code' => $country_code, |
@@ -119,13 +119,13 @@ discard block |
||
| 119 | 119 | $local_states = array(); |
| 120 | 120 | if ( isset( $states[ $country_code ] ) ) { |
| 121 | 121 | foreach ( $states[ $country_code ] as $state_code => $state_name ) { |
| 122 | - $local_states[] = array( |
|
| 122 | + $local_states[ ] = array( |
|
| 123 | 123 | 'code' => $state_code, |
| 124 | 124 | 'name' => $state_name, |
| 125 | 125 | ); |
| 126 | 126 | } |
| 127 | 127 | } |
| 128 | - $country['states'] = $local_states; |
|
| 128 | + $country[ 'states' ] = $local_states; |
|
| 129 | 129 | |
| 130 | 130 | // Allow only desired keys (e.g. filter out tax rates). |
| 131 | 131 | $allowed = array( |
@@ -142,11 +142,11 @@ discard block |
||
| 142 | 142 | ); |
| 143 | 143 | $country = array_intersect_key( $country, array_flip( $allowed ) ); |
| 144 | 144 | |
| 145 | - $local_countries[] = $country; |
|
| 145 | + $local_countries[ ] = $country; |
|
| 146 | 146 | } |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | - $continent['countries'] = $local_countries; |
|
| 149 | + $continent[ 'countries' ] = $local_countries; |
|
| 150 | 150 | return $continent; |
| 151 | 151 | } |
| 152 | 152 | |
@@ -164,7 +164,7 @@ discard block |
||
| 164 | 164 | foreach ( array_keys( $continents ) as $continent_code ) { |
| 165 | 165 | $continent = $this->get_continent( $continent_code, $request ); |
| 166 | 166 | $response = $this->prepare_item_for_response( $continent, $request ); |
| 167 | - $data[] = $this->prepare_response_for_collection( $response ); |
|
| 167 | + $data[ ] = $this->prepare_response_for_collection( $response ); |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | return rest_ensure_response( $data ); |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | * @return \WP_Error|\WP_REST_Response |
| 179 | 179 | */ |
| 180 | 180 | public function get_item( $request ) { |
| 181 | - $data = $this->get_continent( strtoupper( $request['location'] ), $request ); |
|
| 181 | + $data = $this->get_continent( strtoupper( $request[ 'location' ] ), $request ); |
|
| 182 | 182 | if ( empty( $data ) ) { |
| 183 | 183 | return new \WP_Error( 'woocommerce_rest_data_invalid_location', __( 'There are no locations matching these parameters.', 'woocommerce-rest-api' ), array( 'status' => 404 ) ); |
| 184 | 184 | } |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | * @return array |
| 205 | 205 | */ |
| 206 | 206 | protected function prepare_links( $item, $request ) { |
| 207 | - $continent_code = strtolower( $item['code'] ); |
|
| 207 | + $continent_code = strtolower( $item[ 'code' ] ); |
|
| 208 | 208 | $links = array( |
| 209 | 209 | 'self' => array( |
| 210 | 210 | 'href' => rest_url( sprintf( '/%s/%s/%s', $this->namespace, $this->rest_base, $continent_code ) ), |
@@ -87,13 +87,13 @@ discard block |
||
| 87 | 87 | $local_states = array(); |
| 88 | 88 | if ( isset( $states[ $country_code ] ) ) { |
| 89 | 89 | foreach ( $states[ $country_code ] as $state_code => $state_name ) { |
| 90 | - $local_states[] = array( |
|
| 90 | + $local_states[ ] = array( |
|
| 91 | 91 | 'code' => $state_code, |
| 92 | 92 | 'name' => $state_name, |
| 93 | 93 | ); |
| 94 | 94 | } |
| 95 | 95 | } |
| 96 | - $country['states'] = $local_states; |
|
| 96 | + $country[ 'states' ] = $local_states; |
|
| 97 | 97 | return $country; |
| 98 | 98 | } |
| 99 | 99 | |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | foreach ( array_keys( $countries ) as $country_code ) { |
| 112 | 112 | $country = $this->get_country( $country_code, $request ); |
| 113 | 113 | $response = $this->prepare_item_for_response( $country, $request ); |
| 114 | - $data[] = $this->prepare_response_for_collection( $response ); |
|
| 114 | + $data[ ] = $this->prepare_response_for_collection( $response ); |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | return rest_ensure_response( $data ); |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | * @return \WP_Error|\WP_REST_Response |
| 126 | 126 | */ |
| 127 | 127 | public function get_item( $request ) { |
| 128 | - $data = $this->get_country( strtoupper( $request['location'] ), $request ); |
|
| 128 | + $data = $this->get_country( strtoupper( $request[ 'location' ] ), $request ); |
|
| 129 | 129 | if ( empty( $data ) ) { |
| 130 | 130 | return new \WP_Error( 'woocommerce_rest_data_invalid_location', __( 'There are no locations matching these parameters.', 'woocommerce-rest-api' ), array( 'status' => 404 ) ); |
| 131 | 131 | } |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | * @return array |
| 152 | 152 | */ |
| 153 | 153 | protected function prepare_links( $item, $request ) { |
| 154 | - $country_code = strtolower( $item['code'] ); |
|
| 154 | + $country_code = strtolower( $item[ 'code' ] ); |
|
| 155 | 155 | $links = array( |
| 156 | 156 | 'self' => array( |
| 157 | 157 | 'href' => rest_url( sprintf( '/%s/%s/%s', $this->namespace, $this->rest_base, $country_code ) ), |