@@ -22,7 +22,7 @@ |
||
| 22 | 22 | * |
| 23 | 23 | * @var array |
| 24 | 24 | */ |
| 25 | - protected $controllers = []; |
|
| 25 | + protected $controllers = [ ]; |
|
| 26 | 26 | |
| 27 | 27 | /** |
| 28 | 28 | * Hook into WordPress ready to init the REST API as needed. |
@@ -102,7 +102,7 @@ |
||
| 102 | 102 | |
| 103 | 103 | foreach ( $resources as $resource ) { |
| 104 | 104 | $item = $this->prepare_item_for_response( (object) $resource, $request ); |
| 105 | - $data[] = $this->prepare_response_for_collection( $item ); |
|
| 105 | + $data[ ] = $this->prepare_response_for_collection( $item ); |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | return rest_ensure_response( $data ); |
@@ -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' ), |
| 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' ), |
| 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' ), |
| 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' ), |
| 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' ), |
| 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' ), $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' ), $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 | ); |
@@ -27,7 +27,7 @@ |
||
| 27 | 27 | * |
| 28 | 28 | * @var array |
| 29 | 29 | */ |
| 30 | - protected static $classmap = []; |
|
| 30 | + protected static $classmap = [ ]; |
|
| 31 | 31 | |
| 32 | 32 | /** |
| 33 | 33 | * Register the autoloader. |
@@ -164,7 +164,7 @@ discard block |
||
| 164 | 164 | |
| 165 | 165 | // Jetpack does the image resizing heavy lifting so you don't have to. |
| 166 | 166 | if ( ( class_exists( 'Jetpack' ) && Jetpack::is_module_active( 'photon' ) ) || ! apply_filters( 'woocommerce_background_image_regeneration', true ) ) { |
| 167 | - unset( $tools['regenerate_thumbnails'] ); |
|
| 167 | + unset( $tools[ 'regenerate_thumbnails' ] ); |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | return apply_filters( 'woocommerce_debug_tools', $tools ); |
@@ -179,13 +179,13 @@ discard block |
||
| 179 | 179 | public function get_items( $request ) { |
| 180 | 180 | $tools = array(); |
| 181 | 181 | foreach ( $this->get_tools() as $id => $tool ) { |
| 182 | - $tools[] = $this->prepare_response_for_collection( |
|
| 182 | + $tools[ ] = $this->prepare_response_for_collection( |
|
| 183 | 183 | $this->prepare_item_for_response( |
| 184 | 184 | array( |
| 185 | 185 | 'id' => $id, |
| 186 | - 'name' => $tool['name'], |
|
| 187 | - 'action' => $tool['button'], |
|
| 188 | - 'description' => $tool['desc'], |
|
| 186 | + 'name' => $tool[ 'name' ], |
|
| 187 | + 'action' => $tool[ 'button' ], |
|
| 188 | + 'description' => $tool[ 'desc' ], |
|
| 189 | 189 | ), |
| 190 | 190 | $request |
| 191 | 191 | ) |
@@ -204,17 +204,17 @@ discard block |
||
| 204 | 204 | */ |
| 205 | 205 | public function get_item( $request ) { |
| 206 | 206 | $tools = $this->get_tools(); |
| 207 | - if ( empty( $tools[ $request['id'] ] ) ) { |
|
| 207 | + if ( empty( $tools[ $request[ 'id' ] ] ) ) { |
|
| 208 | 208 | return new \WP_Error( 'woocommerce_rest_system_status_tool_invalid_id', __( 'Invalid tool ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
| 209 | 209 | } |
| 210 | - $tool = $tools[ $request['id'] ]; |
|
| 210 | + $tool = $tools[ $request[ 'id' ] ]; |
|
| 211 | 211 | return rest_ensure_response( |
| 212 | 212 | $this->prepare_item_for_response( |
| 213 | 213 | array( |
| 214 | - 'id' => $request['id'], |
|
| 215 | - 'name' => $tool['name'], |
|
| 216 | - 'action' => $tool['button'], |
|
| 217 | - 'description' => $tool['desc'], |
|
| 214 | + 'id' => $request[ 'id' ], |
|
| 215 | + 'name' => $tool[ 'name' ], |
|
| 216 | + 'action' => $tool[ 'button' ], |
|
| 217 | + 'description' => $tool[ 'desc' ], |
|
| 218 | 218 | ), |
| 219 | 219 | $request |
| 220 | 220 | ) |
@@ -229,19 +229,19 @@ discard block |
||
| 229 | 229 | */ |
| 230 | 230 | public function update_item( $request ) { |
| 231 | 231 | $tools = $this->get_tools(); |
| 232 | - if ( empty( $tools[ $request['id'] ] ) ) { |
|
| 232 | + if ( empty( $tools[ $request[ 'id' ] ] ) ) { |
|
| 233 | 233 | return new \WP_Error( 'woocommerce_rest_system_status_tool_invalid_id', __( 'Invalid tool ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
| 234 | 234 | } |
| 235 | 235 | |
| 236 | - $tool = $tools[ $request['id'] ]; |
|
| 236 | + $tool = $tools[ $request[ 'id' ] ]; |
|
| 237 | 237 | $tool = array( |
| 238 | - 'id' => $request['id'], |
|
| 239 | - 'name' => $tool['name'], |
|
| 240 | - 'action' => $tool['button'], |
|
| 241 | - 'description' => $tool['desc'], |
|
| 238 | + 'id' => $request[ 'id' ], |
|
| 239 | + 'name' => $tool[ 'name' ], |
|
| 240 | + 'action' => $tool[ 'button' ], |
|
| 241 | + 'description' => $tool[ 'desc' ], |
|
| 242 | 242 | ); |
| 243 | 243 | |
| 244 | - $execute_return = $this->execute_tool( $request['id'] ); |
|
| 244 | + $execute_return = $this->execute_tool( $request[ 'id' ] ); |
|
| 245 | 245 | $tool = array_merge( $tool, $execute_return ); |
| 246 | 246 | |
| 247 | 247 | /** |
@@ -330,7 +330,7 @@ discard block |
||
| 330 | 330 | $base = '/' . $this->namespace . '/' . $this->rest_base; |
| 331 | 331 | $links = array( |
| 332 | 332 | 'item' => array( |
| 333 | - 'href' => rest_url( trailingslashit( $base ) . $item['id'] ), |
|
| 333 | + 'href' => rest_url( trailingslashit( $base ) . $item[ 'id' ] ), |
|
| 334 | 334 | 'embeddable' => true, |
| 335 | 335 | ), |
| 336 | 336 | ); |
@@ -365,7 +365,7 @@ discard block |
||
| 365 | 365 | throw new Exception( __( 'There was an error calling this tool. There is no callback present.', 'woocommerce' ) ); |
| 366 | 366 | } |
| 367 | 367 | |
| 368 | - $callback = isset( $tools[ $tool ]['callback'] ) ? $tools[ $tool ]['callback'] : array( $this, $tool ); |
|
| 368 | + $callback = isset( $tools[ $tool ][ 'callback' ] ) ? $tools[ $tool ][ 'callback' ] : array( $this, $tool ); |
|
| 369 | 369 | |
| 370 | 370 | if ( ! is_callable( $callback ) ) { |
| 371 | 371 | throw new Exception( __( 'There was an error calling this tool. Invalid callback.', 'woocommerce' ) ); |
@@ -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' ), |
| 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' ), |
| 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' ), |
| 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' ), |
| 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' ), |
| 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' ), |
| 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' ), |
| 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' ), |
| 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' ), |
| 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' ), |
| 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' ), |
| 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' ), |
| 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' ), |
| 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' ), |
| 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' ), |
| 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' ), |
| 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' ), |
| 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() ) { |
@@ -57,7 +57,7 @@ |
||
| 57 | 57 | |
| 58 | 58 | if ( ! is_null( $meta_data ) ) { |
| 59 | 59 | foreach ( $meta_data as $meta ) { |
| 60 | - $object->update_meta_data( $meta['key'], $meta['value'], isset( $meta['id'] ) ? $meta['id'] : '' ); |
|
| 60 | + $object->update_meta_data( $meta[ 'key' ], $meta[ 'value' ], isset( $meta[ 'id' ] ) ? $meta[ 'id' ] : '' ); |
|
| 61 | 61 | } |
| 62 | 62 | } |
| 63 | 63 | } |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | ]; |
| 52 | 52 | |
| 53 | 53 | $request_props = array_intersect_key( $this->request, array_flip( $props ) ); |
| 54 | - $prop_values = []; |
|
| 54 | + $prop_values = [ ]; |
|
| 55 | 55 | |
| 56 | 56 | foreach ( $request_props as $prop => $value ) { |
| 57 | 57 | switch ( $prop ) { |
@@ -95,8 +95,8 @@ discard block |
||
| 95 | 95 | if ( ! is_array( $item ) ) { |
| 96 | 96 | continue; |
| 97 | 97 | } |
| 98 | - if ( $this->item_is_null( $item ) || ( isset( $item['quantity'] ) && 0 === $item['quantity'] ) ) { |
|
| 99 | - $object->remove_item( $item['id'] ); |
|
| 98 | + if ( $this->item_is_null( $item ) || ( isset( $item[ 'quantity' ] ) && 0 === $item[ 'quantity' ] ) ) { |
|
| 99 | + $object->remove_item( $item[ 'id' ] ); |
|
| 100 | 100 | } else { |
| 101 | 101 | $this->set_item( $object, $type, $item ); |
| 102 | 102 | } |
@@ -156,11 +156,11 @@ discard block |
||
| 156 | 156 | * @param array $posted Request data. |
| 157 | 157 | */ |
| 158 | 158 | protected function maybe_set_item_meta_data( $item, $posted ) { |
| 159 | - if ( ! empty( $posted['meta_data'] ) && is_array( $posted['meta_data'] ) ) { |
|
| 160 | - foreach ( $posted['meta_data'] as $meta ) { |
|
| 161 | - if ( isset( $meta['key'] ) ) { |
|
| 162 | - $value = isset( $meta['value'] ) ? $meta['value'] : null; |
|
| 163 | - $item->update_meta_data( $meta['key'], $value, isset( $meta['id'] ) ? $meta['id'] : '' ); |
|
| 159 | + if ( ! empty( $posted[ 'meta_data' ] ) && is_array( $posted[ 'meta_data' ] ) ) { |
|
| 160 | + foreach ( $posted[ 'meta_data' ] as $meta ) { |
|
| 161 | + if ( isset( $meta[ 'key' ] ) ) { |
|
| 162 | + $value = isset( $meta[ 'value' ] ) ? $meta[ 'value' ] : null; |
|
| 163 | + $item->update_meta_data( $meta[ 'key' ], $value, isset( $meta[ 'id' ] ) ? $meta[ 'id' ] : '' ); |
|
| 164 | 164 | } |
| 165 | 165 | } |
| 166 | 166 | } |
@@ -174,12 +174,12 @@ discard block |
||
| 174 | 174 | * @throws \WC_REST_Exception When SKU or ID is not valid. |
| 175 | 175 | */ |
| 176 | 176 | protected function get_product_id_from_line_item( $posted ) { |
| 177 | - if ( ! empty( $posted['sku'] ) ) { |
|
| 178 | - $product_id = (int) wc_get_product_id_by_sku( $posted['sku'] ); |
|
| 179 | - } elseif ( ! empty( $posted['product_id'] ) && empty( $posted['variation_id'] ) ) { |
|
| 180 | - $product_id = (int) $posted['product_id']; |
|
| 181 | - } elseif ( ! empty( $posted['variation_id'] ) ) { |
|
| 182 | - $product_id = (int) $posted['variation_id']; |
|
| 177 | + if ( ! empty( $posted[ 'sku' ] ) ) { |
|
| 178 | + $product_id = (int) wc_get_product_id_by_sku( $posted[ 'sku' ] ); |
|
| 179 | + } elseif ( ! empty( $posted[ 'product_id' ] ) && empty( $posted[ 'variation_id' ] ) ) { |
|
| 180 | + $product_id = (int) $posted[ 'product_id' ]; |
|
| 181 | + } elseif ( ! empty( $posted[ 'variation_id' ] ) ) { |
|
| 182 | + $product_id = (int) $posted[ 'variation_id' ]; |
|
| 183 | 183 | } else { |
| 184 | 184 | throw new \WC_REST_Exception( 'woocommerce_rest_required_product_reference', __( 'Product ID or SKU is required.', 'woocommerce' ), 400 ); |
| 185 | 185 | } |
@@ -196,14 +196,14 @@ discard block |
||
| 196 | 196 | * @throws \WC_REST_Exception Invalid data, server error. |
| 197 | 197 | */ |
| 198 | 198 | protected function prepare_line_items( $posted, $action = 'create', $item = null ) { |
| 199 | - $item = is_null( $item ) ? new \WC_Order_Item_Product( ! empty( $posted['id'] ) ? $posted['id'] : '' ) : $item; |
|
| 199 | + $item = is_null( $item ) ? new \WC_Order_Item_Product( ! empty( $posted[ 'id' ] ) ? $posted[ 'id' ] : '' ) : $item; |
|
| 200 | 200 | $product = wc_get_product( $this->get_product_id_from_line_item( $posted ) ); |
| 201 | 201 | |
| 202 | 202 | if ( $product !== $item->get_product() ) { |
| 203 | 203 | $item->set_product( $product ); |
| 204 | 204 | |
| 205 | 205 | if ( 'create' === $action ) { |
| 206 | - $quantity = isset( $posted['quantity'] ) ? $posted['quantity'] : 1; |
|
| 206 | + $quantity = isset( $posted[ 'quantity' ] ) ? $posted[ 'quantity' ] : 1; |
|
| 207 | 207 | $total = wc_get_price_excluding_tax( $product, array( 'qty' => $quantity ) ); |
| 208 | 208 | $item->set_total( $total ); |
| 209 | 209 | $item->set_subtotal( $total ); |
@@ -226,10 +226,10 @@ discard block |
||
| 226 | 226 | * @throws \WC_REST_Exception Invalid data, server error. |
| 227 | 227 | */ |
| 228 | 228 | protected function prepare_shipping_lines( $posted, $action = 'create', $item = null ) { |
| 229 | - $item = is_null( $item ) ? new \WC_Order_Item_Shipping( ! empty( $posted['id'] ) ? $posted['id'] : '' ) : $item; |
|
| 229 | + $item = is_null( $item ) ? new \WC_Order_Item_Shipping( ! empty( $posted[ 'id' ] ) ? $posted[ 'id' ] : '' ) : $item; |
|
| 230 | 230 | |
| 231 | 231 | if ( 'create' === $action ) { |
| 232 | - if ( empty( $posted['method_id'] ) ) { |
|
| 232 | + if ( empty( $posted[ 'method_id' ] ) ) { |
|
| 233 | 233 | throw new \WC_REST_Exception( 'woocommerce_rest_invalid_shipping_item', __( 'Shipping method ID is required.', 'woocommerce' ), 400 ); |
| 234 | 234 | } |
| 235 | 235 | } |
@@ -250,10 +250,10 @@ discard block |
||
| 250 | 250 | * @throws \WC_REST_Exception Invalid data, server error. |
| 251 | 251 | */ |
| 252 | 252 | protected function prepare_fee_lines( $posted, $action = 'create', $item = null ) { |
| 253 | - $item = is_null( $item ) ? new \WC_Order_Item_Fee( ! empty( $posted['id'] ) ? $posted['id'] : '' ) : $item; |
|
| 253 | + $item = is_null( $item ) ? new \WC_Order_Item_Fee( ! empty( $posted[ 'id' ] ) ? $posted[ 'id' ] : '' ) : $item; |
|
| 254 | 254 | |
| 255 | 255 | if ( 'create' === $action ) { |
| 256 | - if ( empty( $posted['name'] ) ) { |
|
| 256 | + if ( empty( $posted[ 'name' ] ) ) { |
|
| 257 | 257 | throw new \WC_REST_Exception( 'woocommerce_rest_invalid_fee_item', __( 'Fee name is required.', 'woocommerce' ), 400 ); |
| 258 | 258 | } |
| 259 | 259 | } |
@@ -275,7 +275,7 @@ discard block |
||
| 275 | 275 | * @throws \WC_REST_Exception If item ID is not associated with order. |
| 276 | 276 | */ |
| 277 | 277 | protected function set_item( &$order, $item_type, $posted ) { |
| 278 | - if ( ! empty( $posted['id'] ) ) { |
|
| 278 | + if ( ! empty( $posted[ 'id' ] ) ) { |
|
| 279 | 279 | $action = 'update'; |
| 280 | 280 | } else { |
| 281 | 281 | $action = 'create'; |
@@ -286,7 +286,7 @@ discard block |
||
| 286 | 286 | |
| 287 | 287 | // Verify provided line item ID is associated with order. |
| 288 | 288 | if ( 'update' === $action ) { |
| 289 | - $item = $order->get_item( absint( $posted['id'] ), false ); |
|
| 289 | + $item = $order->get_item( absint( $posted[ 'id' ] ), false ); |
|
| 290 | 290 | |
| 291 | 291 | if ( ! $item ) { |
| 292 | 292 | throw new \WC_REST_Exception( 'woocommerce_rest_invalid_item_id', __( 'Order item ID provided is not associated with order.', 'woocommerce' ), 400 ); |
@@ -315,7 +315,7 @@ discard block |
||
| 315 | 315 | * @return array |
| 316 | 316 | */ |
| 317 | 317 | protected function parse_address_field( $data, $object, $type = 'billing' ) { |
| 318 | - $address = []; |
|
| 318 | + $address = [ ]; |
|
| 319 | 319 | foreach ( $data as $key => $value ) { |
| 320 | 320 | if ( is_callable( array( $object, "set_{$type}_{$key}" ) ) ) { |
| 321 | 321 | $address[ "{$type}_{$key}" ] = $value; |
@@ -368,12 +368,12 @@ discard block |
||
| 368 | 368 | |
| 369 | 369 | foreach ( $coupon_lines as $item ) { |
| 370 | 370 | if ( is_array( $item ) ) { |
| 371 | - if ( empty( $item['id'] ) ) { |
|
| 372 | - if ( empty( $item['code'] ) ) { |
|
| 371 | + if ( empty( $item[ 'id' ] ) ) { |
|
| 372 | + if ( empty( $item[ 'code' ] ) ) { |
|
| 373 | 373 | throw new \WC_REST_Exception( 'woocommerce_rest_invalid_coupon', __( 'Coupon code is required.', 'woocommerce' ), 400 ); |
| 374 | 374 | } |
| 375 | 375 | |
| 376 | - $results = $order->apply_coupon( wc_clean( $item['code'] ) ); |
|
| 376 | + $results = $order->apply_coupon( wc_clean( $item[ 'code' ] ) ); |
|
| 377 | 377 | |
| 378 | 378 | if ( is_wp_error( $results ) ) { |
| 379 | 379 | throw new \WC_REST_Exception( 'woocommerce_rest_' . $results->get_error_code(), $results->get_error_message(), 400 ); |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | ]; |
| 55 | 55 | |
| 56 | 56 | $request_props = array_intersect_key( $this->request, array_flip( $props ) ); |
| 57 | - $prop_values = []; |
|
| 57 | + $prop_values = [ ]; |
|
| 58 | 58 | |
| 59 | 59 | foreach ( $request_props as $prop => $value ) { |
| 60 | 60 | switch ( $prop ) { |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | * @return array |
| 95 | 95 | */ |
| 96 | 96 | protected function parse_address_field( $data, $object, $type = 'billing' ) { |
| 97 | - $address = []; |
|
| 97 | + $address = [ ]; |
|
| 98 | 98 | foreach ( $data as $key => $value ) { |
| 99 | 99 | if ( is_callable( array( $object, "set_{$type}_{$key}" ) ) ) { |
| 100 | 100 | $address[ "{$type}_{$key}" ] = $value; |