@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | ]; |
130 | 130 | |
131 | 131 | $request_props = array_intersect_key( $this->request, array_flip( $props ) ); |
132 | - $prop_values = []; |
|
132 | + $prop_values = [ ]; |
|
133 | 133 | |
134 | 134 | foreach ( $request_props as $prop => $value ) { |
135 | 135 | switch ( $prop ) { |
@@ -146,20 +146,20 @@ discard block |
||
146 | 146 | $prop_values = array_merge( $prop_values, $images ); |
147 | 147 | break; |
148 | 148 | case 'categories': |
149 | - $prop_values['category_ids'] = wp_list_pluck( $value, 'id' ); |
|
149 | + $prop_values[ 'category_ids' ] = wp_list_pluck( $value, 'id' ); |
|
150 | 150 | break; |
151 | 151 | case 'tags': |
152 | - $prop_values['tag_ids'] = wp_list_pluck( $value, 'id' ); |
|
152 | + $prop_values[ 'tag_ids' ] = wp_list_pluck( $value, 'id' ); |
|
153 | 153 | break; |
154 | 154 | case 'attributes': |
155 | - $prop_values['attributes'] = $this->parse_attributes_field( $value ); |
|
155 | + $prop_values[ 'attributes' ] = $this->parse_attributes_field( $value ); |
|
156 | 156 | break; |
157 | 157 | case 'dimensions': |
158 | 158 | $dimensions = $this->parse_dimensions_fields( $value ); |
159 | 159 | $prop_values = array_merge( $prop_values, $dimensions ); |
160 | 160 | break; |
161 | 161 | case 'shipping_class': |
162 | - $prop_values['shipping_class_id'] = $this->parse_shipping_class( $value, $object ); |
|
162 | + $prop_values[ 'shipping_class_id' ] = $this->parse_shipping_class( $value, $object ); |
|
163 | 163 | break; |
164 | 164 | default: |
165 | 165 | $prop_values[ $prop ] = $value; |
@@ -248,34 +248,34 @@ discard block |
||
248 | 248 | $attributes = array(); |
249 | 249 | |
250 | 250 | foreach ( $raw_attributes as $attribute ) { |
251 | - if ( ! empty( $attribute['id'] ) ) { |
|
252 | - $attribute_id = absint( $attribute['id'] ); |
|
251 | + if ( ! empty( $attribute[ 'id' ] ) ) { |
|
252 | + $attribute_id = absint( $attribute[ 'id' ] ); |
|
253 | 253 | $attribute_name = wc_attribute_taxonomy_name_by_id( $attribute_id ); |
254 | - } elseif ( ! empty( $attribute['name'] ) ) { |
|
254 | + } elseif ( ! empty( $attribute[ 'name' ] ) ) { |
|
255 | 255 | $attribute_id = 0; |
256 | - $attribute_name = wc_clean( $attribute['name'] ); |
|
256 | + $attribute_name = wc_clean( $attribute[ 'name' ] ); |
|
257 | 257 | } |
258 | 258 | |
259 | - if ( ! $attribute_name || ! isset( $attribute['options'] ) ) { |
|
259 | + if ( ! $attribute_name || ! isset( $attribute[ 'options' ] ) ) { |
|
260 | 260 | continue; |
261 | 261 | } |
262 | 262 | |
263 | - if ( ! is_array( $attribute['options'] ) ) { |
|
264 | - $attribute['options'] = explode( \WC_DELIMITER, $attribute['options'] ); |
|
263 | + if ( ! is_array( $attribute[ 'options' ] ) ) { |
|
264 | + $attribute[ 'options' ] = explode( \WC_DELIMITER, $attribute[ 'options' ] ); |
|
265 | 265 | } |
266 | 266 | |
267 | 267 | if ( $attribute_id ) { |
268 | - $attribute['options'] = array_filter( array_map( 'wc_sanitize_term_text_based', $attribute['options'] ), 'strlen' ); |
|
268 | + $attribute[ 'options' ] = array_filter( array_map( 'wc_sanitize_term_text_based', $attribute[ 'options' ] ), 'strlen' ); |
|
269 | 269 | } |
270 | 270 | |
271 | 271 | $attribute_object = new \WC_Product_Attribute(); |
272 | 272 | $attribute_object->set_id( $attribute_id ); |
273 | 273 | $attribute_object->set_name( $attribute_name ); |
274 | - $attribute_object->set_options( $attribute['options'] ); |
|
275 | - $attribute_object->set_position( isset( $attribute['position'] ) ? (string) absint( $attribute['position'] ) : '0' ); |
|
276 | - $attribute_object->set_visible( ! empty( $attribute['visible'] ) ? 1 : 0 ); |
|
277 | - $attribute_object->set_variation( ! empty( $attribute['variation'] ) ? 1 : 0 ); |
|
278 | - $attributes[] = $attribute_object; |
|
274 | + $attribute_object->set_options( $attribute[ 'options' ] ); |
|
275 | + $attribute_object->set_position( isset( $attribute[ 'position' ] ) ? (string) absint( $attribute[ 'position' ] ) : '0' ); |
|
276 | + $attribute_object->set_visible( ! empty( $attribute[ 'visible' ] ) ? 1 : 0 ); |
|
277 | + $attribute_object->set_variation( ! empty( $attribute[ 'variation' ] ) ? 1 : 0 ); |
|
278 | + $attributes[ ] = $attribute_object; |
|
279 | 279 | } |
280 | 280 | return $attributes; |
281 | 281 | } |
@@ -291,35 +291,35 @@ discard block |
||
291 | 291 | protected function parse_images_field( $images, $object ) { |
292 | 292 | $response = [ |
293 | 293 | 'image_id' => '', |
294 | - 'gallery_image_ids' => [], |
|
294 | + 'gallery_image_ids' => [ ], |
|
295 | 295 | ]; |
296 | 296 | |
297 | - $images = is_array( $images ) ? array_filter( $images ) : []; |
|
297 | + $images = is_array( $images ) ? array_filter( $images ) : [ ]; |
|
298 | 298 | |
299 | 299 | if ( empty( $images ) ) { |
300 | 300 | return $response; |
301 | 301 | } |
302 | 302 | |
303 | 303 | foreach ( $images as $index => $image ) { |
304 | - $attachment_id = isset( $image['id'] ) ? absint( $image['id'] ) : 0; |
|
304 | + $attachment_id = isset( $image[ 'id' ] ) ? absint( $image[ 'id' ] ) : 0; |
|
305 | 305 | $attachment = new ImageAttachment( $attachment_id, $object->get_id() ); |
306 | 306 | |
307 | - if ( 0 === $attachment->id && ! empty( $image['src'] ) ) { |
|
308 | - $attachment->upload_image_from_src( $image['src'] ); |
|
307 | + if ( 0 === $attachment->id && ! empty( $image[ 'src' ] ) ) { |
|
308 | + $attachment->upload_image_from_src( $image[ 'src' ] ); |
|
309 | 309 | } |
310 | 310 | |
311 | - if ( ! empty( $image['alt'] ) ) { |
|
312 | - $attachment->update_alt_text( $image['alt'] ); |
|
311 | + if ( ! empty( $image[ 'alt' ] ) ) { |
|
312 | + $attachment->update_alt_text( $image[ 'alt' ] ); |
|
313 | 313 | } |
314 | 314 | |
315 | - if ( ! empty( $image['name'] ) ) { |
|
316 | - $attachment->update_name( $image['name'] ); |
|
315 | + if ( ! empty( $image[ 'name' ] ) ) { |
|
316 | + $attachment->update_name( $image[ 'name' ] ); |
|
317 | 317 | } |
318 | 318 | |
319 | 319 | if ( 0 === $index ) { |
320 | - $response['image_id'] = $attachment->id; |
|
320 | + $response[ 'image_id' ] = $attachment->id; |
|
321 | 321 | } else { |
322 | - $response['gallery_image_ids'][] = $attachment->id; |
|
322 | + $response[ 'gallery_image_ids' ][ ] = $attachment->id; |
|
323 | 323 | } |
324 | 324 | } |
325 | 325 | |
@@ -333,18 +333,18 @@ discard block |
||
333 | 333 | * @return array |
334 | 334 | */ |
335 | 335 | protected function parse_dimensions_fields( $dimensions ) { |
336 | - $response = []; |
|
336 | + $response = [ ]; |
|
337 | 337 | |
338 | - if ( isset( $dimensions['length'] ) ) { |
|
339 | - $response['length'] = $dimensions['length']; |
|
338 | + if ( isset( $dimensions[ 'length' ] ) ) { |
|
339 | + $response[ 'length' ] = $dimensions[ 'length' ]; |
|
340 | 340 | } |
341 | 341 | |
342 | - if ( isset( $dimensions['width'] ) ) { |
|
343 | - $response['width'] = $dimensions['width']; |
|
342 | + if ( isset( $dimensions[ 'width' ] ) ) { |
|
343 | + $response[ 'width' ] = $dimensions[ 'width' ]; |
|
344 | 344 | } |
345 | 345 | |
346 | - if ( isset( $dimensions['height'] ) ) { |
|
347 | - $response['height'] = $dimensions['height']; |
|
346 | + if ( isset( $dimensions[ 'height' ] ) ) { |
|
347 | + $response[ 'height' ] = $dimensions[ 'height' ]; |
|
348 | 348 | } |
349 | 349 | |
350 | 350 | return $response; |
@@ -371,15 +371,15 @@ discard block |
||
371 | 371 | protected function parse_downloads_field( $downloads ) { |
372 | 372 | $files = array(); |
373 | 373 | foreach ( $downloads as $key => $file ) { |
374 | - if ( empty( $file['file'] ) ) { |
|
374 | + if ( empty( $file[ 'file' ] ) ) { |
|
375 | 375 | continue; |
376 | 376 | } |
377 | 377 | |
378 | 378 | $download = new \WC_Product_Download(); |
379 | - $download->set_id( ! empty( $file['id'] ) ? $file['id'] : wp_generate_uuid4() ); |
|
380 | - $download->set_name( $file['name'] ? $file['name'] : wc_get_filename_from_url( $file['file'] ) ); |
|
381 | - $download->set_file( $file['file'] ); |
|
382 | - $files[] = $download; |
|
379 | + $download->set_id( ! empty( $file[ 'id' ] ) ? $file[ 'id' ] : wp_generate_uuid4() ); |
|
380 | + $download->set_name( $file[ 'name' ] ? $file[ 'name' ] : wc_get_filename_from_url( $file[ 'file' ] ) ); |
|
381 | + $download->set_file( $file[ 'file' ] ); |
|
382 | + $files[ ] = $download; |
|
383 | 383 | } |
384 | 384 | return $files; |
385 | 385 | } |
@@ -400,11 +400,11 @@ discard block |
||
400 | 400 | $attribute_name = ''; |
401 | 401 | |
402 | 402 | // Check ID for global attributes or name for product attributes. |
403 | - if ( ! empty( $attribute['id'] ) ) { |
|
404 | - $attribute_id = absint( $attribute['id'] ); |
|
403 | + if ( ! empty( $attribute[ 'id' ] ) ) { |
|
404 | + $attribute_id = absint( $attribute[ 'id' ] ); |
|
405 | 405 | $attribute_name = wc_attribute_taxonomy_name_by_id( $attribute_id ); |
406 | - } elseif ( ! empty( $attribute['name'] ) ) { |
|
407 | - $attribute_name = sanitize_title( $attribute['name'] ); |
|
406 | + } elseif ( ! empty( $attribute[ 'name' ] ) ) { |
|
407 | + $attribute_name = sanitize_title( $attribute[ 'name' ] ); |
|
408 | 408 | } |
409 | 409 | |
410 | 410 | if ( ! $attribute_id && ! $attribute_name ) { |
@@ -414,10 +414,10 @@ discard block |
||
414 | 414 | if ( isset( $attributes[ $attribute_name ] ) ) { |
415 | 415 | $_attribute = $attributes[ $attribute_name ]; |
416 | 416 | |
417 | - if ( $_attribute['is_variation'] ) { |
|
418 | - $value = isset( $attribute['option'] ) ? wc_clean( stripslashes( $attribute['option'] ) ) : ''; |
|
417 | + if ( $_attribute[ 'is_variation' ] ) { |
|
418 | + $value = isset( $attribute[ 'option' ] ) ? wc_clean( stripslashes( $attribute[ 'option' ] ) ) : ''; |
|
419 | 419 | |
420 | - if ( ! empty( $_attribute['is_taxonomy'] ) ) { |
|
420 | + if ( ! empty( $_attribute[ 'is_taxonomy' ] ) ) { |
|
421 | 421 | // If dealing with a taxonomy, we need to get the slug from the name posted to the API. |
422 | 422 | $term = get_term_by( 'name', $value, $attribute_name ); |
423 | 423 |
@@ -136,16 +136,16 @@ discard block |
||
136 | 136 | */ |
137 | 137 | public function get_items( $request ) { |
138 | 138 | $prepared_args = array( |
139 | - 'exclude' => $request['exclude'], |
|
140 | - 'include' => $request['include'], |
|
141 | - 'order' => $request['order'], |
|
142 | - 'number' => $request['per_page'], |
|
139 | + 'exclude' => $request[ 'exclude' ], |
|
140 | + 'include' => $request[ 'include' ], |
|
141 | + 'order' => $request[ 'order' ], |
|
142 | + 'number' => $request[ 'per_page' ], |
|
143 | 143 | ); |
144 | 144 | |
145 | - if ( ! empty( $request['offset'] ) ) { |
|
146 | - $prepared_args['offset'] = $request['offset']; |
|
145 | + if ( ! empty( $request[ 'offset' ] ) ) { |
|
146 | + $prepared_args[ 'offset' ] = $request[ 'offset' ]; |
|
147 | 147 | } else { |
148 | - $prepared_args['offset'] = ( $request['page'] - 1 ) * $prepared_args['number']; |
|
148 | + $prepared_args[ 'offset' ] = ( $request[ 'page' ] - 1 ) * $prepared_args[ 'number' ]; |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | $orderby_possibles = array( |
@@ -154,22 +154,22 @@ discard block |
||
154 | 154 | 'name' => 'display_name', |
155 | 155 | 'registered_date' => 'registered', |
156 | 156 | ); |
157 | - $prepared_args['orderby'] = $orderby_possibles[ $request['orderby'] ]; |
|
158 | - $prepared_args['search'] = $request['search']; |
|
157 | + $prepared_args[ 'orderby' ] = $orderby_possibles[ $request[ 'orderby' ] ]; |
|
158 | + $prepared_args[ 'search' ] = $request[ 'search' ]; |
|
159 | 159 | |
160 | - if ( '' !== $prepared_args['search'] ) { |
|
161 | - $prepared_args['search'] = '*' . $prepared_args['search'] . '*'; |
|
160 | + if ( '' !== $prepared_args[ 'search' ] ) { |
|
161 | + $prepared_args[ 'search' ] = '*' . $prepared_args[ 'search' ] . '*'; |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | // Filter by email. |
165 | - if ( ! empty( $request['email'] ) ) { |
|
166 | - $prepared_args['search'] = $request['email']; |
|
167 | - $prepared_args['search_columns'] = array( 'user_email' ); |
|
165 | + if ( ! empty( $request[ 'email' ] ) ) { |
|
166 | + $prepared_args[ 'search' ] = $request[ 'email' ]; |
|
167 | + $prepared_args[ 'search_columns' ] = array( 'user_email' ); |
|
168 | 168 | } |
169 | 169 | |
170 | 170 | // Filter by role. |
171 | - if ( 'all' !== $request['role'] ) { |
|
172 | - $prepared_args['role'] = $request['role']; |
|
171 | + if ( 'all' !== $request[ 'role' ] ) { |
|
172 | + $prepared_args[ 'role' ] = $request[ 'role' ]; |
|
173 | 173 | } |
174 | 174 | |
175 | 175 | /** |
@@ -188,21 +188,21 @@ discard block |
||
188 | 188 | foreach ( $query->results as $user ) { |
189 | 189 | $customer = new \WC_Customer( $user->ID ); |
190 | 190 | $data = $this->prepare_item_for_response( $customer, $request ); |
191 | - $users[] = $this->prepare_response_for_collection( $data ); |
|
191 | + $users[ ] = $this->prepare_response_for_collection( $data ); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | // Store pagination values for headers then unset for count query. |
195 | - $per_page = (int) $prepared_args['number']; |
|
196 | - $page = ceil( ( ( (int) $prepared_args['offset'] ) / $per_page ) + 1 ); |
|
195 | + $per_page = (int) $prepared_args[ 'number' ]; |
|
196 | + $page = ceil( ( ( (int) $prepared_args[ 'offset' ] ) / $per_page ) + 1 ); |
|
197 | 197 | |
198 | - $prepared_args['fields'] = 'ID'; |
|
198 | + $prepared_args[ 'fields' ] = 'ID'; |
|
199 | 199 | |
200 | 200 | $total_users = $query->get_total(); |
201 | 201 | |
202 | 202 | if ( $total_users < 1 ) { |
203 | 203 | // Out-of-bounds, run the query again without LIMIT for total count. |
204 | - unset( $prepared_args['number'] ); |
|
205 | - unset( $prepared_args['offset'] ); |
|
204 | + unset( $prepared_args[ 'number' ] ); |
|
205 | + unset( $prepared_args[ 'offset' ] ); |
|
206 | 206 | $count_query = new \ WP_User_Query( $prepared_args ); |
207 | 207 | $total_users = $count_query->get_total(); |
208 | 208 | } |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | */ |
223 | 223 | public function create_item( $request ) { |
224 | 224 | try { |
225 | - if ( ! empty( $request['id'] ) ) { |
|
225 | + if ( ! empty( $request[ 'id' ] ) ) { |
|
226 | 226 | throw new \WC_REST_Exception( 'woocommerce_rest_customer_exists', __( 'Cannot create existing resource.', 'woocommerce' ), 400 ); |
227 | 227 | } |
228 | 228 | |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | * @return \WP_Error|\WP_REST_Response |
265 | 265 | */ |
266 | 266 | public function get_item( $request ) { |
267 | - $id = (int) $request['id']; |
|
267 | + $id = (int) $request[ 'id' ]; |
|
268 | 268 | $customer = new \WC_Customer( $id ); |
269 | 269 | |
270 | 270 | if ( empty( $id ) || ! $customer->get_id() ) { |
@@ -322,9 +322,9 @@ discard block |
||
322 | 322 | * @return \WP_Error|\WP_REST_Response |
323 | 323 | */ |
324 | 324 | public function delete_item( $request ) { |
325 | - $id = (int) $request['id']; |
|
326 | - $reassign = isset( $request['reassign'] ) ? absint( $request['reassign'] ) : null; |
|
327 | - $force = isset( $request['force'] ) ? (bool) $request['force'] : false; |
|
325 | + $id = (int) $request[ 'id' ]; |
|
326 | + $reassign = isset( $request[ 'reassign' ] ) ? absint( $request[ 'reassign' ] ) : null; |
|
327 | + $force = isset( $request[ 'force' ] ) ? (bool) $request[ 'force' ] : false; |
|
328 | 328 | |
329 | 329 | // We don't support trashing for this type, error out. |
330 | 330 | if ( ! $force ) { |
@@ -663,9 +663,9 @@ discard block |
||
663 | 663 | public function get_collection_params() { |
664 | 664 | $params = parent::get_collection_params(); |
665 | 665 | |
666 | - $params['context']['default'] = 'view'; |
|
666 | + $params[ 'context' ][ 'default' ] = 'view'; |
|
667 | 667 | |
668 | - $params['exclude'] = array( |
|
668 | + $params[ 'exclude' ] = array( |
|
669 | 669 | 'description' => __( 'Ensure result set excludes specific IDs.', 'woocommerce' ), |
670 | 670 | 'type' => 'array', |
671 | 671 | 'items' => array( |
@@ -674,7 +674,7 @@ discard block |
||
674 | 674 | 'default' => array(), |
675 | 675 | 'sanitize_callback' => 'wp_parse_id_list', |
676 | 676 | ); |
677 | - $params['include'] = array( |
|
677 | + $params[ 'include' ] = array( |
|
678 | 678 | 'description' => __( 'Limit result set to specific IDs.', 'woocommerce' ), |
679 | 679 | 'type' => 'array', |
680 | 680 | 'items' => array( |
@@ -683,13 +683,13 @@ discard block |
||
683 | 683 | 'default' => array(), |
684 | 684 | 'sanitize_callback' => 'wp_parse_id_list', |
685 | 685 | ); |
686 | - $params['offset'] = array( |
|
686 | + $params[ 'offset' ] = array( |
|
687 | 687 | 'description' => __( 'Offset the result set by a specific number of items.', 'woocommerce' ), |
688 | 688 | 'type' => 'integer', |
689 | 689 | 'sanitize_callback' => 'absint', |
690 | 690 | 'validate_callback' => 'rest_validate_request_arg', |
691 | 691 | ); |
692 | - $params['order'] = array( |
|
692 | + $params[ 'order' ] = array( |
|
693 | 693 | 'default' => 'asc', |
694 | 694 | 'description' => __( 'Order sort attribute ascending or descending.', 'woocommerce' ), |
695 | 695 | 'enum' => array( 'asc', 'desc' ), |
@@ -697,7 +697,7 @@ discard block |
||
697 | 697 | 'type' => 'string', |
698 | 698 | 'validate_callback' => 'rest_validate_request_arg', |
699 | 699 | ); |
700 | - $params['orderby'] = array( |
|
700 | + $params[ 'orderby' ] = array( |
|
701 | 701 | 'default' => 'name', |
702 | 702 | 'description' => __( 'Sort collection by object attribute.', 'woocommerce' ), |
703 | 703 | 'enum' => array( |
@@ -710,13 +710,13 @@ discard block |
||
710 | 710 | 'type' => 'string', |
711 | 711 | 'validate_callback' => 'rest_validate_request_arg', |
712 | 712 | ); |
713 | - $params['email'] = array( |
|
713 | + $params[ 'email' ] = array( |
|
714 | 714 | 'description' => __( 'Limit result set to resources with a specific email.', 'woocommerce' ), |
715 | 715 | 'type' => 'string', |
716 | 716 | 'format' => 'email', |
717 | 717 | 'validate_callback' => 'rest_validate_request_arg', |
718 | 718 | ); |
719 | - $params['role'] = array( |
|
719 | + $params[ 'role' ] = array( |
|
720 | 720 | 'description' => __( 'Limit result set to resources with a specific role.', 'woocommerce' ), |
721 | 721 | 'type' => 'string', |
722 | 722 | 'default' => 'customer', |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | if ( $image_id ) { |
57 | 57 | $attachment = get_post( $image_id ); |
58 | 58 | |
59 | - $data['image'] = array( |
|
59 | + $data[ 'image' ] = array( |
|
60 | 60 | 'id' => (int) $image_id, |
61 | 61 | 'date_created' => wc_rest_prepare_date_response( $attachment->post_date ), |
62 | 62 | 'date_created_gmt' => wc_rest_prepare_date_response( $attachment->post_date_gmt ), |
@@ -82,17 +82,17 @@ discard block |
||
82 | 82 | protected function update_term_meta_fields( $term, $request ) { |
83 | 83 | $id = (int) $term->term_id; |
84 | 84 | |
85 | - if ( isset( $request['display'] ) ) { |
|
86 | - update_term_meta( $id, 'display_type', 'default' === $request['display'] ? '' : $request['display'] ); |
|
85 | + if ( isset( $request[ 'display' ] ) ) { |
|
86 | + update_term_meta( $id, 'display_type', 'default' === $request[ 'display' ] ? '' : $request[ 'display' ] ); |
|
87 | 87 | } |
88 | 88 | |
89 | - if ( isset( $request['menu_order'] ) ) { |
|
90 | - update_term_meta( $id, 'order', $request['menu_order'] ); |
|
89 | + if ( isset( $request[ 'menu_order' ] ) ) { |
|
90 | + update_term_meta( $id, 'order', $request[ 'menu_order' ] ); |
|
91 | 91 | } |
92 | 92 | |
93 | - if ( isset( $request['image'] ) ) { |
|
94 | - if ( empty( $request['image']['id'] ) && ! empty( $request['image']['src'] ) ) { |
|
95 | - $upload = wc_rest_upload_image_from_url( esc_url_raw( $request['image']['src'] ) ); |
|
93 | + if ( isset( $request[ 'image' ] ) ) { |
|
94 | + if ( empty( $request[ 'image' ][ 'id' ] ) && ! empty( $request[ 'image' ][ 'src' ] ) ) { |
|
95 | + $upload = wc_rest_upload_image_from_url( esc_url_raw( $request[ 'image' ][ 'src' ] ) ); |
|
96 | 96 | |
97 | 97 | if ( is_wp_error( $upload ) ) { |
98 | 98 | return $upload; |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | |
101 | 101 | $image_id = wc_rest_set_uploaded_image_as_attachment( $upload ); |
102 | 102 | } else { |
103 | - $image_id = isset( $request['image']['id'] ) ? absint( $request['image']['id'] ) : 0; |
|
103 | + $image_id = isset( $request[ 'image' ][ 'id' ] ) ? absint( $request[ 'image' ][ 'id' ] ) : 0; |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | // Check if image_id is a valid image attachment before updating the term meta. |
@@ -108,16 +108,16 @@ discard block |
||
108 | 108 | update_term_meta( $id, 'thumbnail_id', $image_id ); |
109 | 109 | |
110 | 110 | // Set the image alt. |
111 | - if ( ! empty( $request['image']['alt'] ) ) { |
|
112 | - update_post_meta( $image_id, '_wp_attachment_image_alt', wc_clean( $request['image']['alt'] ) ); |
|
111 | + if ( ! empty( $request[ 'image' ][ 'alt' ] ) ) { |
|
112 | + update_post_meta( $image_id, '_wp_attachment_image_alt', wc_clean( $request[ 'image' ][ 'alt' ] ) ); |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | // Set the image title. |
116 | - if ( ! empty( $request['image']['name'] ) ) { |
|
116 | + if ( ! empty( $request[ 'image' ][ 'name' ] ) ) { |
|
117 | 117 | wp_update_post( |
118 | 118 | array( |
119 | 119 | 'ID' => $image_id, |
120 | - 'post_title' => wc_clean( $request['image']['name'] ), |
|
120 | + 'post_title' => wc_clean( $request[ 'image' ][ 'name' ] ), |
|
121 | 121 | ) |
122 | 122 | ); |
123 | 123 | } |
@@ -74,32 +74,32 @@ discard block |
||
74 | 74 | |
75 | 75 | return array( |
76 | 76 | 'id' => $object->get_id(), |
77 | - 'code' => $data['code'], |
|
78 | - 'amount' => $data['amount'], |
|
79 | - 'date_created' => $data['date_created'], |
|
80 | - 'date_created_gmt' => $data['date_created_gmt'], |
|
81 | - 'date_modified' => $data['date_modified'], |
|
82 | - 'date_modified_gmt' => $data['date_modified_gmt'], |
|
83 | - 'discount_type' => $data['discount_type'], |
|
84 | - 'description' => $data['description'], |
|
85 | - 'date_expires' => $data['date_expires'], |
|
86 | - 'date_expires_gmt' => $data['date_expires_gmt'], |
|
87 | - 'usage_count' => $data['usage_count'], |
|
88 | - 'individual_use' => $data['individual_use'], |
|
89 | - 'product_ids' => $data['product_ids'], |
|
90 | - 'excluded_product_ids' => $data['excluded_product_ids'], |
|
91 | - 'usage_limit' => $data['usage_limit'], |
|
92 | - 'usage_limit_per_user' => $data['usage_limit_per_user'], |
|
93 | - 'limit_usage_to_x_items' => $data['limit_usage_to_x_items'], |
|
94 | - 'free_shipping' => $data['free_shipping'], |
|
95 | - 'product_categories' => $data['product_categories'], |
|
96 | - 'excluded_product_categories' => $data['excluded_product_categories'], |
|
97 | - 'exclude_sale_items' => $data['exclude_sale_items'], |
|
98 | - 'minimum_amount' => $data['minimum_amount'], |
|
99 | - 'maximum_amount' => $data['maximum_amount'], |
|
100 | - 'email_restrictions' => $data['email_restrictions'], |
|
101 | - 'used_by' => $data['used_by'], |
|
102 | - 'meta_data' => $data['meta_data'], |
|
77 | + 'code' => $data[ 'code' ], |
|
78 | + 'amount' => $data[ 'amount' ], |
|
79 | + 'date_created' => $data[ 'date_created' ], |
|
80 | + 'date_created_gmt' => $data[ 'date_created_gmt' ], |
|
81 | + 'date_modified' => $data[ 'date_modified' ], |
|
82 | + 'date_modified_gmt' => $data[ 'date_modified_gmt' ], |
|
83 | + 'discount_type' => $data[ 'discount_type' ], |
|
84 | + 'description' => $data[ 'description' ], |
|
85 | + 'date_expires' => $data[ 'date_expires' ], |
|
86 | + 'date_expires_gmt' => $data[ 'date_expires_gmt' ], |
|
87 | + 'usage_count' => $data[ 'usage_count' ], |
|
88 | + 'individual_use' => $data[ 'individual_use' ], |
|
89 | + 'product_ids' => $data[ 'product_ids' ], |
|
90 | + 'excluded_product_ids' => $data[ 'excluded_product_ids' ], |
|
91 | + 'usage_limit' => $data[ 'usage_limit' ], |
|
92 | + 'usage_limit_per_user' => $data[ 'usage_limit_per_user' ], |
|
93 | + 'limit_usage_to_x_items' => $data[ 'limit_usage_to_x_items' ], |
|
94 | + 'free_shipping' => $data[ 'free_shipping' ], |
|
95 | + 'product_categories' => $data[ 'product_categories' ], |
|
96 | + 'excluded_product_categories' => $data[ 'excluded_product_categories' ], |
|
97 | + 'exclude_sale_items' => $data[ 'exclude_sale_items' ], |
|
98 | + 'minimum_amount' => $data[ 'minimum_amount' ], |
|
99 | + 'maximum_amount' => $data[ 'maximum_amount' ], |
|
100 | + 'email_restrictions' => $data[ 'email_restrictions' ], |
|
101 | + 'used_by' => $data[ 'used_by' ], |
|
102 | + 'meta_data' => $data[ 'meta_data' ], |
|
103 | 103 | ); |
104 | 104 | } |
105 | 105 | |
@@ -113,14 +113,14 @@ discard block |
||
113 | 113 | protected function prepare_objects_query( $request ) { |
114 | 114 | $args = parent::prepare_objects_query( $request ); |
115 | 115 | |
116 | - if ( ! empty( $request['code'] ) ) { |
|
117 | - $id = wc_get_coupon_id_by_code( $request['code'] ); |
|
118 | - $args['post__in'] = array( $id ); |
|
116 | + if ( ! empty( $request[ 'code' ] ) ) { |
|
117 | + $id = wc_get_coupon_id_by_code( $request[ 'code' ] ); |
|
118 | + $args[ 'post__in' ] = array( $id ); |
|
119 | 119 | } |
120 | 120 | |
121 | - if ( ! empty( $request['search'] ) ) { |
|
122 | - $args['search'] = $request['search']; |
|
123 | - $args['s'] = false; |
|
121 | + if ( ! empty( $request[ 'search' ] ) ) { |
|
122 | + $args[ 'search' ] = $request[ 'search' ]; |
|
123 | + $args[ 's' ] = false; |
|
124 | 124 | } |
125 | 125 | |
126 | 126 | return $args; |
@@ -134,13 +134,13 @@ discard block |
||
134 | 134 | * @return \WP_Error|\WC_Data |
135 | 135 | */ |
136 | 136 | protected function prepare_object_for_database( $request, $creating = false ) { |
137 | - $id = isset( $request['id'] ) ? absint( $request['id'] ) : 0; |
|
137 | + $id = isset( $request[ 'id' ] ) ? absint( $request[ 'id' ] ) : 0; |
|
138 | 138 | $coupon = new \WC_Coupon( $id ); |
139 | 139 | $schema = $this->get_item_schema(); |
140 | - $data_keys = array_keys( array_filter( $schema['properties'], array( $this, 'filter_writable_props' ) ) ); |
|
140 | + $data_keys = array_keys( array_filter( $schema[ 'properties' ], array( $this, 'filter_writable_props' ) ) ); |
|
141 | 141 | |
142 | 142 | // Validate required POST fields. |
143 | - if ( $creating && empty( $request['code'] ) ) { |
|
143 | + if ( $creating && empty( $request[ 'code' ] ) ) { |
|
144 | 144 | return new \WP_Error( 'woocommerce_rest_empty_coupon_code', sprintf( __( 'The coupon code cannot be empty.', 'woocommerce' ), 'code' ), array( 'status' => 400 ) ); |
145 | 145 | } |
146 | 146 | |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | case 'meta_data': |
165 | 165 | if ( is_array( $value ) ) { |
166 | 166 | foreach ( $value as $meta ) { |
167 | - $coupon->update_meta_data( $meta['key'], $meta['value'], isset( $meta['id'] ) ? $meta['id'] : 0 ); |
|
167 | + $coupon->update_meta_data( $meta[ 'key' ], $meta[ 'value' ], isset( $meta[ 'id' ] ) ? $meta[ 'id' ] : 0 ); |
|
168 | 168 | } |
169 | 169 | } |
170 | 170 | break; |
@@ -404,14 +404,14 @@ discard block |
||
404 | 404 | public function get_collection_params() { |
405 | 405 | $params = parent::get_collection_params(); |
406 | 406 | |
407 | - $params['code'] = array( |
|
407 | + $params[ 'code' ] = array( |
|
408 | 408 | 'description' => __( 'Limit result set to resources with a specific code.', 'woocommerce' ), |
409 | 409 | 'type' => 'string', |
410 | 410 | 'sanitize_callback' => 'sanitize_text_field', |
411 | 411 | 'validate_callback' => 'rest_validate_request_arg', |
412 | 412 | ); |
413 | 413 | |
414 | - $params['search'] = array( |
|
414 | + $params[ 'search' ] = array( |
|
415 | 415 | 'description' => __( 'Limit results to coupons with codes matching a given string.', 'woocommerce' ), |
416 | 416 | 'type' => 'string', |
417 | 417 | 'validate_callback' => 'rest_validate_request_arg', |
@@ -427,7 +427,7 @@ discard block |
||
427 | 427 | * @return bool |
428 | 428 | */ |
429 | 429 | protected function filter_writable_props( $schema ) { |
430 | - return empty( $schema['readonly'] ); |
|
430 | + return empty( $schema[ 'readonly' ] ); |
|
431 | 431 | } |
432 | 432 | |
433 | 433 | /** |
@@ -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' ), 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' ), 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' ), 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' ), $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' ), 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' ), 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' ), 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' ), 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' ), 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' ), |
441 | 441 | 'type' => 'string', |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | * @return \WP_Error|boolean |
47 | 47 | */ |
48 | 48 | public function get_items_permissions_check( $request ) { |
49 | - $customer = get_user_by( 'id', (int) $request['customer_id'] ); |
|
49 | + $customer = get_user_by( 'id', (int) $request[ 'customer_id' ] ); |
|
50 | 50 | |
51 | 51 | if ( ! $customer ) { |
52 | 52 | return new \WP_Error( 'woocommerce_rest_customer_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) ); |
@@ -66,13 +66,13 @@ discard block |
||
66 | 66 | * @return array |
67 | 67 | */ |
68 | 68 | public function get_items( $request ) { |
69 | - $downloads = wc_get_customer_available_downloads( (int) $request['customer_id'] ); |
|
69 | + $downloads = wc_get_customer_available_downloads( (int) $request[ 'customer_id' ] ); |
|
70 | 70 | |
71 | 71 | $data = array(); |
72 | 72 | foreach ( $downloads as $download_data ) { |
73 | 73 | $download = $this->prepare_item_for_response( (object) $download_data, $request ); |
74 | 74 | $download = $this->prepare_response_for_collection( $download ); |
75 | - $data[] = $download; |
|
75 | + $data[ ] = $download; |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | return rest_ensure_response( $data ); |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | * @return array |
110 | 110 | */ |
111 | 111 | protected function prepare_links( $item, $request ) { |
112 | - $base = str_replace( '(?P<customer_id>[\d]+)', $request['customer_id'], $this->rest_base ); |
|
112 | + $base = str_replace( '(?P<customer_id>[\d]+)', $request[ 'customer_id' ], $this->rest_base ); |
|
113 | 113 | $links = array( |
114 | 114 | 'collection' => array( |
115 | 115 | 'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $base ) ), |
@@ -83,19 +83,19 @@ discard block |
||
83 | 83 | foreach ( $groups as $group ) { |
84 | 84 | $sub_groups = array(); |
85 | 85 | foreach ( $groups as $_group ) { |
86 | - if ( ! empty( $_group['parent_id'] ) && $group['id'] === $_group['parent_id'] ) { |
|
87 | - $sub_groups[] = $_group['id']; |
|
86 | + if ( ! empty( $_group[ 'parent_id' ] ) && $group[ 'id' ] === $_group[ 'parent_id' ] ) { |
|
87 | + $sub_groups[ ] = $_group[ 'id' ]; |
|
88 | 88 | } |
89 | 89 | } |
90 | - $group['sub_groups'] = $sub_groups; |
|
90 | + $group[ 'sub_groups' ] = $sub_groups; |
|
91 | 91 | |
92 | 92 | $group = wp_parse_args( $group, $defaults ); |
93 | - if ( ! is_null( $group['id'] ) && ! is_null( $group['label'] ) ) { |
|
93 | + if ( ! is_null( $group[ 'id' ] ) && ! is_null( $group[ 'label' ] ) ) { |
|
94 | 94 | $group_obj = $this->filter_group( $group ); |
95 | 95 | $group_data = $this->prepare_item_for_response( $group_obj, $request ); |
96 | 96 | $group_data = $this->prepare_response_for_collection( $group_data ); |
97 | 97 | |
98 | - $filtered_groups[] = $group_data; |
|
98 | + $filtered_groups[ ] = $group_data; |
|
99 | 99 | } |
100 | 100 | } |
101 | 101 | |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | $base = '/' . $this->namespace . '/' . $this->rest_base; |
115 | 115 | $links = array( |
116 | 116 | 'options' => array( |
117 | - 'href' => rest_url( trailingslashit( $base ) . $item['id'] ), |
|
117 | + 'href' => rest_url( trailingslashit( $base ) . $item[ 'id' ] ), |
|
118 | 118 | ), |
119 | 119 | ); |
120 | 120 |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | * @return \WP_REST_Response|\WP_Error |
55 | 55 | */ |
56 | 56 | public function get_items( $request ) { |
57 | - $zone = $this->get_zone( (int) $request['id'] ); |
|
57 | + $zone = $this->get_zone( (int) $request[ 'id' ] ); |
|
58 | 58 | |
59 | 59 | if ( is_wp_error( $zone ) ) { |
60 | 60 | return $zone; |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | foreach ( $locations as $location_obj ) { |
67 | 67 | $location = $this->prepare_item_for_response( (array) $location_obj, $request ); |
68 | 68 | $location = $this->prepare_response_for_collection( $location ); |
69 | - $data[] = $location; |
|
69 | + $data[ ] = $location; |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | return rest_ensure_response( $data ); |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | * @return \WP_REST_Response|\WP_Error |
80 | 80 | */ |
81 | 81 | public function update_items( $request ) { |
82 | - $zone = $this->get_zone( (int) $request['id'] ); |
|
82 | + $zone = $this->get_zone( (int) $request[ 'id' ] ); |
|
83 | 83 | |
84 | 84 | if ( is_wp_error( $zone ) ) { |
85 | 85 | return $zone; |
@@ -93,18 +93,18 @@ discard block |
||
93 | 93 | $locations = array(); |
94 | 94 | |
95 | 95 | foreach ( (array) $raw_locations as $raw_location ) { |
96 | - if ( empty( $raw_location['code'] ) ) { |
|
96 | + if ( empty( $raw_location[ 'code' ] ) ) { |
|
97 | 97 | continue; |
98 | 98 | } |
99 | 99 | |
100 | - $type = ! empty( $raw_location['type'] ) ? sanitize_text_field( $raw_location['type'] ) : 'country'; |
|
100 | + $type = ! empty( $raw_location[ 'type' ] ) ? sanitize_text_field( $raw_location[ 'type' ] ) : 'country'; |
|
101 | 101 | |
102 | 102 | if ( ! in_array( $type, array( 'postcode', 'state', 'country', 'continent' ), true ) ) { |
103 | 103 | continue; |
104 | 104 | } |
105 | 105 | |
106 | - $locations[] = array( |
|
107 | - 'code' => sanitize_text_field( $raw_location['code'] ), |
|
106 | + $locations[ ] = array( |
|
107 | + 'code' => sanitize_text_field( $raw_location[ 'code' ] ), |
|
108 | 108 | 'type' => sanitize_text_field( $type ), |
109 | 109 | ); |
110 | 110 | } |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | * @return array |
124 | 124 | */ |
125 | 125 | protected function prepare_links( $item, $request ) { |
126 | - $base = '/' . $this->namespace . '/' . $this->rest_base . '/' . $request['id']; |
|
126 | + $base = '/' . $this->namespace . '/' . $this->rest_base . '/' . $request[ 'id' ]; |
|
127 | 127 | $links = array( |
128 | 128 | 'collection' => array( |
129 | 129 | 'href' => rest_url( $base . '/locations' ), |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | foreach ( $zones as $zone_obj ) { |
125 | 125 | $zone = $this->prepare_item_for_response( $zone_obj, $request ); |
126 | 126 | $zone = $this->prepare_response_for_collection( $zone ); |
127 | - $data[] = $zone; |
|
127 | + $data[ ] = $zone; |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | return rest_ensure_response( $data ); |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | return $zone; |
210 | 210 | } |
211 | 211 | |
212 | - $force = $request['force']; |
|
212 | + $force = $request[ 'force' ]; |
|
213 | 213 | |
214 | 214 | // We don't support trashing for this type, error out. |
215 | 215 | if ( ! $force ) { |
@@ -238,9 +238,9 @@ discard block |
||
238 | 238 | */ |
239 | 239 | protected function get_data_for_response( $object, $request ) { |
240 | 240 | return array( |
241 | - 'id' => (int) $object['id'], |
|
242 | - 'name' => $object['zone_name'], |
|
243 | - 'order' => (int) $object['zone_order'], |
|
241 | + 'id' => (int) $object[ 'id' ], |
|
242 | + 'name' => $object[ 'zone_name' ], |
|
243 | + 'order' => (int) $object[ 'zone_order' ], |
|
244 | 244 | ); |
245 | 245 | } |
246 | 246 | |
@@ -255,13 +255,13 @@ discard block |
||
255 | 255 | $base = '/' . $this->namespace . '/' . $this->rest_base; |
256 | 256 | $links = array( |
257 | 257 | 'self' => array( |
258 | - 'href' => rest_url( trailingslashit( $base ) . $item['id'] ), |
|
258 | + 'href' => rest_url( trailingslashit( $base ) . $item[ 'id' ] ), |
|
259 | 259 | ), |
260 | 260 | 'collection' => array( |
261 | 261 | 'href' => rest_url( $base ), |
262 | 262 | ), |
263 | 263 | 'describedby' => array( |
264 | - 'href' => rest_url( trailingslashit( $base ) . $item['id'] . '/locations' ), |
|
264 | + 'href' => rest_url( trailingslashit( $base ) . $item[ 'id' ] . '/locations' ), |
|
265 | 265 | ), |
266 | 266 | ); |
267 | 267 |