@@ -22,7 +22,7 @@ |
||
| 22 | 22 | * |
| 23 | 23 | * @var array |
| 24 | 24 | */ |
| 25 | - protected $controllers = []; |
|
| 25 | + protected $controllers = [ ]; |
|
| 26 | 26 | |
| 27 | 27 | /** |
| 28 | 28 | * Hook into WordPress ready to init the REST API as needed. |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | |
| 197 | 197 | // Jetpack does the image resizing heavy lifting so you don't have to. |
| 198 | 198 | if ( ( class_exists( 'Jetpack' ) && Jetpack::is_module_active( 'photon' ) ) || ! apply_filters( 'woocommerce_background_image_regeneration', true ) ) { |
| 199 | - unset( $tools['regenerate_thumbnails'] ); |
|
| 199 | + unset( $tools[ 'regenerate_thumbnails' ] ); |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | return apply_filters( 'woocommerce_debug_tools', $tools ); |
@@ -211,13 +211,13 @@ discard block |
||
| 211 | 211 | public function get_items( $request ) { |
| 212 | 212 | $tools = array(); |
| 213 | 213 | foreach ( $this->get_tools() as $id => $tool ) { |
| 214 | - $tools[] = $this->prepare_response_for_collection( |
|
| 214 | + $tools[ ] = $this->prepare_response_for_collection( |
|
| 215 | 215 | $this->prepare_item_for_response( |
| 216 | 216 | array( |
| 217 | 217 | 'id' => $id, |
| 218 | - 'name' => $tool['name'], |
|
| 219 | - 'action' => $tool['button'], |
|
| 220 | - 'description' => $tool['desc'], |
|
| 218 | + 'name' => $tool[ 'name' ], |
|
| 219 | + 'action' => $tool[ 'button' ], |
|
| 220 | + 'description' => $tool[ 'desc' ], |
|
| 221 | 221 | ), |
| 222 | 222 | $request |
| 223 | 223 | ) |
@@ -236,17 +236,17 @@ discard block |
||
| 236 | 236 | */ |
| 237 | 237 | public function get_item( $request ) { |
| 238 | 238 | $tools = $this->get_tools(); |
| 239 | - if ( empty( $tools[ $request['id'] ] ) ) { |
|
| 239 | + if ( empty( $tools[ $request[ 'id' ] ] ) ) { |
|
| 240 | 240 | return new \WP_Error( 'woocommerce_rest_system_status_tool_invalid_id', __( 'Invalid tool ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
| 241 | 241 | } |
| 242 | - $tool = $tools[ $request['id'] ]; |
|
| 242 | + $tool = $tools[ $request[ 'id' ] ]; |
|
| 243 | 243 | return rest_ensure_response( |
| 244 | 244 | $this->prepare_item_for_response( |
| 245 | 245 | array( |
| 246 | - 'id' => $request['id'], |
|
| 247 | - 'name' => $tool['name'], |
|
| 248 | - 'action' => $tool['button'], |
|
| 249 | - 'description' => $tool['desc'], |
|
| 246 | + 'id' => $request[ 'id' ], |
|
| 247 | + 'name' => $tool[ 'name' ], |
|
| 248 | + 'action' => $tool[ 'button' ], |
|
| 249 | + 'description' => $tool[ 'desc' ], |
|
| 250 | 250 | ), |
| 251 | 251 | $request |
| 252 | 252 | ) |
@@ -261,19 +261,19 @@ discard block |
||
| 261 | 261 | */ |
| 262 | 262 | public function update_item( $request ) { |
| 263 | 263 | $tools = $this->get_tools(); |
| 264 | - if ( empty( $tools[ $request['id'] ] ) ) { |
|
| 264 | + if ( empty( $tools[ $request[ 'id' ] ] ) ) { |
|
| 265 | 265 | return new \WP_Error( 'woocommerce_rest_system_status_tool_invalid_id', __( 'Invalid tool ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
| 266 | 266 | } |
| 267 | 267 | |
| 268 | - $tool = $tools[ $request['id'] ]; |
|
| 268 | + $tool = $tools[ $request[ 'id' ] ]; |
|
| 269 | 269 | $tool = array( |
| 270 | - 'id' => $request['id'], |
|
| 271 | - 'name' => $tool['name'], |
|
| 272 | - 'action' => $tool['button'], |
|
| 273 | - 'description' => $tool['desc'], |
|
| 270 | + 'id' => $request[ 'id' ], |
|
| 271 | + 'name' => $tool[ 'name' ], |
|
| 272 | + 'action' => $tool[ 'button' ], |
|
| 273 | + 'description' => $tool[ 'desc' ], |
|
| 274 | 274 | ); |
| 275 | 275 | |
| 276 | - $execute_return = $this->execute_tool( $request['id'] ); |
|
| 276 | + $execute_return = $this->execute_tool( $request[ 'id' ] ); |
|
| 277 | 277 | $tool = array_merge( $tool, $execute_return ); |
| 278 | 278 | |
| 279 | 279 | /** |
@@ -297,13 +297,13 @@ discard block |
||
| 297 | 297 | * @return \WP_REST_Response $response Response data. |
| 298 | 298 | */ |
| 299 | 299 | public function prepare_item_for_response( $item, $request ) { |
| 300 | - $context = empty( $request['context'] ) ? 'view' : $request['context']; |
|
| 300 | + $context = empty( $request[ 'context' ] ) ? 'view' : $request[ 'context' ]; |
|
| 301 | 301 | $data = $this->add_additional_fields_to_object( $item, $request ); |
| 302 | 302 | $data = $this->filter_response_by_context( $data, $context ); |
| 303 | 303 | |
| 304 | 304 | $response = rest_ensure_response( $data ); |
| 305 | 305 | |
| 306 | - $response->add_links( $this->prepare_links( $item['id'] ) ); |
|
| 306 | + $response->add_links( $this->prepare_links( $item[ 'id' ] ) ); |
|
| 307 | 307 | |
| 308 | 308 | return $response; |
| 309 | 309 | } |
@@ -528,13 +528,13 @@ discard block |
||
| 528 | 528 | |
| 529 | 529 | default: |
| 530 | 530 | $tools = $this->get_tools(); |
| 531 | - if ( isset( $tools[ $tool ]['callback'] ) ) { |
|
| 532 | - $callback = $tools[ $tool ]['callback']; |
|
| 531 | + if ( isset( $tools[ $tool ][ 'callback' ] ) ) { |
|
| 532 | + $callback = $tools[ $tool ][ 'callback' ]; |
|
| 533 | 533 | $return = call_user_func( $callback ); |
| 534 | 534 | if ( is_string( $return ) ) { |
| 535 | 535 | $message = $return; |
| 536 | 536 | } elseif ( false === $return ) { |
| 537 | - $callback_string = is_array( $callback ) ? get_class( $callback[0] ) . '::' . $callback[1] : $callback; |
|
| 537 | + $callback_string = is_array( $callback ) ? get_class( $callback[ 0 ] ) . '::' . $callback[ 1 ] : $callback; |
|
| 538 | 538 | $ran = false; |
| 539 | 539 | /* translators: %s: callback string */ |
| 540 | 540 | $message = sprintf( __( 'There was an error calling %s', 'woocommerce' ), $callback_string ); |
@@ -494,7 +494,7 @@ |
||
| 494 | 494 | break; |
| 495 | 495 | |
| 496 | 496 | case 'clear_sessions': |
| 497 | - $wpdb->query( "TRUNCATE {$wpdb->prefix}woocommerce_sessions" ); |
|
| 497 | + $wpdb->query( "truncate {$wpdb->prefix}woocommerce_sessions" ); |
|
| 498 | 498 | $result = absint( $wpdb->query( "DELETE FROM {$wpdb->usermeta} WHERE meta_key='_woocommerce_persistent_cart_" . get_current_blog_id() . "';" ) ); // WPCS: unprepared SQL ok. |
| 499 | 499 | wp_cache_flush(); |
| 500 | 500 | /* translators: %d: amount of sessions */ |
@@ -152,17 +152,17 @@ discard block |
||
| 152 | 152 | * @return \WP_REST_Response |
| 153 | 153 | */ |
| 154 | 154 | public function prepare_object_for_response( $object, $request ) { |
| 155 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
| 155 | + $context = ! empty( $request[ 'context' ] ) ? $request[ 'context' ] : 'view'; |
|
| 156 | 156 | $data = $this->get_product_data( $object, $context ); |
| 157 | 157 | |
| 158 | 158 | // Add variations to variable products. |
| 159 | 159 | if ( $object->is_type( 'variable' ) && $object->has_child() ) { |
| 160 | - $data['variations'] = $object->get_children(); |
|
| 160 | + $data[ 'variations' ] = $object->get_children(); |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | // Add grouped products data. |
| 164 | 164 | if ( $object->is_type( 'grouped' ) && $object->has_child() ) { |
| 165 | - $data['grouped_products'] = $object->get_children(); |
|
| 165 | + $data[ 'grouped_products' ] = $object->get_children(); |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | $data = $this->add_additional_fields_to_object( $data, $request ); |
@@ -191,18 +191,18 @@ discard block |
||
| 191 | 191 | * @return \WP_Error|\WC_Data |
| 192 | 192 | */ |
| 193 | 193 | protected function prepare_object_for_database( $request, $creating = false ) { |
| 194 | - $id = isset( $request['id'] ) ? absint( $request['id'] ) : 0; |
|
| 194 | + $id = isset( $request[ 'id' ] ) ? absint( $request[ 'id' ] ) : 0; |
|
| 195 | 195 | |
| 196 | 196 | // Type is the most important part here because we need to be using the correct class and methods. |
| 197 | - if ( isset( $request['type'] ) ) { |
|
| 198 | - $classname = \WC_Product_Factory::get_classname_from_product_type( $request['type'] ); |
|
| 197 | + if ( isset( $request[ 'type' ] ) ) { |
|
| 198 | + $classname = \WC_Product_Factory::get_classname_from_product_type( $request[ 'type' ] ); |
|
| 199 | 199 | |
| 200 | 200 | if ( ! class_exists( $classname ) ) { |
| 201 | 201 | $classname = 'WC_Product_Simple'; |
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | $product = new $classname( $id ); |
| 205 | - } elseif ( isset( $request['id'] ) ) { |
|
| 205 | + } elseif ( isset( $request[ 'id' ] ) ) { |
|
| 206 | 206 | $product = wc_get_product( $id ); |
| 207 | 207 | } else { |
| 208 | 208 | $product = new \WC_Product_Simple(); |
@@ -219,92 +219,92 @@ discard block |
||
| 219 | 219 | } |
| 220 | 220 | |
| 221 | 221 | // Post title. |
| 222 | - if ( isset( $request['name'] ) ) { |
|
| 223 | - $product->set_name( wp_filter_post_kses( $request['name'] ) ); |
|
| 222 | + if ( isset( $request[ 'name' ] ) ) { |
|
| 223 | + $product->set_name( wp_filter_post_kses( $request[ 'name' ] ) ); |
|
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | // Post content. |
| 227 | - if ( isset( $request['description'] ) ) { |
|
| 228 | - $product->set_description( wp_filter_post_kses( $request['description'] ) ); |
|
| 227 | + if ( isset( $request[ 'description' ] ) ) { |
|
| 228 | + $product->set_description( wp_filter_post_kses( $request[ 'description' ] ) ); |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | // Post excerpt. |
| 232 | - if ( isset( $request['short_description'] ) ) { |
|
| 233 | - $product->set_short_description( wp_filter_post_kses( $request['short_description'] ) ); |
|
| 232 | + if ( isset( $request[ 'short_description' ] ) ) { |
|
| 233 | + $product->set_short_description( wp_filter_post_kses( $request[ 'short_description' ] ) ); |
|
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | // Post status. |
| 237 | - if ( isset( $request['status'] ) ) { |
|
| 238 | - $product->set_status( get_post_status_object( $request['status'] ) ? $request['status'] : 'draft' ); |
|
| 237 | + if ( isset( $request[ 'status' ] ) ) { |
|
| 238 | + $product->set_status( get_post_status_object( $request[ 'status' ] ) ? $request[ 'status' ] : 'draft' ); |
|
| 239 | 239 | } |
| 240 | 240 | |
| 241 | 241 | // Post slug. |
| 242 | - if ( isset( $request['slug'] ) ) { |
|
| 243 | - $product->set_slug( $request['slug'] ); |
|
| 242 | + if ( isset( $request[ 'slug' ] ) ) { |
|
| 243 | + $product->set_slug( $request[ 'slug' ] ); |
|
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | // Menu order. |
| 247 | - if ( isset( $request['menu_order'] ) ) { |
|
| 248 | - $product->set_menu_order( $request['menu_order'] ); |
|
| 247 | + if ( isset( $request[ 'menu_order' ] ) ) { |
|
| 248 | + $product->set_menu_order( $request[ 'menu_order' ] ); |
|
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | // Comment status. |
| 252 | - if ( isset( $request['reviews_allowed'] ) ) { |
|
| 253 | - $product->set_reviews_allowed( $request['reviews_allowed'] ); |
|
| 252 | + if ( isset( $request[ 'reviews_allowed' ] ) ) { |
|
| 253 | + $product->set_reviews_allowed( $request[ 'reviews_allowed' ] ); |
|
| 254 | 254 | } |
| 255 | 255 | |
| 256 | 256 | // Virtual. |
| 257 | - if ( isset( $request['virtual'] ) ) { |
|
| 258 | - $product->set_virtual( $request['virtual'] ); |
|
| 257 | + if ( isset( $request[ 'virtual' ] ) ) { |
|
| 258 | + $product->set_virtual( $request[ 'virtual' ] ); |
|
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | // Tax status. |
| 262 | - if ( isset( $request['tax_status'] ) ) { |
|
| 263 | - $product->set_tax_status( $request['tax_status'] ); |
|
| 262 | + if ( isset( $request[ 'tax_status' ] ) ) { |
|
| 263 | + $product->set_tax_status( $request[ 'tax_status' ] ); |
|
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | // Tax Class. |
| 267 | - if ( isset( $request['tax_class'] ) ) { |
|
| 268 | - $product->set_tax_class( $request['tax_class'] ); |
|
| 267 | + if ( isset( $request[ 'tax_class' ] ) ) { |
|
| 268 | + $product->set_tax_class( $request[ 'tax_class' ] ); |
|
| 269 | 269 | } |
| 270 | 270 | |
| 271 | 271 | // Catalog Visibility. |
| 272 | - if ( isset( $request['catalog_visibility'] ) ) { |
|
| 273 | - $product->set_catalog_visibility( $request['catalog_visibility'] ); |
|
| 272 | + if ( isset( $request[ 'catalog_visibility' ] ) ) { |
|
| 273 | + $product->set_catalog_visibility( $request[ 'catalog_visibility' ] ); |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | // Purchase Note. |
| 277 | - if ( isset( $request['purchase_note'] ) ) { |
|
| 278 | - $product->set_purchase_note( wp_kses_post( wp_unslash( $request['purchase_note'] ) ) ); |
|
| 277 | + if ( isset( $request[ 'purchase_note' ] ) ) { |
|
| 278 | + $product->set_purchase_note( wp_kses_post( wp_unslash( $request[ 'purchase_note' ] ) ) ); |
|
| 279 | 279 | } |
| 280 | 280 | |
| 281 | 281 | // Featured Product. |
| 282 | - if ( isset( $request['featured'] ) ) { |
|
| 283 | - $product->set_featured( $request['featured'] ); |
|
| 282 | + if ( isset( $request[ 'featured' ] ) ) { |
|
| 283 | + $product->set_featured( $request[ 'featured' ] ); |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | // Shipping data. |
| 287 | 287 | $product = $this->save_product_shipping_data( $product, $request ); |
| 288 | 288 | |
| 289 | 289 | // SKU. |
| 290 | - if ( isset( $request['sku'] ) ) { |
|
| 291 | - $product->set_sku( wc_clean( $request['sku'] ) ); |
|
| 290 | + if ( isset( $request[ 'sku' ] ) ) { |
|
| 291 | + $product->set_sku( wc_clean( $request[ 'sku' ] ) ); |
|
| 292 | 292 | } |
| 293 | 293 | |
| 294 | 294 | // Attributes. |
| 295 | - if ( isset( $request['attributes'] ) ) { |
|
| 295 | + if ( isset( $request[ 'attributes' ] ) ) { |
|
| 296 | 296 | $attributes = array(); |
| 297 | 297 | |
| 298 | - foreach ( $request['attributes'] as $attribute ) { |
|
| 298 | + foreach ( $request[ 'attributes' ] as $attribute ) { |
|
| 299 | 299 | $attribute_id = 0; |
| 300 | 300 | $attribute_name = ''; |
| 301 | 301 | |
| 302 | 302 | // Check ID for global attributes or name for product attributes. |
| 303 | - if ( ! empty( $attribute['id'] ) ) { |
|
| 304 | - $attribute_id = absint( $attribute['id'] ); |
|
| 303 | + if ( ! empty( $attribute[ 'id' ] ) ) { |
|
| 304 | + $attribute_id = absint( $attribute[ 'id' ] ); |
|
| 305 | 305 | $attribute_name = wc_attribute_taxonomy_name_by_id( $attribute_id ); |
| 306 | - } elseif ( ! empty( $attribute['name'] ) ) { |
|
| 307 | - $attribute_name = wc_clean( $attribute['name'] ); |
|
| 306 | + } elseif ( ! empty( $attribute[ 'name' ] ) ) { |
|
| 307 | + $attribute_name = wc_clean( $attribute[ 'name' ] ); |
|
| 308 | 308 | } |
| 309 | 309 | |
| 310 | 310 | if ( ! $attribute_id && ! $attribute_name ) { |
@@ -313,10 +313,10 @@ discard block |
||
| 313 | 313 | |
| 314 | 314 | if ( $attribute_id ) { |
| 315 | 315 | |
| 316 | - if ( isset( $attribute['options'] ) ) { |
|
| 317 | - $options = $attribute['options']; |
|
| 316 | + if ( isset( $attribute[ 'options' ] ) ) { |
|
| 317 | + $options = $attribute[ 'options' ]; |
|
| 318 | 318 | |
| 319 | - if ( ! is_array( $attribute['options'] ) ) { |
|
| 319 | + if ( ! is_array( $attribute[ 'options' ] ) ) { |
|
| 320 | 320 | // Text based attributes - Posted values are term names. |
| 321 | 321 | $options = explode( WC_DELIMITER, $options ); |
| 322 | 322 | } |
@@ -333,25 +333,25 @@ discard block |
||
| 333 | 333 | $attribute_object->set_id( $attribute_id ); |
| 334 | 334 | $attribute_object->set_name( $attribute_name ); |
| 335 | 335 | $attribute_object->set_options( $values ); |
| 336 | - $attribute_object->set_position( isset( $attribute['position'] ) ? (string) absint( $attribute['position'] ) : '0' ); |
|
| 337 | - $attribute_object->set_visible( ( isset( $attribute['visible'] ) && $attribute['visible'] ) ? 1 : 0 ); |
|
| 338 | - $attribute_object->set_variation( ( isset( $attribute['variation'] ) && $attribute['variation'] ) ? 1 : 0 ); |
|
| 339 | - $attributes[] = $attribute_object; |
|
| 336 | + $attribute_object->set_position( isset( $attribute[ 'position' ] ) ? (string) absint( $attribute[ 'position' ] ) : '0' ); |
|
| 337 | + $attribute_object->set_visible( ( isset( $attribute[ 'visible' ] ) && $attribute[ 'visible' ] ) ? 1 : 0 ); |
|
| 338 | + $attribute_object->set_variation( ( isset( $attribute[ 'variation' ] ) && $attribute[ 'variation' ] ) ? 1 : 0 ); |
|
| 339 | + $attributes[ ] = $attribute_object; |
|
| 340 | 340 | } |
| 341 | - } elseif ( isset( $attribute['options'] ) ) { |
|
| 341 | + } elseif ( isset( $attribute[ 'options' ] ) ) { |
|
| 342 | 342 | // Custom attribute - Add attribute to array and set the values. |
| 343 | - if ( is_array( $attribute['options'] ) ) { |
|
| 344 | - $values = $attribute['options']; |
|
| 343 | + if ( is_array( $attribute[ 'options' ] ) ) { |
|
| 344 | + $values = $attribute[ 'options' ]; |
|
| 345 | 345 | } else { |
| 346 | - $values = explode( WC_DELIMITER, $attribute['options'] ); |
|
| 346 | + $values = explode( WC_DELIMITER, $attribute[ 'options' ] ); |
|
| 347 | 347 | } |
| 348 | 348 | $attribute_object = new \WC_Product_Attribute(); |
| 349 | 349 | $attribute_object->set_name( $attribute_name ); |
| 350 | 350 | $attribute_object->set_options( $values ); |
| 351 | - $attribute_object->set_position( isset( $attribute['position'] ) ? (string) absint( $attribute['position'] ) : '0' ); |
|
| 352 | - $attribute_object->set_visible( ( isset( $attribute['visible'] ) && $attribute['visible'] ) ? 1 : 0 ); |
|
| 353 | - $attribute_object->set_variation( ( isset( $attribute['variation'] ) && $attribute['variation'] ) ? 1 : 0 ); |
|
| 354 | - $attributes[] = $attribute_object; |
|
| 351 | + $attribute_object->set_position( isset( $attribute[ 'position' ] ) ? (string) absint( $attribute[ 'position' ] ) : '0' ); |
|
| 352 | + $attribute_object->set_visible( ( isset( $attribute[ 'visible' ] ) && $attribute[ 'visible' ] ) ? 1 : 0 ); |
|
| 353 | + $attribute_object->set_variation( ( isset( $attribute[ 'variation' ] ) && $attribute[ 'variation' ] ) ? 1 : 0 ); |
|
| 354 | + $attributes[ ] = $attribute_object; |
|
| 355 | 355 | } |
| 356 | 356 | } |
| 357 | 357 | $product->set_attributes( $attributes ); |
@@ -366,45 +366,45 @@ discard block |
||
| 366 | 366 | $product->set_price( '' ); |
| 367 | 367 | } else { |
| 368 | 368 | // Regular Price. |
| 369 | - if ( isset( $request['regular_price'] ) ) { |
|
| 370 | - $product->set_regular_price( $request['regular_price'] ); |
|
| 369 | + if ( isset( $request[ 'regular_price' ] ) ) { |
|
| 370 | + $product->set_regular_price( $request[ 'regular_price' ] ); |
|
| 371 | 371 | } |
| 372 | 372 | |
| 373 | 373 | // Sale Price. |
| 374 | - if ( isset( $request['sale_price'] ) ) { |
|
| 375 | - $product->set_sale_price( $request['sale_price'] ); |
|
| 374 | + if ( isset( $request[ 'sale_price' ] ) ) { |
|
| 375 | + $product->set_sale_price( $request[ 'sale_price' ] ); |
|
| 376 | 376 | } |
| 377 | 377 | |
| 378 | - if ( isset( $request['date_on_sale_from'] ) ) { |
|
| 379 | - $product->set_date_on_sale_from( $request['date_on_sale_from'] ); |
|
| 378 | + if ( isset( $request[ 'date_on_sale_from' ] ) ) { |
|
| 379 | + $product->set_date_on_sale_from( $request[ 'date_on_sale_from' ] ); |
|
| 380 | 380 | } |
| 381 | 381 | |
| 382 | - if ( isset( $request['date_on_sale_from_gmt'] ) ) { |
|
| 383 | - $product->set_date_on_sale_from( $request['date_on_sale_from_gmt'] ? strtotime( $request['date_on_sale_from_gmt'] ) : null ); |
|
| 382 | + if ( isset( $request[ 'date_on_sale_from_gmt' ] ) ) { |
|
| 383 | + $product->set_date_on_sale_from( $request[ 'date_on_sale_from_gmt' ] ? strtotime( $request[ 'date_on_sale_from_gmt' ] ) : null ); |
|
| 384 | 384 | } |
| 385 | 385 | |
| 386 | - if ( isset( $request['date_on_sale_to'] ) ) { |
|
| 387 | - $product->set_date_on_sale_to( $request['date_on_sale_to'] ); |
|
| 386 | + if ( isset( $request[ 'date_on_sale_to' ] ) ) { |
|
| 387 | + $product->set_date_on_sale_to( $request[ 'date_on_sale_to' ] ); |
|
| 388 | 388 | } |
| 389 | 389 | |
| 390 | - if ( isset( $request['date_on_sale_to_gmt'] ) ) { |
|
| 391 | - $product->set_date_on_sale_to( $request['date_on_sale_to_gmt'] ? strtotime( $request['date_on_sale_to_gmt'] ) : null ); |
|
| 390 | + if ( isset( $request[ 'date_on_sale_to_gmt' ] ) ) { |
|
| 391 | + $product->set_date_on_sale_to( $request[ 'date_on_sale_to_gmt' ] ? strtotime( $request[ 'date_on_sale_to_gmt' ] ) : null ); |
|
| 392 | 392 | } |
| 393 | 393 | } |
| 394 | 394 | |
| 395 | 395 | // Product parent ID. |
| 396 | - if ( isset( $request['parent_id'] ) ) { |
|
| 397 | - $product->set_parent_id( $request['parent_id'] ); |
|
| 396 | + if ( isset( $request[ 'parent_id' ] ) ) { |
|
| 397 | + $product->set_parent_id( $request[ 'parent_id' ] ); |
|
| 398 | 398 | } |
| 399 | 399 | |
| 400 | 400 | // Sold individually. |
| 401 | - if ( isset( $request['sold_individually'] ) ) { |
|
| 402 | - $product->set_sold_individually( $request['sold_individually'] ); |
|
| 401 | + if ( isset( $request[ 'sold_individually' ] ) ) { |
|
| 402 | + $product->set_sold_individually( $request[ 'sold_individually' ] ); |
|
| 403 | 403 | } |
| 404 | 404 | |
| 405 | 405 | // Stock status; stock_status has priority over in_stock. |
| 406 | - if ( isset( $request['stock_status'] ) ) { |
|
| 407 | - $stock_status = $request['stock_status']; |
|
| 406 | + if ( isset( $request[ 'stock_status' ] ) ) { |
|
| 407 | + $stock_status = $request[ 'stock_status' ]; |
|
| 408 | 408 | } else { |
| 409 | 409 | $stock_status = $product->get_stock_status(); |
| 410 | 410 | } |
@@ -412,13 +412,13 @@ discard block |
||
| 412 | 412 | // Stock data. |
| 413 | 413 | if ( 'yes' === get_option( 'woocommerce_manage_stock' ) ) { |
| 414 | 414 | // Manage stock. |
| 415 | - if ( isset( $request['manage_stock'] ) ) { |
|
| 416 | - $product->set_manage_stock( $request['manage_stock'] ); |
|
| 415 | + if ( isset( $request[ 'manage_stock' ] ) ) { |
|
| 416 | + $product->set_manage_stock( $request[ 'manage_stock' ] ); |
|
| 417 | 417 | } |
| 418 | 418 | |
| 419 | 419 | // Backorders. |
| 420 | - if ( isset( $request['backorders'] ) ) { |
|
| 421 | - $product->set_backorders( $request['backorders'] ); |
|
| 420 | + if ( isset( $request[ 'backorders' ] ) ) { |
|
| 421 | + $product->set_backorders( $request[ 'backorders' ] ); |
|
| 422 | 422 | } |
| 423 | 423 | |
| 424 | 424 | if ( $product->is_type( 'grouped' ) ) { |
@@ -438,11 +438,11 @@ discard block |
||
| 438 | 438 | } |
| 439 | 439 | |
| 440 | 440 | // Stock quantity. |
| 441 | - if ( isset( $request['stock_quantity'] ) ) { |
|
| 442 | - $product->set_stock_quantity( wc_stock_amount( $request['stock_quantity'] ) ); |
|
| 443 | - } elseif ( isset( $request['inventory_delta'] ) ) { |
|
| 441 | + if ( isset( $request[ 'stock_quantity' ] ) ) { |
|
| 442 | + $product->set_stock_quantity( wc_stock_amount( $request[ 'stock_quantity' ] ) ); |
|
| 443 | + } elseif ( isset( $request[ 'inventory_delta' ] ) ) { |
|
| 444 | 444 | $stock_quantity = wc_stock_amount( $product->get_stock_quantity() ); |
| 445 | - $stock_quantity += wc_stock_amount( $request['inventory_delta'] ); |
|
| 445 | + $stock_quantity += wc_stock_amount( $request[ 'inventory_delta' ] ); |
|
| 446 | 446 | $product->set_stock_quantity( wc_stock_amount( $stock_quantity ) ); |
| 447 | 447 | } |
| 448 | 448 | } else { |
@@ -456,14 +456,14 @@ discard block |
||
| 456 | 456 | } |
| 457 | 457 | |
| 458 | 458 | // Upsells. |
| 459 | - if ( isset( $request['upsell_ids'] ) ) { |
|
| 459 | + if ( isset( $request[ 'upsell_ids' ] ) ) { |
|
| 460 | 460 | $upsells = array(); |
| 461 | - $ids = $request['upsell_ids']; |
|
| 461 | + $ids = $request[ 'upsell_ids' ]; |
|
| 462 | 462 | |
| 463 | 463 | if ( ! empty( $ids ) ) { |
| 464 | 464 | foreach ( $ids as $id ) { |
| 465 | 465 | if ( $id && $id > 0 ) { |
| 466 | - $upsells[] = $id; |
|
| 466 | + $upsells[ ] = $id; |
|
| 467 | 467 | } |
| 468 | 468 | } |
| 469 | 469 | } |
@@ -472,14 +472,14 @@ discard block |
||
| 472 | 472 | } |
| 473 | 473 | |
| 474 | 474 | // Cross sells. |
| 475 | - if ( isset( $request['cross_sell_ids'] ) ) { |
|
| 475 | + if ( isset( $request[ 'cross_sell_ids' ] ) ) { |
|
| 476 | 476 | $crosssells = array(); |
| 477 | - $ids = $request['cross_sell_ids']; |
|
| 477 | + $ids = $request[ 'cross_sell_ids' ]; |
|
| 478 | 478 | |
| 479 | 479 | if ( ! empty( $ids ) ) { |
| 480 | 480 | foreach ( $ids as $id ) { |
| 481 | 481 | if ( $id && $id > 0 ) { |
| 482 | - $crosssells[] = $id; |
|
| 482 | + $crosssells[ ] = $id; |
|
| 483 | 483 | } |
| 484 | 484 | } |
| 485 | 485 | } |
@@ -488,47 +488,47 @@ discard block |
||
| 488 | 488 | } |
| 489 | 489 | |
| 490 | 490 | // Product categories. |
| 491 | - if ( isset( $request['categories'] ) && is_array( $request['categories'] ) ) { |
|
| 492 | - $product = $this->save_taxonomy_terms( $product, $request['categories'] ); |
|
| 491 | + if ( isset( $request[ 'categories' ] ) && is_array( $request[ 'categories' ] ) ) { |
|
| 492 | + $product = $this->save_taxonomy_terms( $product, $request[ 'categories' ] ); |
|
| 493 | 493 | } |
| 494 | 494 | |
| 495 | 495 | // Product tags. |
| 496 | - if ( isset( $request['tags'] ) && is_array( $request['tags'] ) ) { |
|
| 497 | - $product = $this->save_taxonomy_terms( $product, $request['tags'], 'tag' ); |
|
| 496 | + if ( isset( $request[ 'tags' ] ) && is_array( $request[ 'tags' ] ) ) { |
|
| 497 | + $product = $this->save_taxonomy_terms( $product, $request[ 'tags' ], 'tag' ); |
|
| 498 | 498 | } |
| 499 | 499 | |
| 500 | 500 | // Downloadable. |
| 501 | - if ( isset( $request['downloadable'] ) ) { |
|
| 502 | - $product->set_downloadable( $request['downloadable'] ); |
|
| 501 | + if ( isset( $request[ 'downloadable' ] ) ) { |
|
| 502 | + $product->set_downloadable( $request[ 'downloadable' ] ); |
|
| 503 | 503 | } |
| 504 | 504 | |
| 505 | 505 | // Downloadable options. |
| 506 | 506 | if ( $product->get_downloadable() ) { |
| 507 | 507 | |
| 508 | 508 | // Downloadable files. |
| 509 | - if ( isset( $request['downloads'] ) && is_array( $request['downloads'] ) ) { |
|
| 510 | - $product = $this->save_downloadable_files( $product, $request['downloads'] ); |
|
| 509 | + if ( isset( $request[ 'downloads' ] ) && is_array( $request[ 'downloads' ] ) ) { |
|
| 510 | + $product = $this->save_downloadable_files( $product, $request[ 'downloads' ] ); |
|
| 511 | 511 | } |
| 512 | 512 | |
| 513 | 513 | // Download limit. |
| 514 | - if ( isset( $request['download_limit'] ) ) { |
|
| 515 | - $product->set_download_limit( $request['download_limit'] ); |
|
| 514 | + if ( isset( $request[ 'download_limit' ] ) ) { |
|
| 515 | + $product->set_download_limit( $request[ 'download_limit' ] ); |
|
| 516 | 516 | } |
| 517 | 517 | |
| 518 | 518 | // Download expiry. |
| 519 | - if ( isset( $request['download_expiry'] ) ) { |
|
| 520 | - $product->set_download_expiry( $request['download_expiry'] ); |
|
| 519 | + if ( isset( $request[ 'download_expiry' ] ) ) { |
|
| 520 | + $product->set_download_expiry( $request[ 'download_expiry' ] ); |
|
| 521 | 521 | } |
| 522 | 522 | } |
| 523 | 523 | |
| 524 | 524 | // Product url and button text for external products. |
| 525 | 525 | if ( $product->is_type( 'external' ) ) { |
| 526 | - if ( isset( $request['external_url'] ) ) { |
|
| 527 | - $product->set_product_url( $request['external_url'] ); |
|
| 526 | + if ( isset( $request[ 'external_url' ] ) ) { |
|
| 527 | + $product->set_product_url( $request[ 'external_url' ] ); |
|
| 528 | 528 | } |
| 529 | 529 | |
| 530 | - if ( isset( $request['button_text'] ) ) { |
|
| 531 | - $product->set_button_text( $request['button_text'] ); |
|
| 530 | + if ( isset( $request[ 'button_text' ] ) ) { |
|
| 531 | + $product->set_button_text( $request[ 'button_text' ] ); |
|
| 532 | 532 | } |
| 533 | 533 | } |
| 534 | 534 | |
@@ -538,46 +538,46 @@ discard block |
||
| 538 | 538 | } |
| 539 | 539 | |
| 540 | 540 | // Set children for a grouped product. |
| 541 | - if ( $product->is_type( 'grouped' ) && isset( $request['grouped_products'] ) ) { |
|
| 542 | - $product->set_children( $request['grouped_products'] ); |
|
| 541 | + if ( $product->is_type( 'grouped' ) && isset( $request[ 'grouped_products' ] ) ) { |
|
| 542 | + $product->set_children( $request[ 'grouped_products' ] ); |
|
| 543 | 543 | } |
| 544 | 544 | |
| 545 | 545 | // Check for featured/gallery images, upload it and set it. |
| 546 | - if ( isset( $request['images'] ) ) { |
|
| 547 | - $product = $this->set_product_images( $product, $request['images'] ); |
|
| 546 | + if ( isset( $request[ 'images' ] ) ) { |
|
| 547 | + $product = $this->set_product_images( $product, $request[ 'images' ] ); |
|
| 548 | 548 | } |
| 549 | 549 | |
| 550 | 550 | // Allow set meta_data. |
| 551 | - if ( is_array( $request['meta_data'] ) ) { |
|
| 552 | - foreach ( $request['meta_data'] as $meta ) { |
|
| 553 | - $product->update_meta_data( $meta['key'], $meta['value'], isset( $meta['id'] ) ? $meta['id'] : '' ); |
|
| 551 | + if ( is_array( $request[ 'meta_data' ] ) ) { |
|
| 552 | + foreach ( $request[ 'meta_data' ] as $meta ) { |
|
| 553 | + $product->update_meta_data( $meta[ 'key' ], $meta[ 'value' ], isset( $meta[ 'id' ] ) ? $meta[ 'id' ] : '' ); |
|
| 554 | 554 | } |
| 555 | 555 | } |
| 556 | 556 | |
| 557 | - if ( ! empty( $request['date_created'] ) ) { |
|
| 558 | - $date = rest_parse_date( $request['date_created'] ); |
|
| 557 | + if ( ! empty( $request[ 'date_created' ] ) ) { |
|
| 558 | + $date = rest_parse_date( $request[ 'date_created' ] ); |
|
| 559 | 559 | |
| 560 | 560 | if ( $date ) { |
| 561 | 561 | $product->set_date_created( $date ); |
| 562 | 562 | } |
| 563 | 563 | } |
| 564 | 564 | |
| 565 | - if ( ! empty( $request['date_created_gmt'] ) ) { |
|
| 566 | - $date = rest_parse_date( $request['date_created_gmt'], true ); |
|
| 565 | + if ( ! empty( $request[ 'date_created_gmt' ] ) ) { |
|
| 566 | + $date = rest_parse_date( $request[ 'date_created_gmt' ], true ); |
|
| 567 | 567 | |
| 568 | 568 | if ( $date ) { |
| 569 | 569 | $product->set_date_created( $date ); |
| 570 | 570 | } |
| 571 | 571 | } |
| 572 | 572 | |
| 573 | - if ( ! empty( $request['search'] ) ) { |
|
| 574 | - $args['search'] = trim( $request['search'] ); |
|
| 575 | - unset( $args['s'] ); |
|
| 573 | + if ( ! empty( $request[ 'search' ] ) ) { |
|
| 574 | + $args[ 'search' ] = trim( $request[ 'search' ] ); |
|
| 575 | + unset( $args[ 's' ] ); |
|
| 576 | 576 | } |
| 577 | 577 | |
| 578 | - if ( ! empty( $request['low_in_stock'] ) ) { |
|
| 579 | - $args['low_in_stock'] = $request['low_in_stock']; |
|
| 580 | - $args['post_type'] = array( 'product', 'product_variation' ); |
|
| 578 | + if ( ! empty( $request[ 'low_in_stock' ] ) ) { |
|
| 579 | + $args[ 'low_in_stock' ] = $request[ 'low_in_stock' ]; |
|
| 580 | + $args[ 'post_type' ] = array( 'product', 'product_variation' ); |
|
| 581 | 581 | } |
| 582 | 582 | |
| 583 | 583 | /** |
@@ -699,7 +699,7 @@ discard block |
||
| 699 | 699 | $args = parent::prepare_objects_query( $request ); |
| 700 | 700 | |
| 701 | 701 | // Set post_status. |
| 702 | - $args['post_status'] = $request['status']; |
|
| 702 | + $args[ 'post_status' ] = $request[ 'status' ]; |
|
| 703 | 703 | |
| 704 | 704 | // Taxonomy query to filter products by type, category, |
| 705 | 705 | // tag, shipping class, and attribute. |
@@ -715,7 +715,7 @@ discard block |
||
| 715 | 715 | // Set tax_query for each passed arg. |
| 716 | 716 | foreach ( $taxonomies as $taxonomy => $key ) { |
| 717 | 717 | if ( ! empty( $request[ $key ] ) ) { |
| 718 | - $tax_query[] = array( |
|
| 718 | + $tax_query[ ] = array( |
|
| 719 | 719 | 'taxonomy' => $taxonomy, |
| 720 | 720 | 'field' => 'term_id', |
| 721 | 721 | 'terms' => $request[ $key ], |
@@ -724,53 +724,53 @@ discard block |
||
| 724 | 724 | } |
| 725 | 725 | |
| 726 | 726 | // Filter product type by slug. |
| 727 | - if ( ! empty( $request['type'] ) ) { |
|
| 728 | - $tax_query[] = array( |
|
| 727 | + if ( ! empty( $request[ 'type' ] ) ) { |
|
| 728 | + $tax_query[ ] = array( |
|
| 729 | 729 | 'taxonomy' => 'product_type', |
| 730 | 730 | 'field' => 'slug', |
| 731 | - 'terms' => $request['type'], |
|
| 731 | + 'terms' => $request[ 'type' ], |
|
| 732 | 732 | ); |
| 733 | 733 | } |
| 734 | 734 | |
| 735 | 735 | // Filter by attribute and term. |
| 736 | - if ( ! empty( $request['attribute'] ) && ! empty( $request['attribute_term'] ) ) { |
|
| 737 | - if ( in_array( $request['attribute'], wc_get_attribute_taxonomy_names(), true ) ) { |
|
| 738 | - $tax_query[] = array( |
|
| 739 | - 'taxonomy' => $request['attribute'], |
|
| 736 | + if ( ! empty( $request[ 'attribute' ] ) && ! empty( $request[ 'attribute_term' ] ) ) { |
|
| 737 | + if ( in_array( $request[ 'attribute' ], wc_get_attribute_taxonomy_names(), true ) ) { |
|
| 738 | + $tax_query[ ] = array( |
|
| 739 | + 'taxonomy' => $request[ 'attribute' ], |
|
| 740 | 740 | 'field' => 'term_id', |
| 741 | - 'terms' => $request['attribute_term'], |
|
| 741 | + 'terms' => $request[ 'attribute_term' ], |
|
| 742 | 742 | ); |
| 743 | 743 | } |
| 744 | 744 | } |
| 745 | 745 | |
| 746 | 746 | // Build tax_query if taxonomies are set. |
| 747 | 747 | if ( ! empty( $tax_query ) ) { |
| 748 | - if ( ! empty( $args['tax_query'] ) ) { |
|
| 749 | - $args['tax_query'] = array_merge( $tax_query, $args['tax_query'] ); // WPCS: slow query ok. |
|
| 748 | + if ( ! empty( $args[ 'tax_query' ] ) ) { |
|
| 749 | + $args[ 'tax_query' ] = array_merge( $tax_query, $args[ 'tax_query' ] ); // WPCS: slow query ok. |
|
| 750 | 750 | } else { |
| 751 | - $args['tax_query'] = $tax_query; // WPCS: slow query ok. |
|
| 751 | + $args[ 'tax_query' ] = $tax_query; // WPCS: slow query ok. |
|
| 752 | 752 | } |
| 753 | 753 | } |
| 754 | 754 | |
| 755 | 755 | // Filter featured. |
| 756 | - if ( is_bool( $request['featured'] ) ) { |
|
| 757 | - $args['tax_query'][] = array( |
|
| 756 | + if ( is_bool( $request[ 'featured' ] ) ) { |
|
| 757 | + $args[ 'tax_query' ][ ] = array( |
|
| 758 | 758 | 'taxonomy' => 'product_visibility', |
| 759 | 759 | 'field' => 'name', |
| 760 | 760 | 'terms' => 'featured', |
| 761 | - 'operator' => true === $request['featured'] ? 'IN' : 'NOT IN', |
|
| 761 | + 'operator' => true === $request[ 'featured' ] ? 'IN' : 'NOT IN', |
|
| 762 | 762 | ); |
| 763 | 763 | } |
| 764 | 764 | |
| 765 | 765 | // Filter by sku. |
| 766 | - if ( ! empty( $request['sku'] ) ) { |
|
| 767 | - $skus = explode( ',', $request['sku'] ); |
|
| 766 | + if ( ! empty( $request[ 'sku' ] ) ) { |
|
| 767 | + $skus = explode( ',', $request[ 'sku' ] ); |
|
| 768 | 768 | // Include the current string as a SKU too. |
| 769 | 769 | if ( 1 < count( $skus ) ) { |
| 770 | - $skus[] = $request['sku']; |
|
| 770 | + $skus[ ] = $request[ 'sku' ]; |
|
| 771 | 771 | } |
| 772 | 772 | |
| 773 | - $args['meta_query'] = $this->add_meta_query( // WPCS: slow query ok. |
|
| 773 | + $args[ 'meta_query' ] = $this->add_meta_query( // WPCS: slow query ok. |
|
| 774 | 774 | $args, |
| 775 | 775 | array( |
| 776 | 776 | 'key' => '_sku', |
@@ -781,35 +781,35 @@ discard block |
||
| 781 | 781 | } |
| 782 | 782 | |
| 783 | 783 | // Filter by tax class. |
| 784 | - if ( ! empty( $request['tax_class'] ) ) { |
|
| 785 | - $args['meta_query'] = $this->add_meta_query( // WPCS: slow query ok. |
|
| 784 | + if ( ! empty( $request[ 'tax_class' ] ) ) { |
|
| 785 | + $args[ 'meta_query' ] = $this->add_meta_query( // WPCS: slow query ok. |
|
| 786 | 786 | $args, |
| 787 | 787 | array( |
| 788 | 788 | 'key' => '_tax_class', |
| 789 | - 'value' => 'standard' !== $request['tax_class'] ? $request['tax_class'] : '', |
|
| 789 | + 'value' => 'standard' !== $request[ 'tax_class' ] ? $request[ 'tax_class' ] : '', |
|
| 790 | 790 | ) |
| 791 | 791 | ); |
| 792 | 792 | } |
| 793 | 793 | |
| 794 | 794 | // Price filter. |
| 795 | - if ( ! empty( $request['min_price'] ) || ! empty( $request['max_price'] ) ) { |
|
| 796 | - $args['meta_query'] = $this->add_meta_query( $args, wc_get_min_max_price_meta_query( $request ) ); // WPCS: slow query ok. |
|
| 795 | + if ( ! empty( $request[ 'min_price' ] ) || ! empty( $request[ 'max_price' ] ) ) { |
|
| 796 | + $args[ 'meta_query' ] = $this->add_meta_query( $args, wc_get_min_max_price_meta_query( $request ) ); // WPCS: slow query ok. |
|
| 797 | 797 | } |
| 798 | 798 | |
| 799 | 799 | // Filter product by stock_status. |
| 800 | - if ( ! empty( $request['stock_status'] ) ) { |
|
| 801 | - $args['meta_query'] = $this->add_meta_query( // WPCS: slow query ok. |
|
| 800 | + if ( ! empty( $request[ 'stock_status' ] ) ) { |
|
| 801 | + $args[ 'meta_query' ] = $this->add_meta_query( // WPCS: slow query ok. |
|
| 802 | 802 | $args, |
| 803 | 803 | array( |
| 804 | 804 | 'key' => '_stock_status', |
| 805 | - 'value' => $request['stock_status'], |
|
| 805 | + 'value' => $request[ 'stock_status' ], |
|
| 806 | 806 | ) |
| 807 | 807 | ); |
| 808 | 808 | } |
| 809 | 809 | |
| 810 | 810 | // Filter by on sale products. |
| 811 | - if ( is_bool( $request['on_sale'] ) ) { |
|
| 812 | - $on_sale_key = $request['on_sale'] ? 'post__in' : 'post__not_in'; |
|
| 811 | + if ( is_bool( $request[ 'on_sale' ] ) ) { |
|
| 812 | + $on_sale_key = $request[ 'on_sale' ] ? 'post__in' : 'post__not_in'; |
|
| 813 | 813 | $on_sale_ids = wc_get_product_ids_on_sale(); |
| 814 | 814 | |
| 815 | 815 | // Use 0 when there's no on sale products to avoid return all products. |
@@ -819,20 +819,20 @@ discard block |
||
| 819 | 819 | } |
| 820 | 820 | |
| 821 | 821 | // Force the post_type argument, since it's not a user input variable. |
| 822 | - if ( ! empty( $request['sku'] ) ) { |
|
| 823 | - $args['post_type'] = array( 'product', 'product_variation' ); |
|
| 822 | + if ( ! empty( $request[ 'sku' ] ) ) { |
|
| 823 | + $args[ 'post_type' ] = array( 'product', 'product_variation' ); |
|
| 824 | 824 | } else { |
| 825 | - $args['post_type'] = $this->post_type; |
|
| 825 | + $args[ 'post_type' ] = $this->post_type; |
|
| 826 | 826 | } |
| 827 | 827 | |
| 828 | 828 | $orderby = $request->get_param( 'orderby' ); |
| 829 | 829 | $order = $request->get_param( 'order' ); |
| 830 | 830 | |
| 831 | 831 | $ordering_args = WC()->query->get_catalog_ordering_args( $orderby, $order ); |
| 832 | - $args['orderby'] = $ordering_args['orderby']; |
|
| 833 | - $args['order'] = $ordering_args['order']; |
|
| 834 | - if ( $ordering_args['meta_key'] ) { |
|
| 835 | - $args['meta_key'] = $ordering_args['meta_key']; // WPCS: slow query ok. |
|
| 832 | + $args[ 'orderby' ] = $ordering_args[ 'orderby' ]; |
|
| 833 | + $args[ 'order' ] = $ordering_args[ 'order' ]; |
|
| 834 | + if ( $ordering_args[ 'meta_key' ] ) { |
|
| 835 | + $args[ 'meta_key' ] = $ordering_args[ 'meta_key' ]; // WPCS: slow query ok. |
|
| 836 | 836 | } |
| 837 | 837 | |
| 838 | 838 | return $args; |
@@ -850,10 +850,10 @@ discard block |
||
| 850 | 850 | |
| 851 | 851 | if ( $product->is_downloadable() ) { |
| 852 | 852 | foreach ( $product->get_downloads() as $file_id => $file ) { |
| 853 | - $downloads[] = array( |
|
| 853 | + $downloads[ ] = array( |
|
| 854 | 854 | 'id' => $file_id, // MD5 hash. |
| 855 | - 'name' => $file['name'], |
|
| 856 | - 'file' => $file['file'], |
|
| 855 | + 'name' => $file[ 'name' ], |
|
| 856 | + 'file' => $file[ 'file' ], |
|
| 857 | 857 | ); |
| 858 | 858 | } |
| 859 | 859 | } |
@@ -873,7 +873,7 @@ discard block |
||
| 873 | 873 | $terms = array(); |
| 874 | 874 | |
| 875 | 875 | foreach ( wc_get_object_terms( $product->get_id(), 'product_' . $taxonomy ) as $term ) { |
| 876 | - $terms[] = array( |
|
| 876 | + $terms[ ] = array( |
|
| 877 | 877 | 'id' => $term->term_id, |
| 878 | 878 | 'name' => $term->name, |
| 879 | 879 | 'slug' => $term->slug, |
@@ -895,7 +895,7 @@ discard block |
||
| 895 | 895 | |
| 896 | 896 | // Add featured image. |
| 897 | 897 | if ( $product->get_image_id() ) { |
| 898 | - $attachment_ids[] = $product->get_image_id(); |
|
| 898 | + $attachment_ids[ ] = $product->get_image_id(); |
|
| 899 | 899 | } |
| 900 | 900 | |
| 901 | 901 | // Add gallery images. |
@@ -913,7 +913,7 @@ discard block |
||
| 913 | 913 | continue; |
| 914 | 914 | } |
| 915 | 915 | |
| 916 | - $images[] = array( |
|
| 916 | + $images[ ] = array( |
|
| 917 | 917 | 'id' => (int) $attachment_id, |
| 918 | 918 | 'date_created' => wc_rest_prepare_date_response( $attachment_post->post_date, false ), |
| 919 | 919 | 'date_created_gmt' => wc_rest_prepare_date_response( strtotime( $attachment_post->post_date_gmt ) ), |
@@ -992,13 +992,13 @@ discard block |
||
| 992 | 992 | if ( $product->is_type( 'variable' ) ) { |
| 993 | 993 | foreach ( array_filter( (array) $product->get_default_attributes(), 'strlen' ) as $key => $value ) { |
| 994 | 994 | if ( 0 === strpos( $key, 'pa_' ) ) { |
| 995 | - $default[] = array( |
|
| 995 | + $default[ ] = array( |
|
| 996 | 996 | 'id' => wc_attribute_taxonomy_id_by_name( $key ), |
| 997 | 997 | 'name' => $this->get_attribute_taxonomy_name( $key, $product ), |
| 998 | 998 | 'option' => $value, |
| 999 | 999 | ); |
| 1000 | 1000 | } else { |
| 1001 | - $default[] = array( |
|
| 1001 | + $default[ ] = array( |
|
| 1002 | 1002 | 'id' => 0, |
| 1003 | 1003 | 'name' => $this->get_attribute_taxonomy_name( $key, $product ), |
| 1004 | 1004 | 'option' => $value, |
@@ -1019,16 +1019,16 @@ discard block |
||
| 1019 | 1019 | * @return array |
| 1020 | 1020 | */ |
| 1021 | 1021 | protected function get_attribute_options( $product_id, $attribute ) { |
| 1022 | - if ( isset( $attribute['is_taxonomy'] ) && $attribute['is_taxonomy'] ) { |
|
| 1022 | + if ( isset( $attribute[ 'is_taxonomy' ] ) && $attribute[ 'is_taxonomy' ] ) { |
|
| 1023 | 1023 | return wc_get_product_terms( |
| 1024 | 1024 | $product_id, |
| 1025 | - $attribute['name'], |
|
| 1025 | + $attribute[ 'name' ], |
|
| 1026 | 1026 | array( |
| 1027 | 1027 | 'fields' => 'names', |
| 1028 | 1028 | ) |
| 1029 | 1029 | ); |
| 1030 | - } elseif ( isset( $attribute['value'] ) ) { |
|
| 1031 | - return array_map( 'trim', explode( '|', $attribute['value'] ) ); |
|
| 1030 | + } elseif ( isset( $attribute[ 'value' ] ) ) { |
|
| 1031 | + return array_map( 'trim', explode( '|', $attribute[ 'value' ] ) ); |
|
| 1032 | 1032 | } |
| 1033 | 1033 | |
| 1034 | 1034 | return array(); |
@@ -1056,13 +1056,13 @@ discard block |
||
| 1056 | 1056 | // Taxonomy-based attributes are prefixed with `pa_`, otherwise simply `attribute_`. |
| 1057 | 1057 | if ( 0 === strpos( $attribute_name, 'attribute_pa_' ) ) { |
| 1058 | 1058 | $option_term = get_term_by( 'slug', $attribute, $name ); |
| 1059 | - $attributes[] = array( |
|
| 1059 | + $attributes[ ] = array( |
|
| 1060 | 1060 | 'id' => wc_attribute_taxonomy_id_by_name( $name ), |
| 1061 | 1061 | 'name' => $this->get_attribute_taxonomy_name( $name, $_product ), |
| 1062 | 1062 | 'option' => $option_term && ! is_wp_error( $option_term ) ? $option_term->name : $attribute, |
| 1063 | 1063 | ); |
| 1064 | 1064 | } else { |
| 1065 | - $attributes[] = array( |
|
| 1065 | + $attributes[ ] = array( |
|
| 1066 | 1066 | 'id' => 0, |
| 1067 | 1067 | 'name' => $this->get_attribute_taxonomy_name( $name, $_product ), |
| 1068 | 1068 | 'option' => $attribute, |
@@ -1071,12 +1071,12 @@ discard block |
||
| 1071 | 1071 | } |
| 1072 | 1072 | } else { |
| 1073 | 1073 | foreach ( $product->get_attributes() as $attribute ) { |
| 1074 | - $attributes[] = array( |
|
| 1075 | - 'id' => $attribute['is_taxonomy'] ? wc_attribute_taxonomy_id_by_name( $attribute['name'] ) : 0, |
|
| 1076 | - 'name' => $this->get_attribute_taxonomy_name( $attribute['name'], $product ), |
|
| 1077 | - 'position' => (int) $attribute['position'], |
|
| 1078 | - 'visible' => (bool) $attribute['is_visible'], |
|
| 1079 | - 'variation' => (bool) $attribute['is_variation'], |
|
| 1074 | + $attributes[ ] = array( |
|
| 1075 | + 'id' => $attribute[ 'is_taxonomy' ] ? wc_attribute_taxonomy_id_by_name( $attribute[ 'name' ] ) : 0, |
|
| 1076 | + 'name' => $this->get_attribute_taxonomy_name( $attribute[ 'name' ], $product ), |
|
| 1077 | + 'position' => (int) $attribute[ 'position' ], |
|
| 1078 | + 'visible' => (bool) $attribute[ 'is_visible' ], |
|
| 1079 | + 'variation' => (bool) $attribute[ 'is_variation' ], |
|
| 1080 | 1080 | 'options' => $this->get_attribute_options( $product->get_id(), $attribute ), |
| 1081 | 1081 | ); |
| 1082 | 1082 | } |
@@ -1181,16 +1181,16 @@ discard block |
||
| 1181 | 1181 | protected function prepare_links( $object, $request ) { |
| 1182 | 1182 | $links = array( |
| 1183 | 1183 | 'self' => array( |
| 1184 | - 'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $object->get_id() ) ), // @codingStandardsIgnoreLine. |
|
| 1184 | + 'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $object->get_id() ) ), // @codingStandardsIgnoreLine. |
|
| 1185 | 1185 | ), |
| 1186 | 1186 | 'collection' => array( |
| 1187 | - 'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ), // @codingStandardsIgnoreLine. |
|
| 1187 | + 'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ), // @codingStandardsIgnoreLine. |
|
| 1188 | 1188 | ), |
| 1189 | 1189 | ); |
| 1190 | 1190 | |
| 1191 | 1191 | if ( $object->get_parent_id() ) { |
| 1192 | - $links['up'] = array( |
|
| 1193 | - 'href' => rest_url( sprintf( '/%s/products/%d', $this->namespace, $object->get_parent_id() ) ), // @codingStandardsIgnoreLine. |
|
| 1192 | + $links[ 'up' ] = array( |
|
| 1193 | + 'href' => rest_url( sprintf( '/%s/products/%d', $this->namespace, $object->get_parent_id() ) ), // @codingStandardsIgnoreLine. |
|
| 1194 | 1194 | ); |
| 1195 | 1195 | } |
| 1196 | 1196 | |
@@ -1213,10 +1213,10 @@ discard block |
||
| 1213 | 1213 | $gallery = array(); |
| 1214 | 1214 | |
| 1215 | 1215 | foreach ( $images as $index => $image ) { |
| 1216 | - $attachment_id = isset( $image['id'] ) ? absint( $image['id'] ) : 0; |
|
| 1216 | + $attachment_id = isset( $image[ 'id' ] ) ? absint( $image[ 'id' ] ) : 0; |
|
| 1217 | 1217 | |
| 1218 | - if ( 0 === $attachment_id && isset( $image['src'] ) ) { |
|
| 1219 | - $upload = wc_rest_upload_image_from_url( esc_url_raw( $image['src'] ) ); |
|
| 1218 | + if ( 0 === $attachment_id && isset( $image[ 'src' ] ) ) { |
|
| 1219 | + $upload = wc_rest_upload_image_from_url( esc_url_raw( $image[ 'src' ] ) ); |
|
| 1220 | 1220 | |
| 1221 | 1221 | if ( is_wp_error( $upload ) ) { |
| 1222 | 1222 | if ( ! apply_filters( 'woocommerce_rest_suppress_image_upload_error', false, $upload, $product->get_id(), $images ) ) { |
@@ -1239,20 +1239,20 @@ discard block |
||
| 1239 | 1239 | if ( 0 === $index ) { |
| 1240 | 1240 | $product->set_image_id( $attachment_id ); |
| 1241 | 1241 | } else { |
| 1242 | - $gallery[] = $attachment_id; |
|
| 1242 | + $gallery[ ] = $attachment_id; |
|
| 1243 | 1243 | } |
| 1244 | 1244 | |
| 1245 | 1245 | // Set the image alt if present. |
| 1246 | - if ( ! empty( $image['alt'] ) ) { |
|
| 1247 | - update_post_meta( $attachment_id, '_wp_attachment_image_alt', wc_clean( $image['alt'] ) ); |
|
| 1246 | + if ( ! empty( $image[ 'alt' ] ) ) { |
|
| 1247 | + update_post_meta( $attachment_id, '_wp_attachment_image_alt', wc_clean( $image[ 'alt' ] ) ); |
|
| 1248 | 1248 | } |
| 1249 | 1249 | |
| 1250 | 1250 | // Set the image name if present. |
| 1251 | - if ( ! empty( $image['name'] ) ) { |
|
| 1251 | + if ( ! empty( $image[ 'name' ] ) ) { |
|
| 1252 | 1252 | wp_update_post( |
| 1253 | 1253 | array( |
| 1254 | 1254 | 'ID' => $attachment_id, |
| 1255 | - 'post_title' => $image['name'], |
|
| 1255 | + 'post_title' => $image[ 'name' ], |
|
| 1256 | 1256 | ) |
| 1257 | 1257 | ); |
| 1258 | 1258 | } |
@@ -1277,36 +1277,36 @@ discard block |
||
| 1277 | 1277 | */ |
| 1278 | 1278 | protected function save_product_shipping_data( $product, $data ) { |
| 1279 | 1279 | // Virtual. |
| 1280 | - if ( isset( $data['virtual'] ) && true === $data['virtual'] ) { |
|
| 1280 | + if ( isset( $data[ 'virtual' ] ) && true === $data[ 'virtual' ] ) { |
|
| 1281 | 1281 | $product->set_weight( '' ); |
| 1282 | 1282 | $product->set_height( '' ); |
| 1283 | 1283 | $product->set_length( '' ); |
| 1284 | 1284 | $product->set_width( '' ); |
| 1285 | 1285 | } else { |
| 1286 | - if ( isset( $data['weight'] ) ) { |
|
| 1287 | - $product->set_weight( $data['weight'] ); |
|
| 1286 | + if ( isset( $data[ 'weight' ] ) ) { |
|
| 1287 | + $product->set_weight( $data[ 'weight' ] ); |
|
| 1288 | 1288 | } |
| 1289 | 1289 | |
| 1290 | 1290 | // Height. |
| 1291 | - if ( isset( $data['dimensions']['height'] ) ) { |
|
| 1292 | - $product->set_height( $data['dimensions']['height'] ); |
|
| 1291 | + if ( isset( $data[ 'dimensions' ][ 'height' ] ) ) { |
|
| 1292 | + $product->set_height( $data[ 'dimensions' ][ 'height' ] ); |
|
| 1293 | 1293 | } |
| 1294 | 1294 | |
| 1295 | 1295 | // Width. |
| 1296 | - if ( isset( $data['dimensions']['width'] ) ) { |
|
| 1297 | - $product->set_width( $data['dimensions']['width'] ); |
|
| 1296 | + if ( isset( $data[ 'dimensions' ][ 'width' ] ) ) { |
|
| 1297 | + $product->set_width( $data[ 'dimensions' ][ 'width' ] ); |
|
| 1298 | 1298 | } |
| 1299 | 1299 | |
| 1300 | 1300 | // Length. |
| 1301 | - if ( isset( $data['dimensions']['length'] ) ) { |
|
| 1302 | - $product->set_length( $data['dimensions']['length'] ); |
|
| 1301 | + if ( isset( $data[ 'dimensions' ][ 'length' ] ) ) { |
|
| 1302 | + $product->set_length( $data[ 'dimensions' ][ 'length' ] ); |
|
| 1303 | 1303 | } |
| 1304 | 1304 | } |
| 1305 | 1305 | |
| 1306 | 1306 | // Shipping class. |
| 1307 | - if ( isset( $data['shipping_class'] ) ) { |
|
| 1307 | + if ( isset( $data[ 'shipping_class' ] ) ) { |
|
| 1308 | 1308 | $data_store = $product->get_data_store(); |
| 1309 | - $shipping_class_id = $data_store->get_shipping_class_id_by_slug( wc_clean( $data['shipping_class'] ) ); |
|
| 1309 | + $shipping_class_id = $data_store->get_shipping_class_id_by_slug( wc_clean( $data[ 'shipping_class' ] ) ); |
|
| 1310 | 1310 | $product->set_shipping_class_id( $shipping_class_id ); |
| 1311 | 1311 | } |
| 1312 | 1312 | |
@@ -1329,15 +1329,15 @@ discard block |
||
| 1329 | 1329 | |
| 1330 | 1330 | $files = array(); |
| 1331 | 1331 | foreach ( $downloads as $key => $file ) { |
| 1332 | - if ( empty( $file['file'] ) ) { |
|
| 1332 | + if ( empty( $file[ 'file' ] ) ) { |
|
| 1333 | 1333 | continue; |
| 1334 | 1334 | } |
| 1335 | 1335 | |
| 1336 | 1336 | $download = new \WC_Product_Download(); |
| 1337 | - $download->set_id( ! empty( $file['id'] ) ? $file['id'] : wp_generate_uuid4() ); |
|
| 1338 | - $download->set_name( $file['name'] ? $file['name'] : wc_get_filename_from_url( $file['file'] ) ); |
|
| 1339 | - $download->set_file( apply_filters( 'woocommerce_file_download_path', $file['file'], $product, $key ) ); |
|
| 1340 | - $files[] = $download; |
|
| 1337 | + $download->set_id( ! empty( $file[ 'id' ] ) ? $file[ 'id' ] : wp_generate_uuid4() ); |
|
| 1338 | + $download->set_name( $file[ 'name' ] ? $file[ 'name' ] : wc_get_filename_from_url( $file[ 'file' ] ) ); |
|
| 1339 | + $download->set_file( apply_filters( 'woocommerce_file_download_path', $file[ 'file' ], $product, $key ) ); |
|
| 1340 | + $files[ ] = $download; |
|
| 1341 | 1341 | } |
| 1342 | 1342 | $product->set_downloads( $files ); |
| 1343 | 1343 | |
@@ -1373,21 +1373,21 @@ discard block |
||
| 1373 | 1373 | * @return \WC_Product |
| 1374 | 1374 | */ |
| 1375 | 1375 | protected function save_default_attributes( $product, $request ) { |
| 1376 | - if ( isset( $request['default_attributes'] ) && is_array( $request['default_attributes'] ) ) { |
|
| 1376 | + if ( isset( $request[ 'default_attributes' ] ) && is_array( $request[ 'default_attributes' ] ) ) { |
|
| 1377 | 1377 | |
| 1378 | 1378 | $attributes = $product->get_attributes(); |
| 1379 | 1379 | $default_attributes = array(); |
| 1380 | 1380 | |
| 1381 | - foreach ( $request['default_attributes'] as $attribute ) { |
|
| 1381 | + foreach ( $request[ 'default_attributes' ] as $attribute ) { |
|
| 1382 | 1382 | $attribute_id = 0; |
| 1383 | 1383 | $attribute_name = ''; |
| 1384 | 1384 | |
| 1385 | 1385 | // Check ID for global attributes or name for product attributes. |
| 1386 | - if ( ! empty( $attribute['id'] ) ) { |
|
| 1387 | - $attribute_id = absint( $attribute['id'] ); |
|
| 1386 | + if ( ! empty( $attribute[ 'id' ] ) ) { |
|
| 1387 | + $attribute_id = absint( $attribute[ 'id' ] ); |
|
| 1388 | 1388 | $attribute_name = wc_attribute_taxonomy_name_by_id( $attribute_id ); |
| 1389 | - } elseif ( ! empty( $attribute['name'] ) ) { |
|
| 1390 | - $attribute_name = sanitize_title( $attribute['name'] ); |
|
| 1389 | + } elseif ( ! empty( $attribute[ 'name' ] ) ) { |
|
| 1390 | + $attribute_name = sanitize_title( $attribute[ 'name' ] ); |
|
| 1391 | 1391 | } |
| 1392 | 1392 | |
| 1393 | 1393 | if ( ! $attribute_id && ! $attribute_name ) { |
@@ -1397,10 +1397,10 @@ discard block |
||
| 1397 | 1397 | if ( isset( $attributes[ $attribute_name ] ) ) { |
| 1398 | 1398 | $_attribute = $attributes[ $attribute_name ]; |
| 1399 | 1399 | |
| 1400 | - if ( $_attribute['is_variation'] ) { |
|
| 1401 | - $value = isset( $attribute['option'] ) ? wc_clean( stripslashes( $attribute['option'] ) ) : ''; |
|
| 1400 | + if ( $_attribute[ 'is_variation' ] ) { |
|
| 1401 | + $value = isset( $attribute[ 'option' ] ) ? wc_clean( stripslashes( $attribute[ 'option' ] ) ) : ''; |
|
| 1402 | 1402 | |
| 1403 | - if ( ! empty( $_attribute['is_taxonomy'] ) ) { |
|
| 1403 | + if ( ! empty( $_attribute[ 'is_taxonomy' ] ) ) { |
|
| 1404 | 1404 | // If dealing with a taxonomy, we need to get the slug from the name posted to the API. |
| 1405 | 1405 | $term = get_term_by( 'name', $value, $attribute_name ); |
| 1406 | 1406 | |
@@ -1442,9 +1442,9 @@ discard block |
||
| 1442 | 1442 | * @return \WP_REST_Response|\WP_Error |
| 1443 | 1443 | */ |
| 1444 | 1444 | public function delete_item( $request ) { |
| 1445 | - $id = (int) $request['id']; |
|
| 1446 | - $force = (bool) $request['force']; |
|
| 1447 | - $object = $this->get_object( (int) $request['id'] ); |
|
| 1445 | + $id = (int) $request[ 'id' ]; |
|
| 1446 | + $force = (bool) $request[ 'force' ]; |
|
| 1447 | + $object = $this->get_object( (int) $request[ 'id' ] ); |
|
| 1448 | 1448 | $result = false; |
| 1449 | 1449 | |
| 1450 | 1450 | if ( ! $object || 0 === $object->get_id() ) { |
@@ -2185,13 +2185,13 @@ discard block |
||
| 2185 | 2185 | public function get_collection_params() { |
| 2186 | 2186 | $params = parent::get_collection_params(); |
| 2187 | 2187 | |
| 2188 | - $params['slug'] = array( |
|
| 2188 | + $params[ 'slug' ] = array( |
|
| 2189 | 2189 | 'description' => __( 'Limit result set to products with a specific slug.', 'woocommerce' ), |
| 2190 | 2190 | 'type' => 'string', |
| 2191 | 2191 | 'validate_callback' => 'rest_validate_request_arg', |
| 2192 | 2192 | ); |
| 2193 | 2193 | |
| 2194 | - $params['status'] = array( |
|
| 2194 | + $params[ 'status' ] = array( |
|
| 2195 | 2195 | 'default' => 'any', |
| 2196 | 2196 | 'description' => __( 'Limit result set to products assigned a specific status.', 'woocommerce' ), |
| 2197 | 2197 | 'type' => 'string', |
@@ -2200,7 +2200,7 @@ discard block |
||
| 2200 | 2200 | 'validate_callback' => 'rest_validate_request_arg', |
| 2201 | 2201 | ); |
| 2202 | 2202 | |
| 2203 | - $params['type'] = array( |
|
| 2203 | + $params[ 'type' ] = array( |
|
| 2204 | 2204 | 'description' => __( 'Limit result set to products assigned a specific type.', 'woocommerce' ), |
| 2205 | 2205 | 'type' => 'string', |
| 2206 | 2206 | 'enum' => array_keys( wc_get_product_types() ), |
@@ -2208,49 +2208,49 @@ discard block |
||
| 2208 | 2208 | 'validate_callback' => 'rest_validate_request_arg', |
| 2209 | 2209 | ); |
| 2210 | 2210 | |
| 2211 | - $params['sku'] = array( |
|
| 2211 | + $params[ 'sku' ] = array( |
|
| 2212 | 2212 | 'description' => __( 'Limit result set to products with specific SKU(s). Use commas to separate.', 'woocommerce' ), |
| 2213 | 2213 | 'type' => 'string', |
| 2214 | 2214 | 'sanitize_callback' => 'sanitize_text_field', |
| 2215 | 2215 | 'validate_callback' => 'rest_validate_request_arg', |
| 2216 | 2216 | ); |
| 2217 | 2217 | |
| 2218 | - $params['featured'] = array( |
|
| 2218 | + $params[ 'featured' ] = array( |
|
| 2219 | 2219 | 'description' => __( 'Limit result set to featured products.', 'woocommerce' ), |
| 2220 | 2220 | 'type' => 'boolean', |
| 2221 | 2221 | 'sanitize_callback' => 'wc_string_to_bool', |
| 2222 | 2222 | 'validate_callback' => 'rest_validate_request_arg', |
| 2223 | 2223 | ); |
| 2224 | 2224 | |
| 2225 | - $params['category'] = array( |
|
| 2225 | + $params[ 'category' ] = array( |
|
| 2226 | 2226 | 'description' => __( 'Limit result set to products assigned a specific category ID.', 'woocommerce' ), |
| 2227 | 2227 | 'type' => 'string', |
| 2228 | 2228 | 'sanitize_callback' => 'wp_parse_id_list', |
| 2229 | 2229 | 'validate_callback' => 'rest_validate_request_arg', |
| 2230 | 2230 | ); |
| 2231 | 2231 | |
| 2232 | - $params['tag'] = array( |
|
| 2232 | + $params[ 'tag' ] = array( |
|
| 2233 | 2233 | 'description' => __( 'Limit result set to products assigned a specific tag ID.', 'woocommerce' ), |
| 2234 | 2234 | 'type' => 'string', |
| 2235 | 2235 | 'sanitize_callback' => 'wp_parse_id_list', |
| 2236 | 2236 | 'validate_callback' => 'rest_validate_request_arg', |
| 2237 | 2237 | ); |
| 2238 | 2238 | |
| 2239 | - $params['shipping_class'] = array( |
|
| 2239 | + $params[ 'shipping_class' ] = array( |
|
| 2240 | 2240 | 'description' => __( 'Limit result set to products assigned a specific shipping class ID.', 'woocommerce' ), |
| 2241 | 2241 | 'type' => 'string', |
| 2242 | 2242 | 'sanitize_callback' => 'wp_parse_id_list', |
| 2243 | 2243 | 'validate_callback' => 'rest_validate_request_arg', |
| 2244 | 2244 | ); |
| 2245 | 2245 | |
| 2246 | - $params['attribute'] = array( |
|
| 2246 | + $params[ 'attribute' ] = array( |
|
| 2247 | 2247 | 'description' => __( 'Limit result set to products with a specific attribute. Use the taxonomy name/attribute slug.', 'woocommerce' ), |
| 2248 | 2248 | 'type' => 'string', |
| 2249 | 2249 | 'sanitize_callback' => 'sanitize_text_field', |
| 2250 | 2250 | 'validate_callback' => 'rest_validate_request_arg', |
| 2251 | 2251 | ); |
| 2252 | 2252 | |
| 2253 | - $params['attribute_term'] = array( |
|
| 2253 | + $params[ 'attribute_term' ] = array( |
|
| 2254 | 2254 | 'description' => __( 'Limit result set to products with a specific attribute term ID (required an assigned attribute).', 'woocommerce' ), |
| 2255 | 2255 | 'type' => 'string', |
| 2256 | 2256 | 'sanitize_callback' => 'wp_parse_id_list', |
@@ -2258,7 +2258,7 @@ discard block |
||
| 2258 | 2258 | ); |
| 2259 | 2259 | |
| 2260 | 2260 | if ( wc_tax_enabled() ) { |
| 2261 | - $params['tax_class'] = array( |
|
| 2261 | + $params[ 'tax_class' ] = array( |
|
| 2262 | 2262 | 'description' => __( 'Limit result set to products with a specific tax class.', 'woocommerce' ), |
| 2263 | 2263 | 'type' => 'string', |
| 2264 | 2264 | 'enum' => array_merge( array( 'standard' ), \WC_Tax::get_tax_class_slugs() ), |
@@ -2267,28 +2267,28 @@ discard block |
||
| 2267 | 2267 | ); |
| 2268 | 2268 | } |
| 2269 | 2269 | |
| 2270 | - $params['on_sale'] = array( |
|
| 2270 | + $params[ 'on_sale' ] = array( |
|
| 2271 | 2271 | 'description' => __( 'Limit result set to products on sale.', 'woocommerce' ), |
| 2272 | 2272 | 'type' => 'boolean', |
| 2273 | 2273 | 'sanitize_callback' => 'wc_string_to_bool', |
| 2274 | 2274 | 'validate_callback' => 'rest_validate_request_arg', |
| 2275 | 2275 | ); |
| 2276 | 2276 | |
| 2277 | - $params['min_price'] = array( |
|
| 2277 | + $params[ 'min_price' ] = array( |
|
| 2278 | 2278 | 'description' => __( 'Limit result set to products based on a minimum price.', 'woocommerce' ), |
| 2279 | 2279 | 'type' => 'string', |
| 2280 | 2280 | 'sanitize_callback' => 'sanitize_text_field', |
| 2281 | 2281 | 'validate_callback' => 'rest_validate_request_arg', |
| 2282 | 2282 | ); |
| 2283 | 2283 | |
| 2284 | - $params['max_price'] = array( |
|
| 2284 | + $params[ 'max_price' ] = array( |
|
| 2285 | 2285 | 'description' => __( 'Limit result set to products based on a maximum price.', 'woocommerce' ), |
| 2286 | 2286 | 'type' => 'string', |
| 2287 | 2287 | 'sanitize_callback' => 'sanitize_text_field', |
| 2288 | 2288 | 'validate_callback' => 'rest_validate_request_arg', |
| 2289 | 2289 | ); |
| 2290 | 2290 | |
| 2291 | - $params['stock_status'] = array( |
|
| 2291 | + $params[ 'stock_status' ] = array( |
|
| 2292 | 2292 | 'description' => __( 'Limit result set to products with specified stock status.', 'woocommerce' ), |
| 2293 | 2293 | 'type' => 'string', |
| 2294 | 2294 | 'enum' => array_keys( wc_get_product_stock_status_options() ), |
@@ -2296,20 +2296,20 @@ discard block |
||
| 2296 | 2296 | 'validate_callback' => 'rest_validate_request_arg', |
| 2297 | 2297 | ); |
| 2298 | 2298 | |
| 2299 | - $params['low_in_stock'] = array( |
|
| 2299 | + $params[ 'low_in_stock' ] = array( |
|
| 2300 | 2300 | 'description' => __( 'Limit result set to products that are low or out of stock.', 'woocommerce' ), |
| 2301 | 2301 | 'type' => 'boolean', |
| 2302 | 2302 | 'default' => false, |
| 2303 | 2303 | 'sanitize_callback' => 'wc_string_to_bool', |
| 2304 | 2304 | ); |
| 2305 | 2305 | |
| 2306 | - $params['search'] = array( |
|
| 2306 | + $params[ 'search' ] = array( |
|
| 2307 | 2307 | 'description' => __( 'Search by similar product name or sku.', 'woocommerce' ), |
| 2308 | 2308 | 'type' => 'string', |
| 2309 | 2309 | 'validate_callback' => 'rest_validate_request_arg', |
| 2310 | 2310 | ); |
| 2311 | 2311 | |
| 2312 | - $params['orderby']['enum'] = array_merge( $params['orderby']['enum'], array( 'price', 'popularity', 'rating' ) ); |
|
| 2312 | + $params[ 'orderby' ][ 'enum' ] = array_merge( $params[ 'orderby' ][ 'enum' ], array( 'price', 'popularity', 'rating' ) ); |
|
| 2313 | 2313 | |
| 2314 | 2314 | return $params; |
| 2315 | 2315 | } |
@@ -46,7 +46,7 @@ |
||
| 46 | 46 | 'count' => (int) $item->count, |
| 47 | 47 | ); |
| 48 | 48 | |
| 49 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
| 49 | + $context = ! empty( $request[ 'context' ] ) ? $request[ 'context' ] : 'view'; |
|
| 50 | 50 | $data = $this->add_additional_fields_to_object( $data, $request ); |
| 51 | 51 | $data = $this->filter_response_by_context( $data, $context ); |
| 52 | 52 | |
@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | * @return \WP_Error|boolean |
| 168 | 168 | */ |
| 169 | 169 | public function get_item_permissions_check( $request ) { |
| 170 | - $id = (int) $request['id']; |
|
| 170 | + $id = (int) $request[ 'id' ]; |
|
| 171 | 171 | |
| 172 | 172 | if ( ! wc_rest_check_user_permissions( 'read', $id ) ) { |
| 173 | 173 | return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | * @return bool|\WP_Error |
| 185 | 185 | */ |
| 186 | 186 | public function update_item_permissions_check( $request ) { |
| 187 | - $id = (int) $request['id']; |
|
| 187 | + $id = (int) $request[ 'id' ]; |
|
| 188 | 188 | |
| 189 | 189 | if ( ! wc_rest_check_user_permissions( 'edit', $id ) ) { |
| 190 | 190 | return new \WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you are not allowed to edit this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
@@ -201,7 +201,7 @@ discard block |
||
| 201 | 201 | * @return bool|\WP_Error |
| 202 | 202 | */ |
| 203 | 203 | public function delete_item_permissions_check( $request ) { |
| 204 | - $id = (int) $request['id']; |
|
| 204 | + $id = (int) $request[ 'id' ]; |
|
| 205 | 205 | |
| 206 | 206 | if ( ! wc_rest_check_user_permissions( 'delete', $id ) ) { |
| 207 | 207 | return new \WP_Error( 'woocommerce_rest_cannot_delete', __( 'Sorry, you are not allowed to delete this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
@@ -247,20 +247,20 @@ discard block |
||
| 247 | 247 | |
| 248 | 248 | return array( |
| 249 | 249 | 'id' => $object->get_id(), |
| 250 | - 'date_created' => $data['date_created'], |
|
| 251 | - 'date_created_gmt' => $data['date_created_gmt'], |
|
| 252 | - 'date_modified' => $data['date_modified'], |
|
| 253 | - 'date_modified_gmt' => $data['date_modified_gmt'], |
|
| 254 | - 'email' => $data['email'], |
|
| 255 | - 'first_name' => $data['first_name'], |
|
| 256 | - 'last_name' => $data['last_name'], |
|
| 257 | - 'role' => $data['role'], |
|
| 258 | - 'username' => $data['username'], |
|
| 259 | - 'billing' => $data['billing'], |
|
| 260 | - 'shipping' => $data['shipping'], |
|
| 261 | - 'is_paying_customer' => $data['is_paying_customer'], |
|
| 250 | + 'date_created' => $data[ 'date_created' ], |
|
| 251 | + 'date_created_gmt' => $data[ 'date_created_gmt' ], |
|
| 252 | + 'date_modified' => $data[ 'date_modified' ], |
|
| 253 | + 'date_modified_gmt' => $data[ 'date_modified_gmt' ], |
|
| 254 | + 'email' => $data[ 'email' ], |
|
| 255 | + 'first_name' => $data[ 'first_name' ], |
|
| 256 | + 'last_name' => $data[ 'last_name' ], |
|
| 257 | + 'role' => $data[ 'role' ], |
|
| 258 | + 'username' => $data[ 'username' ], |
|
| 259 | + 'billing' => $data[ 'billing' ], |
|
| 260 | + 'shipping' => $data[ 'shipping' ], |
|
| 261 | + 'is_paying_customer' => $data[ 'is_paying_customer' ], |
|
| 262 | 262 | 'avatar_url' => $object->get_avatar_url(), |
| 263 | - 'meta_data' => $data['meta_data'], |
|
| 263 | + 'meta_data' => $data[ 'meta_data' ], |
|
| 264 | 264 | ); |
| 265 | 265 | } |
| 266 | 266 | |
@@ -272,14 +272,14 @@ discard block |
||
| 272 | 272 | */ |
| 273 | 273 | public function get_items( $request ) { |
| 274 | 274 | $prepared_args = array(); |
| 275 | - $prepared_args['exclude'] = $request['exclude']; |
|
| 276 | - $prepared_args['include'] = $request['include']; |
|
| 277 | - $prepared_args['order'] = $request['order']; |
|
| 278 | - $prepared_args['number'] = $request['per_page']; |
|
| 279 | - if ( ! empty( $request['offset'] ) ) { |
|
| 280 | - $prepared_args['offset'] = $request['offset']; |
|
| 275 | + $prepared_args[ 'exclude' ] = $request[ 'exclude' ]; |
|
| 276 | + $prepared_args[ 'include' ] = $request[ 'include' ]; |
|
| 277 | + $prepared_args[ 'order' ] = $request[ 'order' ]; |
|
| 278 | + $prepared_args[ 'number' ] = $request[ 'per_page' ]; |
|
| 279 | + if ( ! empty( $request[ 'offset' ] ) ) { |
|
| 280 | + $prepared_args[ 'offset' ] = $request[ 'offset' ]; |
|
| 281 | 281 | } else { |
| 282 | - $prepared_args['offset'] = ( $request['page'] - 1 ) * $prepared_args['number']; |
|
| 282 | + $prepared_args[ 'offset' ] = ( $request[ 'page' ] - 1 ) * $prepared_args[ 'number' ]; |
|
| 283 | 283 | } |
| 284 | 284 | $orderby_possibles = array( |
| 285 | 285 | 'id' => 'ID', |
@@ -287,22 +287,22 @@ discard block |
||
| 287 | 287 | 'name' => 'display_name', |
| 288 | 288 | 'registered_date' => 'registered', |
| 289 | 289 | ); |
| 290 | - $prepared_args['orderby'] = $orderby_possibles[ $request['orderby'] ]; |
|
| 291 | - $prepared_args['search'] = $request['search']; |
|
| 290 | + $prepared_args[ 'orderby' ] = $orderby_possibles[ $request[ 'orderby' ] ]; |
|
| 291 | + $prepared_args[ 'search' ] = $request[ 'search' ]; |
|
| 292 | 292 | |
| 293 | - if ( '' !== $prepared_args['search'] ) { |
|
| 294 | - $prepared_args['search'] = '*' . $prepared_args['search'] . '*'; |
|
| 293 | + if ( '' !== $prepared_args[ 'search' ] ) { |
|
| 294 | + $prepared_args[ 'search' ] = '*' . $prepared_args[ 'search' ] . '*'; |
|
| 295 | 295 | } |
| 296 | 296 | |
| 297 | 297 | // Filter by email. |
| 298 | - if ( ! empty( $request['email'] ) ) { |
|
| 299 | - $prepared_args['search'] = $request['email']; |
|
| 300 | - $prepared_args['search_columns'] = array( 'user_email' ); |
|
| 298 | + if ( ! empty( $request[ 'email' ] ) ) { |
|
| 299 | + $prepared_args[ 'search' ] = $request[ 'email' ]; |
|
| 300 | + $prepared_args[ 'search_columns' ] = array( 'user_email' ); |
|
| 301 | 301 | } |
| 302 | 302 | |
| 303 | 303 | // Filter by role. |
| 304 | - if ( 'all' !== $request['role'] ) { |
|
| 305 | - $prepared_args['role'] = $request['role']; |
|
| 304 | + if ( 'all' !== $request[ 'role' ] ) { |
|
| 305 | + $prepared_args[ 'role' ] = $request[ 'role' ]; |
|
| 306 | 306 | } |
| 307 | 307 | |
| 308 | 308 | /** |
@@ -320,22 +320,22 @@ discard block |
||
| 320 | 320 | $users = array(); |
| 321 | 321 | foreach ( $query->results as $user ) { |
| 322 | 322 | $data = $this->prepare_item_for_response( $user, $request ); |
| 323 | - $users[] = $this->prepare_response_for_collection( $data ); |
|
| 323 | + $users[ ] = $this->prepare_response_for_collection( $data ); |
|
| 324 | 324 | } |
| 325 | 325 | |
| 326 | 326 | $response = rest_ensure_response( $users ); |
| 327 | 327 | |
| 328 | 328 | // Store pagination values for headers then unset for count query. |
| 329 | - $per_page = (int) $prepared_args['number']; |
|
| 330 | - $page = ceil( ( ( (int) $prepared_args['offset'] ) / $per_page ) + 1 ); |
|
| 329 | + $per_page = (int) $prepared_args[ 'number' ]; |
|
| 330 | + $page = ceil( ( ( (int) $prepared_args[ 'offset' ] ) / $per_page ) + 1 ); |
|
| 331 | 331 | |
| 332 | - $prepared_args['fields'] = 'ID'; |
|
| 332 | + $prepared_args[ 'fields' ] = 'ID'; |
|
| 333 | 333 | |
| 334 | 334 | $total_users = $query->get_total(); |
| 335 | 335 | if ( $total_users < 1 ) { |
| 336 | 336 | // Out-of-bounds, run the query again without LIMIT for total count. |
| 337 | - unset( $prepared_args['number'] ); |
|
| 338 | - unset( $prepared_args['offset'] ); |
|
| 337 | + unset( $prepared_args[ 'number' ] ); |
|
| 338 | + unset( $prepared_args[ 'offset' ] ); |
|
| 339 | 339 | $count_query = new \ WP_User_Query( $prepared_args ); |
| 340 | 340 | $total_users = $count_query->get_total(); |
| 341 | 341 | } |
@@ -370,21 +370,21 @@ discard block |
||
| 370 | 370 | */ |
| 371 | 371 | public function create_item( $request ) { |
| 372 | 372 | try { |
| 373 | - if ( ! empty( $request['id'] ) ) { |
|
| 373 | + if ( ! empty( $request[ 'id' ] ) ) { |
|
| 374 | 374 | throw new \WC_REST_Exception( 'woocommerce_rest_customer_exists', __( 'Cannot create existing resource.', 'woocommerce' ), 400 ); |
| 375 | 375 | } |
| 376 | 376 | |
| 377 | 377 | // Sets the username. |
| 378 | - $request['username'] = ! empty( $request['username'] ) ? $request['username'] : ''; |
|
| 378 | + $request[ 'username' ] = ! empty( $request[ 'username' ] ) ? $request[ 'username' ] : ''; |
|
| 379 | 379 | |
| 380 | 380 | // Sets the password. |
| 381 | - $request['password'] = ! empty( $request['password'] ) ? $request['password'] : ''; |
|
| 381 | + $request[ 'password' ] = ! empty( $request[ 'password' ] ) ? $request[ 'password' ] : ''; |
|
| 382 | 382 | |
| 383 | 383 | // Create customer. |
| 384 | 384 | $customer = new \WC_Customer(); |
| 385 | - $customer->set_username( $request['username'] ); |
|
| 386 | - $customer->set_password( $request['password'] ); |
|
| 387 | - $customer->set_email( $request['email'] ); |
|
| 385 | + $customer->set_username( $request[ 'username' ] ); |
|
| 386 | + $customer->set_password( $request[ 'password' ] ); |
|
| 387 | + $customer->set_email( $request[ 'email' ] ); |
|
| 388 | 388 | $this->update_customer_meta_fields( $customer, $request ); |
| 389 | 389 | $customer->save(); |
| 390 | 390 | |
@@ -423,7 +423,7 @@ discard block |
||
| 423 | 423 | * @return \WP_Error\WP_REST_Response |
| 424 | 424 | */ |
| 425 | 425 | public function get_item( $request ) { |
| 426 | - $id = (int) $request['id']; |
|
| 426 | + $id = (int) $request[ 'id' ]; |
|
| 427 | 427 | $user_data = get_userdata( $id ); |
| 428 | 428 | |
| 429 | 429 | if ( empty( $id ) || empty( $user_data->ID ) ) { |
@@ -446,29 +446,29 @@ discard block |
||
| 446 | 446 | */ |
| 447 | 447 | public function update_item( $request ) { |
| 448 | 448 | try { |
| 449 | - $id = (int) $request['id']; |
|
| 449 | + $id = (int) $request[ 'id' ]; |
|
| 450 | 450 | $customer = new \WC_Customer( $id ); |
| 451 | 451 | |
| 452 | 452 | if ( ! $customer->get_id() ) { |
| 453 | 453 | throw new \WC_REST_Exception( 'woocommerce_rest_invalid_id', __( 'Invalid resource ID.', 'woocommerce' ), 400 ); |
| 454 | 454 | } |
| 455 | 455 | |
| 456 | - if ( ! empty( $request['email'] ) && email_exists( $request['email'] ) && $request['email'] !== $customer->get_email() ) { |
|
| 456 | + if ( ! empty( $request[ 'email' ] ) && email_exists( $request[ 'email' ] ) && $request[ 'email' ] !== $customer->get_email() ) { |
|
| 457 | 457 | throw new \WC_REST_Exception( 'woocommerce_rest_customer_invalid_email', __( 'Email address is invalid.', 'woocommerce' ), 400 ); |
| 458 | 458 | } |
| 459 | 459 | |
| 460 | - if ( ! empty( $request['username'] ) && $request['username'] !== $customer->get_username() ) { |
|
| 460 | + if ( ! empty( $request[ 'username' ] ) && $request[ 'username' ] !== $customer->get_username() ) { |
|
| 461 | 461 | throw new \WC_REST_Exception( 'woocommerce_rest_customer_invalid_argument', __( "Username isn't editable.", 'woocommerce' ), 400 ); |
| 462 | 462 | } |
| 463 | 463 | |
| 464 | 464 | // Customer email. |
| 465 | - if ( isset( $request['email'] ) ) { |
|
| 466 | - $customer->set_email( sanitize_email( $request['email'] ) ); |
|
| 465 | + if ( isset( $request[ 'email' ] ) ) { |
|
| 466 | + $customer->set_email( sanitize_email( $request[ 'email' ] ) ); |
|
| 467 | 467 | } |
| 468 | 468 | |
| 469 | 469 | // Customer password. |
| 470 | - if ( isset( $request['password'] ) ) { |
|
| 471 | - $customer->set_password( $request['password'] ); |
|
| 470 | + if ( isset( $request[ 'password' ] ) ) { |
|
| 471 | + $customer->set_password( $request[ 'password' ] ); |
|
| 472 | 472 | } |
| 473 | 473 | |
| 474 | 474 | $this->update_customer_meta_fields( $customer, $request ); |
@@ -506,9 +506,9 @@ discard block |
||
| 506 | 506 | * @return \WP_Error\WP_REST_Response |
| 507 | 507 | */ |
| 508 | 508 | public function delete_item( $request ) { |
| 509 | - $id = (int) $request['id']; |
|
| 510 | - $reassign = isset( $request['reassign'] ) ? absint( $request['reassign'] ) : null; |
|
| 511 | - $force = isset( $request['force'] ) ? (bool) $request['force'] : false; |
|
| 509 | + $id = (int) $request[ 'id' ]; |
|
| 510 | + $reassign = isset( $request[ 'reassign' ] ) ? absint( $request[ 'reassign' ] ) : null; |
|
| 511 | + $force = isset( $request[ 'force' ] ) ? (bool) $request[ 'force' ] : false; |
|
| 512 | 512 | |
| 513 | 513 | // We don't support trashing for this type, error out. |
| 514 | 514 | if ( ! $force ) { |
@@ -566,7 +566,7 @@ discard block |
||
| 566 | 566 | public function prepare_item_for_response( $user_data, $request ) { |
| 567 | 567 | $customer = new \WC_Customer( $user_data->ID ); |
| 568 | 568 | $data = $this->get_formatted_item_data( $customer ); |
| 569 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
| 569 | + $context = ! empty( $request[ 'context' ] ) ? $request[ 'context' ] : 'view'; |
|
| 570 | 570 | $data = $this->add_additional_fields_to_object( $data, $request ); |
| 571 | 571 | $data = $this->filter_response_by_context( $data, $context ); |
| 572 | 572 | $response = rest_ensure_response( $data ); |
@@ -592,38 +592,38 @@ discard block |
||
| 592 | 592 | $schema = $this->get_item_schema(); |
| 593 | 593 | |
| 594 | 594 | // Customer first name. |
| 595 | - if ( isset( $request['first_name'] ) ) { |
|
| 596 | - $customer->set_first_name( wc_clean( $request['first_name'] ) ); |
|
| 595 | + if ( isset( $request[ 'first_name' ] ) ) { |
|
| 596 | + $customer->set_first_name( wc_clean( $request[ 'first_name' ] ) ); |
|
| 597 | 597 | } |
| 598 | 598 | |
| 599 | 599 | // Customer last name. |
| 600 | - if ( isset( $request['last_name'] ) ) { |
|
| 601 | - $customer->set_last_name( wc_clean( $request['last_name'] ) ); |
|
| 600 | + if ( isset( $request[ 'last_name' ] ) ) { |
|
| 601 | + $customer->set_last_name( wc_clean( $request[ 'last_name' ] ) ); |
|
| 602 | 602 | } |
| 603 | 603 | |
| 604 | 604 | // Customer billing address. |
| 605 | - if ( isset( $request['billing'] ) ) { |
|
| 606 | - foreach ( array_keys( $schema['properties']['billing']['properties'] ) as $field ) { |
|
| 607 | - if ( isset( $request['billing'][ $field ] ) && is_callable( array( $customer, "set_billing_{$field}" ) ) ) { |
|
| 608 | - $customer->{"set_billing_{$field}"}( $request['billing'][ $field ] ); |
|
| 605 | + if ( isset( $request[ 'billing' ] ) ) { |
|
| 606 | + foreach ( array_keys( $schema[ 'properties' ][ 'billing' ][ 'properties' ] ) as $field ) { |
|
| 607 | + if ( isset( $request[ 'billing' ][ $field ] ) && is_callable( array( $customer, "set_billing_{$field}" ) ) ) { |
|
| 608 | + $customer->{"set_billing_{$field}"}( $request[ 'billing' ][ $field ] ); |
|
| 609 | 609 | } |
| 610 | 610 | } |
| 611 | 611 | } |
| 612 | 612 | |
| 613 | 613 | // Customer shipping address. |
| 614 | - if ( isset( $request['shipping'] ) ) { |
|
| 615 | - foreach ( array_keys( $schema['properties']['shipping']['properties'] ) as $field ) { |
|
| 616 | - if ( isset( $request['shipping'][ $field ] ) && is_callable( array( $customer, "set_shipping_{$field}" ) ) ) { |
|
| 617 | - $customer->{"set_shipping_{$field}"}( $request['shipping'][ $field ] ); |
|
| 614 | + if ( isset( $request[ 'shipping' ] ) ) { |
|
| 615 | + foreach ( array_keys( $schema[ 'properties' ][ 'shipping' ][ 'properties' ] ) as $field ) { |
|
| 616 | + if ( isset( $request[ 'shipping' ][ $field ] ) && is_callable( array( $customer, "set_shipping_{$field}" ) ) ) { |
|
| 617 | + $customer->{"set_shipping_{$field}"}( $request[ 'shipping' ][ $field ] ); |
|
| 618 | 618 | } |
| 619 | 619 | } |
| 620 | 620 | } |
| 621 | 621 | |
| 622 | 622 | // Meta data. |
| 623 | - if ( isset( $request['meta_data'] ) ) { |
|
| 624 | - if ( is_array( $request['meta_data'] ) ) { |
|
| 625 | - foreach ( $request['meta_data'] as $meta ) { |
|
| 626 | - $customer->update_meta_data( $meta['key'], $meta['value'], isset( $meta['id'] ) ? $meta['id'] : '' ); |
|
| 623 | + if ( isset( $request[ 'meta_data' ] ) ) { |
|
| 624 | + if ( is_array( $request[ 'meta_data' ] ) ) { |
|
| 625 | + foreach ( $request[ 'meta_data' ] as $meta ) { |
|
| 626 | + $customer->update_meta_data( $meta[ 'key' ], $meta[ 'value' ], isset( $meta[ 'id' ] ) ? $meta[ 'id' ] : '' ); |
|
| 627 | 627 | } |
| 628 | 628 | } |
| 629 | 629 | } |
@@ -908,9 +908,9 @@ discard block |
||
| 908 | 908 | public function get_collection_params() { |
| 909 | 909 | $params = parent::get_collection_params(); |
| 910 | 910 | |
| 911 | - $params['context']['default'] = 'view'; |
|
| 911 | + $params[ 'context' ][ 'default' ] = 'view'; |
|
| 912 | 912 | |
| 913 | - $params['exclude'] = array( |
|
| 913 | + $params[ 'exclude' ] = array( |
|
| 914 | 914 | 'description' => __( 'Ensure result set excludes specific IDs.', 'woocommerce' ), |
| 915 | 915 | 'type' => 'array', |
| 916 | 916 | 'items' => array( |
@@ -919,7 +919,7 @@ discard block |
||
| 919 | 919 | 'default' => array(), |
| 920 | 920 | 'sanitize_callback' => 'wp_parse_id_list', |
| 921 | 921 | ); |
| 922 | - $params['include'] = array( |
|
| 922 | + $params[ 'include' ] = array( |
|
| 923 | 923 | 'description' => __( 'Limit result set to specific IDs.', 'woocommerce' ), |
| 924 | 924 | 'type' => 'array', |
| 925 | 925 | 'items' => array( |
@@ -928,13 +928,13 @@ discard block |
||
| 928 | 928 | 'default' => array(), |
| 929 | 929 | 'sanitize_callback' => 'wp_parse_id_list', |
| 930 | 930 | ); |
| 931 | - $params['offset'] = array( |
|
| 931 | + $params[ 'offset' ] = array( |
|
| 932 | 932 | 'description' => __( 'Offset the result set by a specific number of items.', 'woocommerce' ), |
| 933 | 933 | 'type' => 'integer', |
| 934 | 934 | 'sanitize_callback' => 'absint', |
| 935 | 935 | 'validate_callback' => 'rest_validate_request_arg', |
| 936 | 936 | ); |
| 937 | - $params['order'] = array( |
|
| 937 | + $params[ 'order' ] = array( |
|
| 938 | 938 | 'default' => 'asc', |
| 939 | 939 | 'description' => __( 'Order sort attribute ascending or descending.', 'woocommerce' ), |
| 940 | 940 | 'enum' => array( 'asc', 'desc' ), |
@@ -942,7 +942,7 @@ discard block |
||
| 942 | 942 | 'type' => 'string', |
| 943 | 943 | 'validate_callback' => 'rest_validate_request_arg', |
| 944 | 944 | ); |
| 945 | - $params['orderby'] = array( |
|
| 945 | + $params[ 'orderby' ] = array( |
|
| 946 | 946 | 'default' => 'name', |
| 947 | 947 | 'description' => __( 'Sort collection by object attribute.', 'woocommerce' ), |
| 948 | 948 | 'enum' => array( |
@@ -955,13 +955,13 @@ discard block |
||
| 955 | 955 | 'type' => 'string', |
| 956 | 956 | 'validate_callback' => 'rest_validate_request_arg', |
| 957 | 957 | ); |
| 958 | - $params['email'] = array( |
|
| 958 | + $params[ 'email' ] = array( |
|
| 959 | 959 | 'description' => __( 'Limit result set to resources with a specific email.', 'woocommerce' ), |
| 960 | 960 | 'type' => 'string', |
| 961 | 961 | 'format' => 'email', |
| 962 | 962 | 'validate_callback' => 'rest_validate_request_arg', |
| 963 | 963 | ); |
| 964 | - $params['role'] = array( |
|
| 964 | + $params[ 'role' ] = array( |
|
| 965 | 965 | 'description' => __( 'Limit result set to resources with a specific role.', 'woocommerce' ), |
| 966 | 966 | 'type' => 'string', |
| 967 | 967 | 'default' => 'customer', |
@@ -46,7 +46,7 @@ |
||
| 46 | 46 | 'count' => (int) $item->count, |
| 47 | 47 | ); |
| 48 | 48 | |
| 49 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
| 49 | + $context = ! empty( $request[ 'context' ] ) ? $request[ 'context' ] : 'view'; |
|
| 50 | 50 | $data = $this->add_additional_fields_to_object( $data, $request ); |
| 51 | 51 | $data = $this->filter_response_by_context( $data, $context ); |
| 52 | 52 | |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | if ( $image_id ) { |
| 62 | 62 | $attachment = get_post( $image_id ); |
| 63 | 63 | |
| 64 | - $data['image'] = array( |
|
| 64 | + $data[ 'image' ] = array( |
|
| 65 | 65 | 'id' => (int) $image_id, |
| 66 | 66 | 'date_created' => wc_rest_prepare_date_response( $attachment->post_date ), |
| 67 | 67 | 'date_created_gmt' => wc_rest_prepare_date_response( $attachment->post_date_gmt ), |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | ); |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
| 76 | + $context = ! empty( $request[ 'context' ] ) ? $request[ 'context' ] : 'view'; |
|
| 77 | 77 | $data = $this->add_additional_fields_to_object( $data, $request ); |
| 78 | 78 | $data = $this->filter_response_by_context( $data, $context ); |
| 79 | 79 | |
@@ -105,17 +105,17 @@ discard block |
||
| 105 | 105 | protected function update_term_meta_fields( $term, $request ) { |
| 106 | 106 | $id = (int) $term->term_id; |
| 107 | 107 | |
| 108 | - if ( isset( $request['display'] ) ) { |
|
| 109 | - update_term_meta( $id, 'display_type', 'default' === $request['display'] ? '' : $request['display'] ); |
|
| 108 | + if ( isset( $request[ 'display' ] ) ) { |
|
| 109 | + update_term_meta( $id, 'display_type', 'default' === $request[ 'display' ] ? '' : $request[ 'display' ] ); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | - if ( isset( $request['menu_order'] ) ) { |
|
| 113 | - update_term_meta( $id, 'order', $request['menu_order'] ); |
|
| 112 | + if ( isset( $request[ 'menu_order' ] ) ) { |
|
| 113 | + update_term_meta( $id, 'order', $request[ 'menu_order' ] ); |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | - if ( isset( $request['image'] ) ) { |
|
| 117 | - if ( empty( $request['image']['id'] ) && ! empty( $request['image']['src'] ) ) { |
|
| 118 | - $upload = wc_rest_upload_image_from_url( esc_url_raw( $request['image']['src'] ) ); |
|
| 116 | + if ( isset( $request[ 'image' ] ) ) { |
|
| 117 | + if ( empty( $request[ 'image' ][ 'id' ] ) && ! empty( $request[ 'image' ][ 'src' ] ) ) { |
|
| 118 | + $upload = wc_rest_upload_image_from_url( esc_url_raw( $request[ 'image' ][ 'src' ] ) ); |
|
| 119 | 119 | |
| 120 | 120 | if ( is_wp_error( $upload ) ) { |
| 121 | 121 | return $upload; |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | |
| 124 | 124 | $image_id = wc_rest_set_uploaded_image_as_attachment( $upload ); |
| 125 | 125 | } else { |
| 126 | - $image_id = isset( $request['image']['id'] ) ? absint( $request['image']['id'] ) : 0; |
|
| 126 | + $image_id = isset( $request[ 'image' ][ 'id' ] ) ? absint( $request[ 'image' ][ 'id' ] ) : 0; |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | // Check if image_id is a valid image attachment before updating the term meta. |
@@ -131,16 +131,16 @@ discard block |
||
| 131 | 131 | update_term_meta( $id, 'thumbnail_id', $image_id ); |
| 132 | 132 | |
| 133 | 133 | // Set the image alt. |
| 134 | - if ( ! empty( $request['image']['alt'] ) ) { |
|
| 135 | - update_post_meta( $image_id, '_wp_attachment_image_alt', wc_clean( $request['image']['alt'] ) ); |
|
| 134 | + if ( ! empty( $request[ 'image' ][ 'alt' ] ) ) { |
|
| 135 | + update_post_meta( $image_id, '_wp_attachment_image_alt', wc_clean( $request[ 'image' ][ 'alt' ] ) ); |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | // Set the image title. |
| 139 | - if ( ! empty( $request['image']['name'] ) ) { |
|
| 139 | + if ( ! empty( $request[ 'image' ][ 'name' ] ) ) { |
|
| 140 | 140 | wp_update_post( |
| 141 | 141 | array( |
| 142 | 142 | 'ID' => $image_id, |
| 143 | - 'post_title' => wc_clean( $request['image']['name'] ), |
|
| 143 | + 'post_title' => wc_clean( $request[ 'image' ][ 'name' ] ), |
|
| 144 | 144 | ) |
| 145 | 145 | ); |
| 146 | 146 | } |
@@ -165,32 +165,32 @@ discard block |
||
| 165 | 165 | |
| 166 | 166 | return array( |
| 167 | 167 | 'id' => $object->get_id(), |
| 168 | - 'code' => $data['code'], |
|
| 169 | - 'amount' => $data['amount'], |
|
| 170 | - 'date_created' => $data['date_created'], |
|
| 171 | - 'date_created_gmt' => $data['date_created_gmt'], |
|
| 172 | - 'date_modified' => $data['date_modified'], |
|
| 173 | - 'date_modified_gmt' => $data['date_modified_gmt'], |
|
| 174 | - 'discount_type' => $data['discount_type'], |
|
| 175 | - 'description' => $data['description'], |
|
| 176 | - 'date_expires' => $data['date_expires'], |
|
| 177 | - 'date_expires_gmt' => $data['date_expires_gmt'], |
|
| 178 | - 'usage_count' => $data['usage_count'], |
|
| 179 | - 'individual_use' => $data['individual_use'], |
|
| 180 | - 'product_ids' => $data['product_ids'], |
|
| 181 | - 'excluded_product_ids' => $data['excluded_product_ids'], |
|
| 182 | - 'usage_limit' => $data['usage_limit'], |
|
| 183 | - 'usage_limit_per_user' => $data['usage_limit_per_user'], |
|
| 184 | - 'limit_usage_to_x_items' => $data['limit_usage_to_x_items'], |
|
| 185 | - 'free_shipping' => $data['free_shipping'], |
|
| 186 | - 'product_categories' => $data['product_categories'], |
|
| 187 | - 'excluded_product_categories' => $data['excluded_product_categories'], |
|
| 188 | - 'exclude_sale_items' => $data['exclude_sale_items'], |
|
| 189 | - 'minimum_amount' => $data['minimum_amount'], |
|
| 190 | - 'maximum_amount' => $data['maximum_amount'], |
|
| 191 | - 'email_restrictions' => $data['email_restrictions'], |
|
| 192 | - 'used_by' => $data['used_by'], |
|
| 193 | - 'meta_data' => $data['meta_data'], |
|
| 168 | + 'code' => $data[ 'code' ], |
|
| 169 | + 'amount' => $data[ 'amount' ], |
|
| 170 | + 'date_created' => $data[ 'date_created' ], |
|
| 171 | + 'date_created_gmt' => $data[ 'date_created_gmt' ], |
|
| 172 | + 'date_modified' => $data[ 'date_modified' ], |
|
| 173 | + 'date_modified_gmt' => $data[ 'date_modified_gmt' ], |
|
| 174 | + 'discount_type' => $data[ 'discount_type' ], |
|
| 175 | + 'description' => $data[ 'description' ], |
|
| 176 | + 'date_expires' => $data[ 'date_expires' ], |
|
| 177 | + 'date_expires_gmt' => $data[ 'date_expires_gmt' ], |
|
| 178 | + 'usage_count' => $data[ 'usage_count' ], |
|
| 179 | + 'individual_use' => $data[ 'individual_use' ], |
|
| 180 | + 'product_ids' => $data[ 'product_ids' ], |
|
| 181 | + 'excluded_product_ids' => $data[ 'excluded_product_ids' ], |
|
| 182 | + 'usage_limit' => $data[ 'usage_limit' ], |
|
| 183 | + 'usage_limit_per_user' => $data[ 'usage_limit_per_user' ], |
|
| 184 | + 'limit_usage_to_x_items' => $data[ 'limit_usage_to_x_items' ], |
|
| 185 | + 'free_shipping' => $data[ 'free_shipping' ], |
|
| 186 | + 'product_categories' => $data[ 'product_categories' ], |
|
| 187 | + 'excluded_product_categories' => $data[ 'excluded_product_categories' ], |
|
| 188 | + 'exclude_sale_items' => $data[ 'exclude_sale_items' ], |
|
| 189 | + 'minimum_amount' => $data[ 'minimum_amount' ], |
|
| 190 | + 'maximum_amount' => $data[ 'maximum_amount' ], |
|
| 191 | + 'email_restrictions' => $data[ 'email_restrictions' ], |
|
| 192 | + 'used_by' => $data[ 'used_by' ], |
|
| 193 | + 'meta_data' => $data[ 'meta_data' ], |
|
| 194 | 194 | ); |
| 195 | 195 | } |
| 196 | 196 | |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | */ |
| 205 | 205 | public function prepare_object_for_response( $object, $request ) { |
| 206 | 206 | $data = $this->get_formatted_item_data( $object ); |
| 207 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
| 207 | + $context = ! empty( $request[ 'context' ] ) ? $request[ 'context' ] : 'view'; |
|
| 208 | 208 | $data = $this->add_additional_fields_to_object( $data, $request ); |
| 209 | 209 | $data = $this->filter_response_by_context( $data, $context ); |
| 210 | 210 | $response = rest_ensure_response( $data ); |
@@ -233,14 +233,14 @@ discard block |
||
| 233 | 233 | protected function prepare_objects_query( $request ) { |
| 234 | 234 | $args = parent::prepare_objects_query( $request ); |
| 235 | 235 | |
| 236 | - if ( ! empty( $request['code'] ) ) { |
|
| 237 | - $id = wc_get_coupon_id_by_code( $request['code'] ); |
|
| 238 | - $args['post__in'] = array( $id ); |
|
| 236 | + if ( ! empty( $request[ 'code' ] ) ) { |
|
| 237 | + $id = wc_get_coupon_id_by_code( $request[ 'code' ] ); |
|
| 238 | + $args[ 'post__in' ] = array( $id ); |
|
| 239 | 239 | } |
| 240 | 240 | |
| 241 | - if ( ! empty( $request['search'] ) ) { |
|
| 242 | - $args['search'] = $request['search']; |
|
| 243 | - $args['s'] = false; |
|
| 241 | + if ( ! empty( $request[ 'search' ] ) ) { |
|
| 242 | + $args[ 'search' ] = $request[ 'search' ]; |
|
| 243 | + $args[ 's' ] = false; |
|
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | return $args; |
@@ -254,13 +254,13 @@ discard block |
||
| 254 | 254 | * @return \WP_Error|WC_Data |
| 255 | 255 | */ |
| 256 | 256 | protected function prepare_object_for_database( $request, $creating = false ) { |
| 257 | - $id = isset( $request['id'] ) ? absint( $request['id'] ) : 0; |
|
| 257 | + $id = isset( $request[ 'id' ] ) ? absint( $request[ 'id' ] ) : 0; |
|
| 258 | 258 | $coupon = new \WC_Coupon( $id ); |
| 259 | 259 | $schema = $this->get_item_schema(); |
| 260 | - $data_keys = array_keys( array_filter( $schema['properties'], array( $this, 'filter_writable_props' ) ) ); |
|
| 260 | + $data_keys = array_keys( array_filter( $schema[ 'properties' ], array( $this, 'filter_writable_props' ) ) ); |
|
| 261 | 261 | |
| 262 | 262 | // Validate required POST fields. |
| 263 | - if ( $creating && empty( $request['code'] ) ) { |
|
| 263 | + if ( $creating && empty( $request[ 'code' ] ) ) { |
|
| 264 | 264 | return new \WP_Error( 'woocommerce_rest_empty_coupon_code', sprintf( __( 'The coupon code cannot be empty.', 'woocommerce' ), 'code' ), array( 'status' => 400 ) ); |
| 265 | 265 | } |
| 266 | 266 | |
@@ -284,7 +284,7 @@ discard block |
||
| 284 | 284 | case 'meta_data': |
| 285 | 285 | if ( is_array( $value ) ) { |
| 286 | 286 | foreach ( $value as $meta ) { |
| 287 | - $coupon->update_meta_data( $meta['key'], $meta['value'], isset( $meta['id'] ) ? $meta['id'] : '' ); |
|
| 287 | + $coupon->update_meta_data( $meta[ 'key' ], $meta[ 'value' ], isset( $meta[ 'id' ] ) ? $meta[ 'id' ] : '' ); |
|
| 288 | 288 | } |
| 289 | 289 | } |
| 290 | 290 | break; |
@@ -523,14 +523,14 @@ discard block |
||
| 523 | 523 | public function get_collection_params() { |
| 524 | 524 | $params = parent::get_collection_params(); |
| 525 | 525 | |
| 526 | - $params['code'] = array( |
|
| 526 | + $params[ 'code' ] = array( |
|
| 527 | 527 | 'description' => __( 'Limit result set to resources with a specific code.', 'woocommerce' ), |
| 528 | 528 | 'type' => 'string', |
| 529 | 529 | 'sanitize_callback' => 'sanitize_text_field', |
| 530 | 530 | 'validate_callback' => 'rest_validate_request_arg', |
| 531 | 531 | ); |
| 532 | 532 | |
| 533 | - $params['search'] = array( |
|
| 533 | + $params[ 'search' ] = array( |
|
| 534 | 534 | 'description' => __( 'Limit results to coupons with codes matching a given string.', 'woocommerce' ), |
| 535 | 535 | 'type' => 'string', |
| 536 | 536 | 'validate_callback' => 'rest_validate_request_arg', |
@@ -546,7 +546,7 @@ discard block |
||
| 546 | 546 | * @return bool |
| 547 | 547 | */ |
| 548 | 548 | protected function filter_writable_props( $schema ) { |
| 549 | - return empty( $schema['readonly'] ); |
|
| 549 | + return empty( $schema[ 'readonly' ] ); |
|
| 550 | 550 | } |
| 551 | 551 | |
| 552 | 552 | /** |
@@ -143,7 +143,7 @@ discard block |
||
| 143 | 143 | * @return \WP_Error|boolean |
| 144 | 144 | */ |
| 145 | 145 | public function get_item_permissions_check( $request ) { |
| 146 | - $order = wc_get_order( (int) $request['order_id'] ); |
|
| 146 | + $order = wc_get_order( (int) $request[ 'order_id' ] ); |
|
| 147 | 147 | |
| 148 | 148 | if ( $order && ! wc_rest_check_post_permissions( $this->post_type, 'read', $order->get_id() ) ) { |
| 149 | 149 | return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | * @return bool|\WP_Error |
| 161 | 161 | */ |
| 162 | 162 | public function delete_item_permissions_check( $request ) { |
| 163 | - $order = wc_get_order( (int) $request['order_id'] ); |
|
| 163 | + $order = wc_get_order( (int) $request[ 'order_id' ] ); |
|
| 164 | 164 | |
| 165 | 165 | if ( $order && ! wc_rest_check_post_permissions( $this->post_type, 'delete', $order->get_id() ) ) { |
| 166 | 166 | return new \WP_Error( 'woocommerce_rest_cannot_delete', __( 'Sorry, you are not allowed to delete this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | * @return array|\WP_Error |
| 178 | 178 | */ |
| 179 | 179 | public function get_items( $request ) { |
| 180 | - $order = wc_get_order( (int) $request['order_id'] ); |
|
| 180 | + $order = wc_get_order( (int) $request[ 'order_id' ] ); |
|
| 181 | 181 | |
| 182 | 182 | if ( ! $order || $this->post_type !== $order->get_type() ) { |
| 183 | 183 | return new \WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'Invalid order ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
@@ -190,16 +190,16 @@ discard block |
||
| 190 | 190 | ); |
| 191 | 191 | |
| 192 | 192 | // Allow filter by order note type. |
| 193 | - if ( 'customer' === $request['type'] ) { |
|
| 194 | - $args['meta_query'] = array( // WPCS: slow query ok. |
|
| 193 | + if ( 'customer' === $request[ 'type' ] ) { |
|
| 194 | + $args[ 'meta_query' ] = array( // WPCS: slow query ok. |
|
| 195 | 195 | array( |
| 196 | 196 | 'key' => 'is_customer_note', |
| 197 | 197 | 'value' => 1, |
| 198 | 198 | 'compare' => '=', |
| 199 | 199 | ), |
| 200 | 200 | ); |
| 201 | - } elseif ( 'internal' === $request['type'] ) { |
|
| 202 | - $args['meta_query'] = array( // WPCS: slow query ok. |
|
| 201 | + } elseif ( 'internal' === $request[ 'type' ] ) { |
|
| 202 | + $args[ 'meta_query' ] = array( // WPCS: slow query ok. |
|
| 203 | 203 | array( |
| 204 | 204 | 'key' => 'is_customer_note', |
| 205 | 205 | 'compare' => 'NOT EXISTS', |
@@ -217,7 +217,7 @@ discard block |
||
| 217 | 217 | foreach ( $notes as $note ) { |
| 218 | 218 | $order_note = $this->prepare_item_for_response( $note, $request ); |
| 219 | 219 | $order_note = $this->prepare_response_for_collection( $order_note ); |
| 220 | - $data[] = $order_note; |
|
| 220 | + $data[ ] = $order_note; |
|
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | return rest_ensure_response( $data ); |
@@ -230,19 +230,19 @@ discard block |
||
| 230 | 230 | * @return \WP_Error\WP_REST_Response |
| 231 | 231 | */ |
| 232 | 232 | public function create_item( $request ) { |
| 233 | - if ( ! empty( $request['id'] ) ) { |
|
| 233 | + if ( ! empty( $request[ 'id' ] ) ) { |
|
| 234 | 234 | /* translators: %s: post type */ |
| 235 | 235 | return new \WP_Error( "woocommerce_rest_{$this->post_type}_exists", sprintf( __( 'Cannot create existing %s.', 'woocommerce' ), $this->post_type ), array( 'status' => 400 ) ); |
| 236 | 236 | } |
| 237 | 237 | |
| 238 | - $order = wc_get_order( (int) $request['order_id'] ); |
|
| 238 | + $order = wc_get_order( (int) $request[ 'order_id' ] ); |
|
| 239 | 239 | |
| 240 | 240 | if ( ! $order || $this->post_type !== $order->get_type() ) { |
| 241 | 241 | return new \WP_Error( 'woocommerce_rest_order_invalid_id', __( 'Invalid order ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | // Create the note. |
| 245 | - $note_id = $order->add_order_note( $request['note'], $request['customer_note'], $request['added_by_user'] ); |
|
| 245 | + $note_id = $order->add_order_note( $request[ 'note' ], $request[ 'customer_note' ], $request[ 'added_by_user' ] ); |
|
| 246 | 246 | |
| 247 | 247 | if ( ! $note_id ) { |
| 248 | 248 | return new \WP_Error( 'woocommerce_api_cannot_create_order_note', __( 'Cannot create order note, please try again.', 'woocommerce' ), array( 'status' => 500 ) ); |
@@ -276,8 +276,8 @@ discard block |
||
| 276 | 276 | * @return \WP_Error\WP_REST_Response |
| 277 | 277 | */ |
| 278 | 278 | public function get_item( $request ) { |
| 279 | - $id = (int) $request['id']; |
|
| 280 | - $order = wc_get_order( (int) $request['order_id'] ); |
|
| 279 | + $id = (int) $request[ 'id' ]; |
|
| 280 | + $order = wc_get_order( (int) $request[ 'order_id' ] ); |
|
| 281 | 281 | |
| 282 | 282 | if ( ! $order || $this->post_type !== $order->get_type() ) { |
| 283 | 283 | return new \WP_Error( 'woocommerce_rest_order_invalid_id', __( 'Invalid order ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
@@ -302,15 +302,15 @@ discard block |
||
| 302 | 302 | * @return \WP_REST_Response|\WP_Error |
| 303 | 303 | */ |
| 304 | 304 | public function delete_item( $request ) { |
| 305 | - $id = (int) $request['id']; |
|
| 306 | - $force = isset( $request['force'] ) ? (bool) $request['force'] : false; |
|
| 305 | + $id = (int) $request[ 'id' ]; |
|
| 306 | + $force = isset( $request[ 'force' ] ) ? (bool) $request[ 'force' ] : false; |
|
| 307 | 307 | |
| 308 | 308 | // We don't support trashing for this type, error out. |
| 309 | 309 | if ( ! $force ) { |
| 310 | 310 | return new \WP_Error( 'woocommerce_rest_trash_not_supported', __( 'Webhooks do not support trashing.', 'woocommerce' ), array( 'status' => 501 ) ); |
| 311 | 311 | } |
| 312 | 312 | |
| 313 | - $order = wc_get_order( (int) $request['order_id'] ); |
|
| 313 | + $order = wc_get_order( (int) $request[ 'order_id' ] ); |
|
| 314 | 314 | |
| 315 | 315 | if ( ! $order || $this->post_type !== $order->get_type() ) { |
| 316 | 316 | return new \WP_Error( 'woocommerce_rest_order_invalid_id', __( 'Invalid order ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
@@ -367,7 +367,7 @@ discard block |
||
| 367 | 367 | 'customer_note' => (bool) get_comment_meta( $note->comment_ID, 'is_customer_note', true ), |
| 368 | 368 | ); |
| 369 | 369 | |
| 370 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
| 370 | + $context = ! empty( $request[ 'context' ] ) ? $request[ 'context' ] : 'view'; |
|
| 371 | 371 | $data = $this->add_additional_fields_to_object( $data, $request ); |
| 372 | 372 | $data = $this->filter_response_by_context( $data, $context ); |
| 373 | 373 | |
@@ -475,8 +475,8 @@ discard block |
||
| 475 | 475 | */ |
| 476 | 476 | public function get_collection_params() { |
| 477 | 477 | $params = array(); |
| 478 | - $params['context'] = $this->get_context_param( array( 'default' => 'view' ) ); |
|
| 479 | - $params['type'] = array( |
|
| 478 | + $params[ 'context' ] = $this->get_context_param( array( 'default' => 'view' ) ); |
|
| 479 | + $params[ 'type' ] = array( |
|
| 480 | 480 | 'default' => 'any', |
| 481 | 481 | 'description' => __( 'Limit result to customers or internal notes.', 'woocommerce' ), |
| 482 | 482 | 'type' => 'string', |