@@ -55,11 +55,11 @@ discard block |
||
55 | 55 | * @param array $methods Supported methods. read, create. |
56 | 56 | */ |
57 | 57 | protected function register_items_route( $methods = [ 'read', 'create' ] ) { |
58 | - $routes = []; |
|
59 | - $routes['schema'] = [ $this, 'get_public_item_schema' ]; |
|
58 | + $routes = [ ]; |
|
59 | + $routes[ 'schema' ] = [ $this, 'get_public_item_schema' ]; |
|
60 | 60 | |
61 | 61 | if ( in_array( 'read', $methods, true ) ) { |
62 | - $routes[] = array( |
|
62 | + $routes[ ] = array( |
|
63 | 63 | 'methods' => \WP_REST_Server::READABLE, |
64 | 64 | 'callback' => array( $this, 'get_items' ), |
65 | 65 | 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | } |
69 | 69 | |
70 | 70 | if ( in_array( 'create', $methods, true ) ) { |
71 | - $routes[] = array( |
|
71 | + $routes[ ] = array( |
|
72 | 72 | 'methods' => \WP_REST_Server::CREATABLE, |
73 | 73 | 'callback' => array( $this, 'create_item' ), |
74 | 74 | 'permission_callback' => array( $this, 'create_item_permissions_check' ), |
@@ -90,9 +90,9 @@ discard block |
||
90 | 90 | * @param array $methods Supported methods. read, create. |
91 | 91 | */ |
92 | 92 | protected function register_item_route( $methods = [ 'read', 'edit', 'delete' ] ) { |
93 | - $routes = []; |
|
94 | - $routes['schema'] = [ $this, 'get_public_item_schema' ]; |
|
95 | - $routes['args'] = [ |
|
93 | + $routes = [ ]; |
|
94 | + $routes[ 'schema' ] = [ $this, 'get_public_item_schema' ]; |
|
95 | + $routes[ 'args' ] = [ |
|
96 | 96 | 'id' => [ |
97 | 97 | 'description' => __( 'Unique identifier for the resource.', 'woocommerce-rest-api' ), |
98 | 98 | 'type' => 'integer', |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | ]; |
101 | 101 | |
102 | 102 | if ( in_array( 'read', $methods, true ) ) { |
103 | - $routes[] = array( |
|
103 | + $routes[ ] = array( |
|
104 | 104 | 'methods' => \WP_REST_Server::READABLE, |
105 | 105 | 'callback' => array( $this, 'get_item' ), |
106 | 106 | 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | } |
116 | 116 | |
117 | 117 | if ( in_array( 'edit', $methods, true ) ) { |
118 | - $routes[] = array( |
|
118 | + $routes[ ] = array( |
|
119 | 119 | 'methods' => \WP_REST_Server::EDITABLE, |
120 | 120 | 'callback' => array( $this, 'update_item' ), |
121 | 121 | 'permission_callback' => array( $this, 'update_item_permissions_check' ), |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | } |
125 | 125 | |
126 | 126 | if ( in_array( 'delete', $methods, true ) ) { |
127 | - $routes[] = array( |
|
127 | + $routes[ ] = array( |
|
128 | 128 | 'methods' => \WP_REST_Server::DELETABLE, |
129 | 129 | 'callback' => array( $this, 'delete_item' ), |
130 | 130 | 'permission_callback' => array( $this, 'delete_item_permissions_check' ), |
@@ -154,8 +154,8 @@ discard block |
||
154 | 154 | */ |
155 | 155 | protected function add_additional_fields_schema( $schema ) { |
156 | 156 | $schema = parent::add_additional_fields_schema( $schema ); |
157 | - $object_type = $schema['title']; |
|
158 | - $schema['properties'] = apply_filters( 'woocommerce_rest_' . $object_type . '_schema', $schema['properties'] ); |
|
157 | + $object_type = $schema[ 'title' ]; |
|
158 | + $schema[ 'properties' ] = apply_filters( 'woocommerce_rest_' . $object_type . '_schema', $schema[ 'properties' ] ); |
|
159 | 159 | return $schema; |
160 | 160 | } |
161 | 161 | |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | * @return string |
272 | 272 | */ |
273 | 273 | protected function get_request_context( $request ) { |
274 | - return ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
274 | + return ! empty( $request[ 'context' ] ) ? $request[ 'context' ] : 'view'; |
|
275 | 275 | } |
276 | 276 | |
277 | 277 | /** |
@@ -312,7 +312,7 @@ discard block |
||
312 | 312 | */ |
313 | 313 | protected function get_item_title() { |
314 | 314 | $schema = $this->get_item_schema(); |
315 | - return $schema['title']; |
|
315 | + return $schema[ 'title' ]; |
|
316 | 316 | } |
317 | 317 | |
318 | 318 | /** |
@@ -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-rest-api' ), 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-rest-api' ), 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-rest-api' ), 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-rest-api' ), 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-rest-api' ), 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 ); |
@@ -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-rest-api' ), 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-rest-api' ), 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-rest-api' ) ); |
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-rest-api' ) ); |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | foreach ( $wc_shipping->get_shipping_methods() as $id => $shipping_method ) { |
85 | 85 | $method = $this->prepare_item_for_response( $shipping_method, $request ); |
86 | 86 | $method = $this->prepare_response_for_collection( $method ); |
87 | - $response[] = $method; |
|
87 | + $response[ ] = $method; |
|
88 | 88 | } |
89 | 89 | return rest_ensure_response( $response ); |
90 | 90 | } |
@@ -98,11 +98,11 @@ discard block |
||
98 | 98 | public function get_item( $request ) { |
99 | 99 | $wc_shipping = \WC_Shipping::instance(); |
100 | 100 | $methods = $wc_shipping->get_shipping_methods(); |
101 | - if ( empty( $methods[ $request['id'] ] ) ) { |
|
101 | + if ( empty( $methods[ $request[ 'id' ] ] ) ) { |
|
102 | 102 | return new \WP_Error( 'woocommerce_rest_shipping_method_invalid', __( 'Resource does not exist.', 'woocommerce-rest-api' ), array( 'status' => 404 ) ); |
103 | 103 | } |
104 | 104 | |
105 | - $method = $methods[ $request['id'] ]; |
|
105 | + $method = $methods[ $request[ 'id' ] ]; |
|
106 | 106 | $response = $this->prepare_item_for_response( $method, $request ); |
107 | 107 | |
108 | 108 | return rest_ensure_response( $response ); |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | * @return \WP_Error|boolean |
120 | 120 | */ |
121 | 121 | public function get_item_permissions_check( $request ) { |
122 | - $order = wc_get_order( (int) $request['order_id'] ); |
|
122 | + $order = wc_get_order( (int) $request[ 'order_id' ] ); |
|
123 | 123 | |
124 | 124 | if ( $order && ! Permissions::user_can_read( $this->post_type, $order->get_id() ) ) { |
125 | 125 | return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce-rest-api' ), array( 'status' => rest_authorization_required_code() ) ); |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | * @return bool|\WP_Error |
137 | 137 | */ |
138 | 138 | public function delete_item_permissions_check( $request ) { |
139 | - $order = wc_get_order( (int) $request['order_id'] ); |
|
139 | + $order = wc_get_order( (int) $request[ 'order_id' ] ); |
|
140 | 140 | |
141 | 141 | if ( $order && ! Permissions::user_can_delete( $this->post_type, $order->get_id() ) ) { |
142 | 142 | return new \WP_Error( 'woocommerce_rest_cannot_delete', __( 'Sorry, you are not allowed to delete this resource.', 'woocommerce-rest-api' ), array( 'status' => rest_authorization_required_code() ) ); |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | * @return array|\WP_Error |
154 | 154 | */ |
155 | 155 | public function get_items( $request ) { |
156 | - $order = wc_get_order( (int) $request['order_id'] ); |
|
156 | + $order = wc_get_order( (int) $request[ 'order_id' ] ); |
|
157 | 157 | |
158 | 158 | if ( ! $order || $this->post_type !== $order->get_type() ) { |
159 | 159 | return new \WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'Invalid order ID.', 'woocommerce-rest-api' ), array( 'status' => 404 ) ); |
@@ -166,16 +166,16 @@ discard block |
||
166 | 166 | ); |
167 | 167 | |
168 | 168 | // Allow filter by order note type. |
169 | - if ( 'customer' === $request['type'] ) { |
|
170 | - $args['meta_query'] = array( // WPCS: slow query ok. |
|
169 | + if ( 'customer' === $request[ 'type' ] ) { |
|
170 | + $args[ 'meta_query' ] = array( // WPCS: slow query ok. |
|
171 | 171 | array( |
172 | 172 | 'key' => 'is_customer_note', |
173 | 173 | 'value' => 1, |
174 | 174 | 'compare' => '=', |
175 | 175 | ), |
176 | 176 | ); |
177 | - } elseif ( 'internal' === $request['type'] ) { |
|
178 | - $args['meta_query'] = array( // WPCS: slow query ok. |
|
177 | + } elseif ( 'internal' === $request[ 'type' ] ) { |
|
178 | + $args[ 'meta_query' ] = array( // WPCS: slow query ok. |
|
179 | 179 | array( |
180 | 180 | 'key' => 'is_customer_note', |
181 | 181 | 'compare' => 'NOT EXISTS', |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | foreach ( $notes as $note ) { |
194 | 194 | $order_note = $this->prepare_item_for_response( $note, $request ); |
195 | 195 | $order_note = $this->prepare_response_for_collection( $order_note ); |
196 | - $data[] = $order_note; |
|
196 | + $data[ ] = $order_note; |
|
197 | 197 | } |
198 | 198 | |
199 | 199 | return rest_ensure_response( $data ); |
@@ -206,19 +206,19 @@ discard block |
||
206 | 206 | * @return \WP_Error|\WP_REST_Response |
207 | 207 | */ |
208 | 208 | public function create_item( $request ) { |
209 | - if ( ! empty( $request['id'] ) ) { |
|
209 | + if ( ! empty( $request[ 'id' ] ) ) { |
|
210 | 210 | /* translators: %s: post type */ |
211 | 211 | return new \WP_Error( "woocommerce_rest_{$this->post_type}_exists", sprintf( __( 'Cannot create existing %s.', 'woocommerce-rest-api' ), $this->post_type ), array( 'status' => 400 ) ); |
212 | 212 | } |
213 | 213 | |
214 | - $order = wc_get_order( (int) $request['order_id'] ); |
|
214 | + $order = wc_get_order( (int) $request[ 'order_id' ] ); |
|
215 | 215 | |
216 | 216 | if ( ! $order || $this->post_type !== $order->get_type() ) { |
217 | 217 | return new \WP_Error( 'woocommerce_rest_order_invalid_id', __( 'Invalid order ID.', 'woocommerce-rest-api' ), array( 'status' => 404 ) ); |
218 | 218 | } |
219 | 219 | |
220 | 220 | // Create the note. |
221 | - $note_id = $order->add_order_note( $request['note'], $request['customer_note'], $request['added_by_user'] ); |
|
221 | + $note_id = $order->add_order_note( $request[ 'note' ], $request[ 'customer_note' ], $request[ 'added_by_user' ] ); |
|
222 | 222 | |
223 | 223 | if ( ! $note_id ) { |
224 | 224 | return new \WP_Error( 'woocommerce_api_cannot_create_order_note', __( 'Cannot create order note, please try again.', 'woocommerce-rest-api' ), array( 'status' => 500 ) ); |
@@ -252,8 +252,8 @@ discard block |
||
252 | 252 | * @return \WP_Error|\WP_REST_Response |
253 | 253 | */ |
254 | 254 | public function get_item( $request ) { |
255 | - $id = (int) $request['id']; |
|
256 | - $order = wc_get_order( (int) $request['order_id'] ); |
|
255 | + $id = (int) $request[ 'id' ]; |
|
256 | + $order = wc_get_order( (int) $request[ 'order_id' ] ); |
|
257 | 257 | |
258 | 258 | if ( ! $order || $this->post_type !== $order->get_type() ) { |
259 | 259 | return new \WP_Error( 'woocommerce_rest_order_invalid_id', __( 'Invalid order ID.', 'woocommerce-rest-api' ), array( 'status' => 404 ) ); |
@@ -278,15 +278,15 @@ discard block |
||
278 | 278 | * @return \WP_REST_Response|\WP_Error |
279 | 279 | */ |
280 | 280 | public function delete_item( $request ) { |
281 | - $id = (int) $request['id']; |
|
282 | - $force = isset( $request['force'] ) ? (bool) $request['force'] : false; |
|
281 | + $id = (int) $request[ 'id' ]; |
|
282 | + $force = isset( $request[ 'force' ] ) ? (bool) $request[ 'force' ] : false; |
|
283 | 283 | |
284 | 284 | // We don't support trashing for this type, error out. |
285 | 285 | if ( ! $force ) { |
286 | 286 | return new \WP_Error( 'woocommerce_rest_trash_not_supported', __( 'Webhooks do not support trashing.', 'woocommerce-rest-api' ), array( 'status' => 501 ) ); |
287 | 287 | } |
288 | 288 | |
289 | - $order = wc_get_order( (int) $request['order_id'] ); |
|
289 | + $order = wc_get_order( (int) $request[ 'order_id' ] ); |
|
290 | 290 | |
291 | 291 | if ( ! $order || $this->post_type !== $order->get_type() ) { |
292 | 292 | return new \WP_Error( 'woocommerce_rest_order_invalid_id', __( 'Invalid order ID.', 'woocommerce-rest-api' ), array( 'status' => 404 ) ); |
@@ -434,8 +434,8 @@ discard block |
||
434 | 434 | */ |
435 | 435 | public function get_collection_params() { |
436 | 436 | $params = array(); |
437 | - $params['context'] = $this->get_context_param( array( 'default' => 'view' ) ); |
|
438 | - $params['type'] = array( |
|
437 | + $params[ 'context' ] = $this->get_context_param( array( 'default' => 'view' ) ); |
|
438 | + $params[ 'type' ] = array( |
|
439 | 439 | 'default' => 'any', |
440 | 440 | 'description' => __( 'Limit result to customers or internal notes.', 'woocommerce-rest-api' ), |
441 | 441 | 'type' => 'string', |
@@ -176,29 +176,29 @@ discard block |
||
176 | 176 | } |
177 | 177 | } |
178 | 178 | |
179 | - if ( isset( $registered['orderby'] ) ) { |
|
180 | - $prepared_args['orderby'] = $this->normalize_query_param( $request['orderby'] ); |
|
179 | + if ( isset( $registered[ 'orderby' ] ) ) { |
|
180 | + $prepared_args[ 'orderby' ] = $this->normalize_query_param( $request[ 'orderby' ] ); |
|
181 | 181 | } |
182 | 182 | |
183 | - if ( isset( $prepared_args['status'] ) ) { |
|
184 | - $prepared_args['status'] = 'approved' === $prepared_args['status'] ? 'approve' : $prepared_args['status']; |
|
183 | + if ( isset( $prepared_args[ 'status' ] ) ) { |
|
184 | + $prepared_args[ 'status' ] = 'approved' === $prepared_args[ 'status' ] ? 'approve' : $prepared_args[ 'status' ]; |
|
185 | 185 | } |
186 | 186 | |
187 | - $prepared_args['no_found_rows'] = false; |
|
188 | - $prepared_args['date_query'] = array(); |
|
187 | + $prepared_args[ 'no_found_rows' ] = false; |
|
188 | + $prepared_args[ 'date_query' ] = array(); |
|
189 | 189 | |
190 | 190 | // Set before into date query. Date query must be specified as an array of an array. |
191 | - if ( isset( $registered['before'], $request['before'] ) ) { |
|
192 | - $prepared_args['date_query'][0]['before'] = $request['before']; |
|
191 | + if ( isset( $registered[ 'before' ], $request[ 'before' ] ) ) { |
|
192 | + $prepared_args[ 'date_query' ][ 0 ][ 'before' ] = $request[ 'before' ]; |
|
193 | 193 | } |
194 | 194 | |
195 | 195 | // Set after into date query. Date query must be specified as an array of an array. |
196 | - if ( isset( $registered['after'], $request['after'] ) ) { |
|
197 | - $prepared_args['date_query'][0]['after'] = $request['after']; |
|
196 | + if ( isset( $registered[ 'after' ], $request[ 'after' ] ) ) { |
|
197 | + $prepared_args[ 'date_query' ][ 0 ][ 'after' ] = $request[ 'after' ]; |
|
198 | 198 | } |
199 | 199 | |
200 | - if ( isset( $registered['page'] ) && empty( $request['offset'] ) ) { |
|
201 | - $prepared_args['offset'] = $prepared_args['number'] * ( absint( $request['page'] ) - 1 ); |
|
200 | + if ( isset( $registered[ 'page' ] ) && empty( $request[ 'offset' ] ) ) { |
|
201 | + $prepared_args[ 'offset' ] = $prepared_args[ 'number' ] * ( absint( $request[ 'page' ] ) - 1 ); |
|
202 | 202 | } |
203 | 203 | |
204 | 204 | /** |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | $prepared_args = apply_filters( 'woocommerce_rest_product_review_query', $prepared_args, $request ); |
213 | 213 | |
214 | 214 | // Make sure that returns only reviews. |
215 | - $prepared_args['type'] = 'review'; |
|
215 | + $prepared_args[ 'type' ] = 'review'; |
|
216 | 216 | |
217 | 217 | // Query reviews. |
218 | 218 | $query = new \WP_Comment_Query(); |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | } |
226 | 226 | |
227 | 227 | $data = $this->prepare_item_for_response( $review, $request ); |
228 | - $reviews[] = $this->prepare_response_for_collection( $data ); |
|
228 | + $reviews[ ] = $this->prepare_response_for_collection( $data ); |
|
229 | 229 | } |
230 | 230 | |
231 | 231 | $total_reviews = (int) $query->found_comments; |
@@ -233,13 +233,13 @@ discard block |
||
233 | 233 | |
234 | 234 | if ( $total_reviews < 1 ) { |
235 | 235 | // Out-of-bounds, run the query again without LIMIT for total count. |
236 | - unset( $prepared_args['number'], $prepared_args['offset'] ); |
|
236 | + unset( $prepared_args[ 'number' ], $prepared_args[ 'offset' ] ); |
|
237 | 237 | |
238 | 238 | $query = new \WP_Comment_Query(); |
239 | - $prepared_args['count'] = true; |
|
239 | + $prepared_args[ 'count' ] = true; |
|
240 | 240 | |
241 | 241 | $total_reviews = $query->query( $prepared_args ); |
242 | - $max_pages = ceil( $total_reviews / $request['per_page'] ); |
|
242 | + $max_pages = ceil( $total_reviews / $request[ 'per_page' ] ); |
|
243 | 243 | } |
244 | 244 | |
245 | 245 | $response = rest_ensure_response( $reviews ); |
@@ -255,11 +255,11 @@ discard block |
||
255 | 255 | * @return \WP_Error|\WP_REST_Response |
256 | 256 | */ |
257 | 257 | public function create_item( $request ) { |
258 | - if ( ! empty( $request['id'] ) ) { |
|
258 | + if ( ! empty( $request[ 'id' ] ) ) { |
|
259 | 259 | return new \WP_Error( 'woocommerce_rest_review_exists', __( 'Cannot create existing product review.', 'woocommerce-rest-api' ), array( 'status' => 400 ) ); |
260 | 260 | } |
261 | 261 | |
262 | - $product_id = (int) $request['product_id']; |
|
262 | + $product_id = (int) $request[ 'product_id' ]; |
|
263 | 263 | |
264 | 264 | if ( 'product' !== get_post_type( $product_id ) ) { |
265 | 265 | return new \WP_Error( 'woocommerce_rest_product_invalid_id', __( 'Invalid product ID.', 'woocommerce-rest-api' ), array( 'status' => 404 ) ); |
@@ -270,32 +270,32 @@ discard block |
||
270 | 270 | return $prepared_review; |
271 | 271 | } |
272 | 272 | |
273 | - $prepared_review['comment_type'] = 'review'; |
|
273 | + $prepared_review[ 'comment_type' ] = 'review'; |
|
274 | 274 | |
275 | 275 | /* |
276 | 276 | * Do not allow a comment to be created with missing or empty comment_content. See wp_handle_comment_submission(). |
277 | 277 | */ |
278 | - if ( empty( $prepared_review['comment_content'] ) ) { |
|
278 | + if ( empty( $prepared_review[ 'comment_content' ] ) ) { |
|
279 | 279 | return new \WP_Error( 'woocommerce_rest_review_content_invalid', __( 'Invalid review content.', 'woocommerce-rest-api' ), array( 'status' => 400 ) ); |
280 | 280 | } |
281 | 281 | |
282 | 282 | // Setting remaining values before wp_insert_comment so we can use wp_allow_comment(). |
283 | - if ( ! isset( $prepared_review['comment_date_gmt'] ) ) { |
|
284 | - $prepared_review['comment_date_gmt'] = current_time( 'mysql', true ); |
|
283 | + if ( ! isset( $prepared_review[ 'comment_date_gmt' ] ) ) { |
|
284 | + $prepared_review[ 'comment_date_gmt' ] = current_time( 'mysql', true ); |
|
285 | 285 | } |
286 | 286 | |
287 | - if ( ! empty( $_SERVER['REMOTE_ADDR'] ) && rest_is_ip_address( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) ) { // WPCS: input var ok, sanitization ok. |
|
288 | - $prepared_review['comment_author_IP'] = wc_clean( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ); // WPCS: input var ok. |
|
287 | + if ( ! empty( $_SERVER[ 'REMOTE_ADDR' ] ) && rest_is_ip_address( wp_unslash( $_SERVER[ 'REMOTE_ADDR' ] ) ) ) { // WPCS: input var ok, sanitization ok. |
|
288 | + $prepared_review[ 'comment_author_IP' ] = wc_clean( wp_unslash( $_SERVER[ 'REMOTE_ADDR' ] ) ); // WPCS: input var ok. |
|
289 | 289 | } else { |
290 | - $prepared_review['comment_author_IP'] = '127.0.0.1'; |
|
290 | + $prepared_review[ 'comment_author_IP' ] = '127.0.0.1'; |
|
291 | 291 | } |
292 | 292 | |
293 | - if ( ! empty( $request['author_user_agent'] ) ) { |
|
294 | - $prepared_review['comment_agent'] = $request['author_user_agent']; |
|
293 | + if ( ! empty( $request[ 'author_user_agent' ] ) ) { |
|
294 | + $prepared_review[ 'comment_agent' ] = $request[ 'author_user_agent' ]; |
|
295 | 295 | } elseif ( $request->get_header( 'user_agent' ) ) { |
296 | - $prepared_review['comment_agent'] = $request->get_header( 'user_agent' ); |
|
296 | + $prepared_review[ 'comment_agent' ] = $request->get_header( 'user_agent' ); |
|
297 | 297 | } else { |
298 | - $prepared_review['comment_agent'] = ''; |
|
298 | + $prepared_review[ 'comment_agent' ] = ''; |
|
299 | 299 | } |
300 | 300 | |
301 | 301 | $check_comment_lengths = wp_check_comment_data_max_lengths( $prepared_review ); |
@@ -304,13 +304,13 @@ discard block |
||
304 | 304 | return new \WP_Error( 'woocommerce_rest_' . $error_code, __( 'Product review field exceeds maximum length allowed.', 'woocommerce-rest-api' ), array( 'status' => 400 ) ); |
305 | 305 | } |
306 | 306 | |
307 | - $prepared_review['comment_parent'] = 0; |
|
308 | - $prepared_review['comment_author_url'] = ''; |
|
309 | - $prepared_review['comment_approved'] = wp_allow_comment( $prepared_review, true ); |
|
307 | + $prepared_review[ 'comment_parent' ] = 0; |
|
308 | + $prepared_review[ 'comment_author_url' ] = ''; |
|
309 | + $prepared_review[ 'comment_approved' ] = wp_allow_comment( $prepared_review, true ); |
|
310 | 310 | |
311 | - if ( is_wp_error( $prepared_review['comment_approved'] ) ) { |
|
312 | - $error_code = $prepared_review['comment_approved']->get_error_code(); |
|
313 | - $error_message = $prepared_review['comment_approved']->get_error_message(); |
|
311 | + if ( is_wp_error( $prepared_review[ 'comment_approved' ] ) ) { |
|
312 | + $error_code = $prepared_review[ 'comment_approved' ]->get_error_code(); |
|
313 | + $error_message = $prepared_review[ 'comment_approved' ]->get_error_message(); |
|
314 | 314 | |
315 | 315 | if ( 'comment_duplicate' === $error_code ) { |
316 | 316 | return new \WP_Error( 'woocommerce_rest_' . $error_code, $error_message, array( 'status' => 409 ) ); |
@@ -320,7 +320,7 @@ discard block |
||
320 | 320 | return new \WP_Error( 'woocommerce_rest_' . $error_code, $error_message, array( 'status' => 400 ) ); |
321 | 321 | } |
322 | 322 | |
323 | - return $prepared_review['comment_approved']; |
|
323 | + return $prepared_review[ 'comment_approved' ]; |
|
324 | 324 | } |
325 | 325 | |
326 | 326 | /** |
@@ -345,11 +345,11 @@ discard block |
||
345 | 345 | return new \WP_Error( 'woocommerce_rest_review_failed_create', __( 'Creating product review failed.', 'woocommerce-rest-api' ), array( 'status' => 500 ) ); |
346 | 346 | } |
347 | 347 | |
348 | - if ( isset( $request['status'] ) ) { |
|
349 | - $this->handle_status_param( $request['status'], $review_id ); |
|
348 | + if ( isset( $request[ 'status' ] ) ) { |
|
349 | + $this->handle_status_param( $request[ 'status' ], $review_id ); |
|
350 | 350 | } |
351 | 351 | |
352 | - update_comment_meta( $review_id, 'rating', ! empty( $request['rating'] ) ? $request['rating'] : '0' ); |
|
352 | + update_comment_meta( $review_id, 'rating', ! empty( $request[ 'rating' ] ) ? $request[ 'rating' ] : '0' ); |
|
353 | 353 | |
354 | 354 | $review = get_comment( $review_id ); |
355 | 355 | |
@@ -385,7 +385,7 @@ discard block |
||
385 | 385 | * @return \WP_Error|\WP_REST_Response |
386 | 386 | */ |
387 | 387 | public function get_item( $request ) { |
388 | - $review = $this->get_review( $request['id'] ); |
|
388 | + $review = $this->get_review( $request[ 'id' ] ); |
|
389 | 389 | if ( is_wp_error( $review ) ) { |
390 | 390 | return $review; |
391 | 391 | } |
@@ -400,14 +400,14 @@ discard block |
||
400 | 400 | * @return \WP_Error|\WP_REST_Response Response object on success, or error object on failure. |
401 | 401 | */ |
402 | 402 | public function update_item( $request ) { |
403 | - $review = $this->get_review( $request['id'] ); |
|
403 | + $review = $this->get_review( $request[ 'id' ] ); |
|
404 | 404 | if ( is_wp_error( $review ) ) { |
405 | 405 | return $review; |
406 | 406 | } |
407 | 407 | |
408 | 408 | $id = (int) $review->comment_ID; |
409 | 409 | |
410 | - if ( isset( $request['type'] ) && 'review' !== get_comment_type( $id ) ) { |
|
410 | + if ( isset( $request[ 'type' ] ) && 'review' !== get_comment_type( $id ) ) { |
|
411 | 411 | return new \WP_Error( 'woocommerce_rest_review_invalid_type', __( 'Sorry, you are not allowed to change the comment type.', 'woocommerce-rest-api' ), array( 'status' => 404 ) ); |
412 | 412 | } |
413 | 413 | |
@@ -416,15 +416,15 @@ discard block |
||
416 | 416 | return $prepared_args; |
417 | 417 | } |
418 | 418 | |
419 | - if ( ! empty( $prepared_args['comment_post_ID'] ) ) { |
|
420 | - if ( 'product' !== get_post_type( (int) $prepared_args['comment_post_ID'] ) ) { |
|
419 | + if ( ! empty( $prepared_args[ 'comment_post_ID' ] ) ) { |
|
420 | + if ( 'product' !== get_post_type( (int) $prepared_args[ 'comment_post_ID' ] ) ) { |
|
421 | 421 | return new \WP_Error( 'woocommerce_rest_product_invalid_id', __( 'Invalid product ID.', 'woocommerce-rest-api' ), array( 'status' => 404 ) ); |
422 | 422 | } |
423 | 423 | } |
424 | 424 | |
425 | - if ( empty( $prepared_args ) && isset( $request['status'] ) ) { |
|
425 | + if ( empty( $prepared_args ) && isset( $request[ 'status' ] ) ) { |
|
426 | 426 | // Only the comment status is being changed. |
427 | - $change = $this->handle_status_param( $request['status'], $id ); |
|
427 | + $change = $this->handle_status_param( $request[ 'status' ], $id ); |
|
428 | 428 | |
429 | 429 | if ( ! $change ) { |
430 | 430 | return new \WP_Error( 'woocommerce_rest_review_failed_edit', __( 'Updating review status failed.', 'woocommerce-rest-api' ), array( 'status' => 500 ) ); |
@@ -434,11 +434,11 @@ discard block |
||
434 | 434 | return $prepared_args; |
435 | 435 | } |
436 | 436 | |
437 | - if ( isset( $prepared_args['comment_content'] ) && empty( $prepared_args['comment_content'] ) ) { |
|
437 | + if ( isset( $prepared_args[ 'comment_content' ] ) && empty( $prepared_args[ 'comment_content' ] ) ) { |
|
438 | 438 | return new \WP_Error( 'woocommerce_rest_review_content_invalid', __( 'Invalid review content.', 'woocommerce-rest-api' ), array( 'status' => 400 ) ); |
439 | 439 | } |
440 | 440 | |
441 | - $prepared_args['comment_ID'] = $id; |
|
441 | + $prepared_args[ 'comment_ID' ] = $id; |
|
442 | 442 | |
443 | 443 | $check_comment_lengths = wp_check_comment_data_max_lengths( $prepared_args ); |
444 | 444 | if ( is_wp_error( $check_comment_lengths ) ) { |
@@ -452,13 +452,13 @@ discard block |
||
452 | 452 | return new \WP_Error( 'woocommerce_rest_comment_failed_edit', __( 'Updating review failed.', 'woocommerce-rest-api' ), array( 'status' => 500 ) ); |
453 | 453 | } |
454 | 454 | |
455 | - if ( isset( $request['status'] ) ) { |
|
456 | - $this->handle_status_param( $request['status'], $id ); |
|
455 | + if ( isset( $request[ 'status' ] ) ) { |
|
456 | + $this->handle_status_param( $request[ 'status' ], $id ); |
|
457 | 457 | } |
458 | 458 | } |
459 | 459 | |
460 | - if ( ! empty( $request['rating'] ) ) { |
|
461 | - update_comment_meta( $id, 'rating', $request['rating'] ); |
|
460 | + if ( ! empty( $request[ 'rating' ] ) ) { |
|
461 | + update_comment_meta( $id, 'rating', $request[ 'rating' ] ); |
|
462 | 462 | } |
463 | 463 | |
464 | 464 | $review = get_comment( $id ); |
@@ -484,12 +484,12 @@ discard block |
||
484 | 484 | * @return \WP_Error|\WP_REST_Response Response object on success, or error object on failure. |
485 | 485 | */ |
486 | 486 | public function delete_item( $request ) { |
487 | - $review = $this->get_review( $request['id'] ); |
|
487 | + $review = $this->get_review( $request[ 'id' ] ); |
|
488 | 488 | if ( is_wp_error( $review ) ) { |
489 | 489 | return $review; |
490 | 490 | } |
491 | 491 | |
492 | - $force = isset( $request['force'] ) ? (bool) $request['force'] : false; |
|
492 | + $force = isset( $request[ 'force' ] ) ? (bool) $request[ 'force' ] : false; |
|
493 | 493 | |
494 | 494 | /** |
495 | 495 | * Filters whether a review can be trashed. |
@@ -566,37 +566,37 @@ discard block |
||
566 | 566 | * @return array|\WP_Error $prepared_review |
567 | 567 | */ |
568 | 568 | protected function prepare_item_for_database( $request ) { |
569 | - if ( isset( $request['id'] ) ) { |
|
570 | - $prepared_review['comment_ID'] = (int) $request['id']; |
|
569 | + if ( isset( $request[ 'id' ] ) ) { |
|
570 | + $prepared_review[ 'comment_ID' ] = (int) $request[ 'id' ]; |
|
571 | 571 | } |
572 | 572 | |
573 | - if ( isset( $request['review'] ) ) { |
|
574 | - $prepared_review['comment_content'] = $request['review']; |
|
573 | + if ( isset( $request[ 'review' ] ) ) { |
|
574 | + $prepared_review[ 'comment_content' ] = $request[ 'review' ]; |
|
575 | 575 | } |
576 | 576 | |
577 | - if ( isset( $request['product_id'] ) ) { |
|
578 | - $prepared_review['comment_post_ID'] = (int) $request['product_id']; |
|
577 | + if ( isset( $request[ 'product_id' ] ) ) { |
|
578 | + $prepared_review[ 'comment_post_ID' ] = (int) $request[ 'product_id' ]; |
|
579 | 579 | } |
580 | 580 | |
581 | - if ( isset( $request['reviewer'] ) ) { |
|
582 | - $prepared_review['comment_author'] = $request['reviewer']; |
|
581 | + if ( isset( $request[ 'reviewer' ] ) ) { |
|
582 | + $prepared_review[ 'comment_author' ] = $request[ 'reviewer' ]; |
|
583 | 583 | } |
584 | 584 | |
585 | - if ( isset( $request['reviewer_email'] ) ) { |
|
586 | - $prepared_review['comment_author_email'] = $request['reviewer_email']; |
|
585 | + if ( isset( $request[ 'reviewer_email' ] ) ) { |
|
586 | + $prepared_review[ 'comment_author_email' ] = $request[ 'reviewer_email' ]; |
|
587 | 587 | } |
588 | 588 | |
589 | - if ( ! empty( $request['date_created'] ) ) { |
|
590 | - $date_data = rest_get_date_with_gmt( $request['date_created'] ); |
|
589 | + if ( ! empty( $request[ 'date_created' ] ) ) { |
|
590 | + $date_data = rest_get_date_with_gmt( $request[ 'date_created' ] ); |
|
591 | 591 | |
592 | 592 | if ( ! empty( $date_data ) ) { |
593 | - list( $prepared_review['comment_date'], $prepared_review['comment_date_gmt'] ) = $date_data; |
|
593 | + list( $prepared_review[ 'comment_date' ], $prepared_review[ 'comment_date_gmt' ] ) = $date_data; |
|
594 | 594 | } |
595 | - } elseif ( ! empty( $request['date_created_gmt'] ) ) { |
|
596 | - $date_data = rest_get_date_with_gmt( $request['date_created_gmt'], true ); |
|
595 | + } elseif ( ! empty( $request[ 'date_created_gmt' ] ) ) { |
|
596 | + $date_data = rest_get_date_with_gmt( $request[ 'date_created_gmt' ], true ); |
|
597 | 597 | |
598 | 598 | if ( ! empty( $date_data ) ) { |
599 | - list( $prepared_review['comment_date'], $prepared_review['comment_date_gmt'] ) = $date_data; |
|
599 | + list( $prepared_review[ 'comment_date' ], $prepared_review[ 'comment_date_gmt' ] ) = $date_data; |
|
600 | 600 | } |
601 | 601 | } |
602 | 602 | |
@@ -629,13 +629,13 @@ discard block |
||
629 | 629 | ), |
630 | 630 | ); |
631 | 631 | if ( 0 !== (int) $item->comment_post_ID ) { |
632 | - $links['up'] = array( |
|
632 | + $links[ 'up' ] = array( |
|
633 | 633 | 'href' => rest_url( sprintf( '/%s/products/%d', $this->namespace, $item->comment_post_ID ) ), |
634 | 634 | 'embeddable' => true, |
635 | 635 | ); |
636 | 636 | } |
637 | 637 | if ( 0 !== (int) $item->user_id ) { |
638 | - $links['reviewer'] = array( |
|
638 | + $links[ 'reviewer' ] = array( |
|
639 | 639 | 'href' => rest_url( 'wp/v2/users/' . $item->user_id ), |
640 | 640 | 'embeddable' => true, |
641 | 641 | ); |
@@ -730,7 +730,7 @@ discard block |
||
730 | 730 | 'context' => array( 'embed', 'view', 'edit' ), |
731 | 731 | ); |
732 | 732 | } |
733 | - $schema['properties']['reviewer_avatar_urls'] = array( |
|
733 | + $schema[ 'properties' ][ 'reviewer_avatar_urls' ] = array( |
|
734 | 734 | 'description' => __( 'Avatar URLs for the object reviewer.', 'woocommerce-rest-api' ), |
735 | 735 | 'type' => 'object', |
736 | 736 | 'context' => array( 'view', 'edit' ), |
@@ -750,19 +750,19 @@ discard block |
||
750 | 750 | public function get_collection_params() { |
751 | 751 | $params = parent::get_collection_params(); |
752 | 752 | |
753 | - $params['context']['default'] = 'view'; |
|
753 | + $params[ 'context' ][ 'default' ] = 'view'; |
|
754 | 754 | |
755 | - $params['after'] = array( |
|
755 | + $params[ 'after' ] = array( |
|
756 | 756 | 'description' => __( 'Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce-rest-api' ), |
757 | 757 | 'type' => 'string', |
758 | 758 | 'format' => 'date-time', |
759 | 759 | ); |
760 | - $params['before'] = array( |
|
760 | + $params[ 'before' ] = array( |
|
761 | 761 | 'description' => __( 'Limit response to reviews published before a given ISO8601 compliant date.', 'woocommerce-rest-api' ), |
762 | 762 | 'type' => 'string', |
763 | 763 | 'format' => 'date-time', |
764 | 764 | ); |
765 | - $params['exclude'] = array( |
|
765 | + $params[ 'exclude' ] = array( |
|
766 | 766 | 'description' => __( 'Ensure result set excludes specific IDs.', 'woocommerce-rest-api' ), |
767 | 767 | 'type' => 'array', |
768 | 768 | 'items' => array( |
@@ -770,7 +770,7 @@ discard block |
||
770 | 770 | ), |
771 | 771 | 'default' => array(), |
772 | 772 | ); |
773 | - $params['include'] = array( |
|
773 | + $params[ 'include' ] = array( |
|
774 | 774 | 'description' => __( 'Limit result set to specific IDs.', 'woocommerce-rest-api' ), |
775 | 775 | 'type' => 'array', |
776 | 776 | 'items' => array( |
@@ -778,11 +778,11 @@ discard block |
||
778 | 778 | ), |
779 | 779 | 'default' => array(), |
780 | 780 | ); |
781 | - $params['offset'] = array( |
|
781 | + $params[ 'offset' ] = array( |
|
782 | 782 | 'description' => __( 'Offset the result set by a specific number of items.', 'woocommerce-rest-api' ), |
783 | 783 | 'type' => 'integer', |
784 | 784 | ); |
785 | - $params['order'] = array( |
|
785 | + $params[ 'order' ] = array( |
|
786 | 786 | 'description' => __( 'Order sort attribute ascending or descending.', 'woocommerce-rest-api' ), |
787 | 787 | 'type' => 'string', |
788 | 788 | 'default' => 'desc', |
@@ -791,7 +791,7 @@ discard block |
||
791 | 791 | 'desc', |
792 | 792 | ), |
793 | 793 | ); |
794 | - $params['orderby'] = array( |
|
794 | + $params[ 'orderby' ] = array( |
|
795 | 795 | 'description' => __( 'Sort collection by object attribute.', 'woocommerce-rest-api' ), |
796 | 796 | 'type' => 'string', |
797 | 797 | 'default' => 'date_gmt', |
@@ -803,27 +803,27 @@ discard block |
||
803 | 803 | 'product', |
804 | 804 | ), |
805 | 805 | ); |
806 | - $params['reviewer'] = array( |
|
806 | + $params[ 'reviewer' ] = array( |
|
807 | 807 | 'description' => __( 'Limit result set to reviews assigned to specific user IDs.', 'woocommerce-rest-api' ), |
808 | 808 | 'type' => 'array', |
809 | 809 | 'items' => array( |
810 | 810 | 'type' => 'integer', |
811 | 811 | ), |
812 | 812 | ); |
813 | - $params['reviewer_exclude'] = array( |
|
813 | + $params[ 'reviewer_exclude' ] = array( |
|
814 | 814 | 'description' => __( 'Ensure result set excludes reviews assigned to specific user IDs.', 'woocommerce-rest-api' ), |
815 | 815 | 'type' => 'array', |
816 | 816 | 'items' => array( |
817 | 817 | 'type' => 'integer', |
818 | 818 | ), |
819 | 819 | ); |
820 | - $params['reviewer_email'] = array( |
|
820 | + $params[ 'reviewer_email' ] = array( |
|
821 | 821 | 'default' => null, |
822 | 822 | 'description' => __( 'Limit result set to that from a specific author email.', 'woocommerce-rest-api' ), |
823 | 823 | 'format' => 'email', |
824 | 824 | 'type' => 'string', |
825 | 825 | ); |
826 | - $params['product'] = array( |
|
826 | + $params[ 'product' ] = array( |
|
827 | 827 | 'default' => array(), |
828 | 828 | 'description' => __( 'Limit result set to reviews assigned to specific product IDs.', 'woocommerce-rest-api' ), |
829 | 829 | 'type' => 'array', |
@@ -831,7 +831,7 @@ discard block |
||
831 | 831 | 'type' => 'integer', |
832 | 832 | ), |
833 | 833 | ); |
834 | - $params['status'] = array( |
|
834 | + $params[ 'status' ] = array( |
|
835 | 835 | 'default' => 'approved', |
836 | 836 | 'description' => __( 'Limit result set to reviews assigned a specific status.', 'woocommerce-rest-api' ), |
837 | 837 | 'sanitize_callback' => 'sanitize_key', |
@@ -111,21 +111,21 @@ discard block |
||
111 | 111 | global $wpdb; |
112 | 112 | |
113 | 113 | $prepared_args = array(); |
114 | - $prepared_args['order'] = $request['order']; |
|
115 | - $prepared_args['number'] = $request['per_page']; |
|
116 | - if ( ! empty( $request['offset'] ) ) { |
|
117 | - $prepared_args['offset'] = $request['offset']; |
|
114 | + $prepared_args[ 'order' ] = $request[ 'order' ]; |
|
115 | + $prepared_args[ 'number' ] = $request[ 'per_page' ]; |
|
116 | + if ( ! empty( $request[ 'offset' ] ) ) { |
|
117 | + $prepared_args[ 'offset' ] = $request[ 'offset' ]; |
|
118 | 118 | } else { |
119 | - $prepared_args['offset'] = ( $request['page'] - 1 ) * $prepared_args['number']; |
|
119 | + $prepared_args[ 'offset' ] = ( $request[ 'page' ] - 1 ) * $prepared_args[ 'number' ]; |
|
120 | 120 | } |
121 | 121 | $orderby_possibles = array( |
122 | 122 | 'id' => 'tax_rate_id', |
123 | 123 | 'order' => 'tax_rate_order', |
124 | 124 | ); |
125 | - $prepared_args['orderby'] = $orderby_possibles[ $request['orderby'] ]; |
|
126 | - $prepared_args['class'] = $request['class']; |
|
127 | - $prepared_args['code'] = $request['code']; |
|
128 | - $prepared_args['include'] = $request['include']; |
|
125 | + $prepared_args[ 'orderby' ] = $orderby_possibles[ $request[ 'orderby' ] ]; |
|
126 | + $prepared_args[ 'class' ] = $request[ 'class' ]; |
|
127 | + $prepared_args[ 'code' ] = $request[ 'code' ]; |
|
128 | + $prepared_args[ 'include' ] = $request[ 'include' ]; |
|
129 | 129 | |
130 | 130 | /** |
131 | 131 | * Filter arguments, before passing to $wpdb->get_results(), when querying taxes via the REST API. |
@@ -142,13 +142,13 @@ discard block |
||
142 | 142 | "; |
143 | 143 | |
144 | 144 | // Filter by tax class. |
145 | - if ( ! empty( $prepared_args['class'] ) ) { |
|
146 | - $class = 'standard' !== $prepared_args['class'] ? sanitize_title( $prepared_args['class'] ) : ''; |
|
145 | + if ( ! empty( $prepared_args[ 'class' ] ) ) { |
|
146 | + $class = 'standard' !== $prepared_args[ 'class' ] ? sanitize_title( $prepared_args[ 'class' ] ) : ''; |
|
147 | 147 | $query .= " AND tax_rate_class = '$class'"; |
148 | 148 | } |
149 | 149 | |
150 | 150 | // Filter by tax code. |
151 | - $tax_code_search = $prepared_args['code']; |
|
151 | + $tax_code_search = $prepared_args[ 'code' ]; |
|
152 | 152 | if ( $tax_code_search ) { |
153 | 153 | $tax_code_search = $wpdb->esc_like( $tax_code_search ); |
154 | 154 | $tax_code_search = ' \'%' . $tax_code_search . '%\''; |
@@ -156,17 +156,17 @@ discard block |
||
156 | 156 | } |
157 | 157 | |
158 | 158 | // Filter by included tax rate IDs. |
159 | - $included_taxes = $prepared_args['include']; |
|
159 | + $included_taxes = $prepared_args[ 'include' ]; |
|
160 | 160 | if ( ! empty( $included_taxes ) ) { |
161 | - $included_taxes = implode( ',', $prepared_args['include'] ); |
|
161 | + $included_taxes = implode( ',', $prepared_args[ 'include' ] ); |
|
162 | 162 | $query .= " AND tax_rate_id IN ({$included_taxes})"; |
163 | 163 | } |
164 | 164 | |
165 | 165 | // Order tax rates. |
166 | - $order_by = sprintf( ' ORDER BY %s', sanitize_key( $prepared_args['orderby'] ) ); |
|
166 | + $order_by = sprintf( ' ORDER BY %s', sanitize_key( $prepared_args[ 'orderby' ] ) ); |
|
167 | 167 | |
168 | 168 | // Pagination. |
169 | - $pagination = sprintf( ' LIMIT %d, %d', $prepared_args['offset'], $prepared_args['number'] ); |
|
169 | + $pagination = sprintf( ' LIMIT %d, %d', $prepared_args[ 'offset' ], $prepared_args[ 'number' ] ); |
|
170 | 170 | |
171 | 171 | // Query taxes. |
172 | 172 | $results = $wpdb->get_results( $query . $order_by . $pagination ); // @codingStandardsIgnoreLine. |
@@ -174,12 +174,12 @@ discard block |
||
174 | 174 | $taxes = array(); |
175 | 175 | foreach ( $results as $tax ) { |
176 | 176 | $data = $this->prepare_item_for_response( $tax, $request ); |
177 | - $taxes[] = $this->prepare_response_for_collection( $data ); |
|
177 | + $taxes[ ] = $this->prepare_response_for_collection( $data ); |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | // Store pagination values for headers then unset for count query. |
181 | - $per_page = (int) $prepared_args['number']; |
|
182 | - $page = ceil( ( ( (int) $prepared_args['offset'] ) / $per_page ) + 1 ); |
|
181 | + $per_page = (int) $prepared_args[ 'number' ]; |
|
182 | + $page = ceil( ( ( (int) $prepared_args[ 'offset' ] ) / $per_page ) + 1 ); |
|
183 | 183 | |
184 | 184 | // Query only for ids. |
185 | 185 | $wpdb->get_results( str_replace( 'SELECT *', 'SELECT tax_rate_id', $query ) ); // @codingStandardsIgnoreLine. |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | * @return object |
203 | 203 | */ |
204 | 204 | protected function create_or_update_tax( $request, $current = null ) { |
205 | - $id = absint( isset( $request['id'] ) ? $request['id'] : 0 ); |
|
205 | + $id = absint( isset( $request[ 'id' ] ) ? $request[ 'id' ] : 0 ); |
|
206 | 206 | $data = array(); |
207 | 207 | $fields = array( |
208 | 208 | 'tax_rate_country', |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | $data[ $field ] = absint( $request[ $key ] ); |
240 | 240 | break; |
241 | 241 | case 'tax_rate_class': |
242 | - $data[ $field ] = 'standard' !== $request['tax_rate_class'] ? $request['tax_rate_class'] : ''; |
|
242 | + $data[ $field ] = 'standard' !== $request[ 'tax_rate_class' ] ? $request[ 'tax_rate_class' ] : ''; |
|
243 | 243 | break; |
244 | 244 | default: |
245 | 245 | $data[ $field ] = wc_clean( $request[ $key ] ); |
@@ -254,11 +254,11 @@ discard block |
||
254 | 254 | } |
255 | 255 | |
256 | 256 | // Add locales. |
257 | - if ( ! empty( $request['postcode'] ) ) { |
|
258 | - \WC_Tax::_update_tax_rate_postcodes( $id, wc_clean( $request['postcode'] ) ); |
|
257 | + if ( ! empty( $request[ 'postcode' ] ) ) { |
|
258 | + \WC_Tax::_update_tax_rate_postcodes( $id, wc_clean( $request[ 'postcode' ] ) ); |
|
259 | 259 | } |
260 | - if ( ! empty( $request['city'] ) ) { |
|
261 | - \WC_Tax::_update_tax_rate_cities( $id, wc_clean( $request['city'] ) ); |
|
260 | + if ( ! empty( $request[ 'city' ] ) ) { |
|
261 | + \WC_Tax::_update_tax_rate_cities( $id, wc_clean( $request[ 'city' ] ) ); |
|
262 | 262 | } |
263 | 263 | |
264 | 264 | return \WC_Tax::_get_tax_rate( $id, OBJECT ); |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | * @return \WP_Error|\WP_REST_Response |
272 | 272 | */ |
273 | 273 | public function create_item( $request ) { |
274 | - if ( ! empty( $request['id'] ) ) { |
|
274 | + if ( ! empty( $request[ 'id' ] ) ) { |
|
275 | 275 | return new \WP_Error( 'woocommerce_rest_tax_exists', __( 'Cannot create existing resource.', 'woocommerce-rest-api' ), array( 'status' => 400 ) ); |
276 | 276 | } |
277 | 277 | |
@@ -304,7 +304,7 @@ discard block |
||
304 | 304 | * @return \WP_Error|\WP_REST_Response |
305 | 305 | */ |
306 | 306 | public function get_item( $request ) { |
307 | - $id = (int) $request['id']; |
|
307 | + $id = (int) $request[ 'id' ]; |
|
308 | 308 | $tax_obj = \WC_Tax::_get_tax_rate( $id, OBJECT ); |
309 | 309 | |
310 | 310 | if ( empty( $id ) || empty( $tax_obj ) ) { |
@@ -324,7 +324,7 @@ discard block |
||
324 | 324 | * @return \WP_Error|\WP_REST_Response |
325 | 325 | */ |
326 | 326 | public function update_item( $request ) { |
327 | - $id = (int) $request['id']; |
|
327 | + $id = (int) $request[ 'id' ]; |
|
328 | 328 | $tax_obj = \WC_Tax::_get_tax_rate( $id, OBJECT ); |
329 | 329 | |
330 | 330 | if ( empty( $id ) || empty( $tax_obj ) ) { |
@@ -360,8 +360,8 @@ discard block |
||
360 | 360 | public function delete_item( $request ) { |
361 | 361 | global $wpdb; |
362 | 362 | |
363 | - $id = (int) $request['id']; |
|
364 | - $force = isset( $request['force'] ) ? (bool) $request['force'] : false; |
|
363 | + $id = (int) $request[ 'id' ]; |
|
364 | + $force = isset( $request[ 'force' ] ) ? (bool) $request[ 'force' ] : false; |
|
365 | 365 | |
366 | 366 | // We don't support trashing for this type, error out. |
367 | 367 | if ( ! $force ) { |
@@ -551,10 +551,10 @@ discard block |
||
551 | 551 | */ |
552 | 552 | public function get_collection_params() { |
553 | 553 | $params = array(); |
554 | - $params['context'] = $this->get_context_param(); |
|
555 | - $params['context']['default'] = 'view'; |
|
554 | + $params[ 'context' ] = $this->get_context_param(); |
|
555 | + $params[ 'context' ][ 'default' ] = 'view'; |
|
556 | 556 | |
557 | - $params['page'] = array( |
|
557 | + $params[ 'page' ] = array( |
|
558 | 558 | 'description' => __( 'Current page of the collection.', 'woocommerce-rest-api' ), |
559 | 559 | 'type' => 'integer', |
560 | 560 | 'default' => 1, |
@@ -562,7 +562,7 @@ discard block |
||
562 | 562 | 'validate_callback' => 'rest_validate_request_arg', |
563 | 563 | 'minimum' => 1, |
564 | 564 | ); |
565 | - $params['per_page'] = array( |
|
565 | + $params[ 'per_page' ] = array( |
|
566 | 566 | 'description' => __( 'Maximum number of items to be returned in result set.', 'woocommerce-rest-api' ), |
567 | 567 | 'type' => 'integer', |
568 | 568 | 'default' => 10, |
@@ -571,13 +571,13 @@ discard block |
||
571 | 571 | 'sanitize_callback' => 'absint', |
572 | 572 | 'validate_callback' => 'rest_validate_request_arg', |
573 | 573 | ); |
574 | - $params['offset'] = array( |
|
574 | + $params[ 'offset' ] = array( |
|
575 | 575 | 'description' => __( 'Offset the result set by a specific number of items.', 'woocommerce-rest-api' ), |
576 | 576 | 'type' => 'integer', |
577 | 577 | 'sanitize_callback' => 'absint', |
578 | 578 | 'validate_callback' => 'rest_validate_request_arg', |
579 | 579 | ); |
580 | - $params['order'] = array( |
|
580 | + $params[ 'order' ] = array( |
|
581 | 581 | 'default' => 'asc', |
582 | 582 | 'description' => __( 'Order sort attribute ascending or descending.', 'woocommerce-rest-api' ), |
583 | 583 | 'enum' => array( 'asc', 'desc' ), |
@@ -585,7 +585,7 @@ discard block |
||
585 | 585 | 'type' => 'string', |
586 | 586 | 'validate_callback' => 'rest_validate_request_arg', |
587 | 587 | ); |
588 | - $params['orderby'] = array( |
|
588 | + $params[ 'orderby' ] = array( |
|
589 | 589 | 'default' => 'order', |
590 | 590 | 'description' => __( 'Sort collection by object attribute.', 'woocommerce-rest-api' ), |
591 | 591 | 'enum' => array( |
@@ -596,19 +596,19 @@ discard block |
||
596 | 596 | 'type' => 'string', |
597 | 597 | 'validate_callback' => 'rest_validate_request_arg', |
598 | 598 | ); |
599 | - $params['class'] = array( |
|
599 | + $params[ 'class' ] = array( |
|
600 | 600 | 'description' => __( 'Sort by tax class.', 'woocommerce-rest-api' ), |
601 | 601 | 'enum' => array_merge( array( 'standard' ), \WC_Tax::get_tax_class_slugs() ), |
602 | 602 | 'sanitize_callback' => 'sanitize_title', |
603 | 603 | 'type' => 'string', |
604 | 604 | 'validate_callback' => 'rest_validate_request_arg', |
605 | 605 | ); |
606 | - $params['code'] = array( |
|
606 | + $params[ 'code' ] = array( |
|
607 | 607 | 'description' => __( 'Search by similar tax code.', 'woocommerce-rest-api' ), |
608 | 608 | 'type' => 'string', |
609 | 609 | 'validate_callback' => 'rest_validate_request_arg', |
610 | 610 | ); |
611 | - $params['include'] = array( |
|
611 | + $params[ 'include' ] = array( |
|
612 | 612 | 'description' => __( 'Limit result set to items that have the specified rate ID(s) assigned.', 'woocommerce-rest-api' ), |
613 | 613 | 'type' => 'array', |
614 | 614 | 'items' => array( |