@@ -138,10 +138,10 @@ |
||
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | /** |
| 141 | - * Test the sanitization of the payment_method_title field through the API. |
|
| 142 | - * |
|
| 143 | - * @since 3.5.2 |
|
| 144 | - */ |
|
| 141 | + * Test the sanitization of the payment_method_title field through the API. |
|
| 142 | + * |
|
| 143 | + * @since 3.5.2 |
|
| 144 | + */ |
|
| 145 | 145 | public function test_create_update_order_payment_method_title_sanitize() { |
| 146 | 146 | $product = ProductHelper::create_simple_product(); |
| 147 | 147 | $data = [ |
@@ -185,22 +185,22 @@ discard block |
||
| 185 | 185 | ), |
| 186 | 186 | ]; |
| 187 | 187 | $response = $this->do_request( '/wc/v4/orders', 'POST', $data ); |
| 188 | - $order = wc_get_order( $response->data['id'] ); |
|
| 188 | + $order = wc_get_order( $response->data[ 'id' ] ); |
|
| 189 | 189 | $this->assertExpectedResponse( $response, 201 ); |
| 190 | - $this->assertEquals( $order->get_payment_method(), $response->data['payment_method'] ); |
|
| 190 | + $this->assertEquals( $order->get_payment_method(), $response->data[ 'payment_method' ] ); |
|
| 191 | 191 | $this->assertEquals( $order->get_payment_method_title(), 'Sanitize this' ); |
| 192 | 192 | |
| 193 | 193 | // Test when updating order. |
| 194 | 194 | $response = $this->do_request( |
| 195 | - '/wc/v4/orders/' . $response->data['id'], |
|
| 195 | + '/wc/v4/orders/' . $response->data[ 'id' ], |
|
| 196 | 196 | 'POST', [ |
| 197 | 197 | 'payment_method' => 'bacs', |
| 198 | 198 | 'payment_method_title' => '<h1>Sanitize this too <script>alert(1);</script></h1>', |
| 199 | 199 | ] |
| 200 | 200 | ); |
| 201 | - $order = wc_get_order( $response->data['id'] ); |
|
| 201 | + $order = wc_get_order( $response->data[ 'id' ] ); |
|
| 202 | 202 | $this->assertExpectedResponse( $response, 200 ); |
| 203 | - $this->assertEquals( $order->get_payment_method(), $response->data['payment_method'] ); |
|
| 203 | + $this->assertEquals( $order->get_payment_method(), $response->data[ 'payment_method' ] ); |
|
| 204 | 204 | $this->assertEquals( $order->get_payment_method_title(), 'Sanitize this too' ); |
| 205 | 205 | } |
| 206 | 206 | |
@@ -259,25 +259,25 @@ discard block |
||
| 259 | 259 | * Test read. |
| 260 | 260 | */ |
| 261 | 261 | public function test_read() { |
| 262 | - $product = ProductHelper::create_simple_product(); |
|
| 262 | + $product = ProductHelper::create_simple_product(); |
|
| 263 | 263 | $product->set_regular_price( 10.95 ); |
| 264 | 264 | $product->set_sale_price( false ); |
| 265 | 265 | $product->save(); |
| 266 | 266 | $customer = CustomerHelper::create_customer(); |
| 267 | - $orders = []; |
|
| 268 | - $orders[] = OrderHelper::create_order( $customer->get_id(), $product ); |
|
| 267 | + $orders = [ ]; |
|
| 268 | + $orders[ ] = OrderHelper::create_order( $customer->get_id(), $product ); |
|
| 269 | 269 | |
| 270 | 270 | // Create orders. |
| 271 | 271 | for ( $i = 0; $i < 9; $i++ ) { |
| 272 | - $orders[] = OrderHelper::create_order( $this->user ); |
|
| 272 | + $orders[ ] = OrderHelper::create_order( $this->user ); |
|
| 273 | 273 | } |
| 274 | 274 | |
| 275 | - $orders[5]->set_status( 'on-hold' ); |
|
| 276 | - $orders[5]->save(); |
|
| 277 | - $orders[6]->set_status( 'on-hold' ); |
|
| 278 | - $orders[6]->save(); |
|
| 279 | - $orders[0]->calculate_totals(); |
|
| 280 | - $orders[0]->save(); |
|
| 275 | + $orders[ 5 ]->set_status( 'on-hold' ); |
|
| 276 | + $orders[ 5 ]->save(); |
|
| 277 | + $orders[ 6 ]->set_status( 'on-hold' ); |
|
| 278 | + $orders[ 6 ]->save(); |
|
| 279 | + $orders[ 0 ]->calculate_totals(); |
|
| 280 | + $orders[ 0 ]->save(); |
|
| 281 | 281 | |
| 282 | 282 | // Collection. |
| 283 | 283 | $response = $this->do_request( '/wc/v4/orders', 'GET' ); |
@@ -289,7 +289,7 @@ discard block |
||
| 289 | 289 | $this->assertExpectedResponse( $response, 200 ); |
| 290 | 290 | $this->assertEquals( 2, count( $response->data ) ); |
| 291 | 291 | |
| 292 | - $response = $this->do_request( '/wc/v4/orders', 'GET', [ 'number' => (string) $orders[0]->get_id() ] ); |
|
| 292 | + $response = $this->do_request( '/wc/v4/orders', 'GET', [ 'number' => (string) $orders[ 0 ]->get_id() ] ); |
|
| 293 | 293 | $this->assertExpectedResponse( $response, 200 ); |
| 294 | 294 | $this->assertEquals( 1, count( $response->data ) ); |
| 295 | 295 | |
@@ -302,13 +302,13 @@ discard block |
||
| 302 | 302 | $this->assertEquals( 1, count( $response->data ) ); |
| 303 | 303 | |
| 304 | 304 | // Single collection args. |
| 305 | - $response = $this->do_request( '/wc/v4/orders/' . $orders[0]->get_id(), 'GET', [ 'dp' => 0 ] ); |
|
| 306 | - $this->assertEquals( '54', $response->data['total'] ); |
|
| 307 | - $response = $this->do_request( '/wc/v4/orders/' . $orders[0]->get_id(), 'GET', [ 'dp' => 2 ] ); |
|
| 308 | - $this->assertEquals( '53.80', $response->data['total'] ); |
|
| 305 | + $response = $this->do_request( '/wc/v4/orders/' . $orders[ 0 ]->get_id(), 'GET', [ 'dp' => 0 ] ); |
|
| 306 | + $this->assertEquals( '54', $response->data[ 'total' ] ); |
|
| 307 | + $response = $this->do_request( '/wc/v4/orders/' . $orders[ 0 ]->get_id(), 'GET', [ 'dp' => 2 ] ); |
|
| 308 | + $this->assertEquals( '53.80', $response->data[ 'total' ] ); |
|
| 309 | 309 | |
| 310 | 310 | // Single. |
| 311 | - $response = $this->do_request( '/wc/v4/orders/' . $orders[0]->get_id(), 'GET' ); |
|
| 311 | + $response = $this->do_request( '/wc/v4/orders/' . $orders[ 0 ]->get_id(), 'GET' ); |
|
| 312 | 312 | $this->assertExpectedResponse( $response, 200 ); |
| 313 | 313 | |
| 314 | 314 | foreach ( $this->get_properties( 'view' ) as $property ) { |
@@ -480,7 +480,7 @@ discard block |
||
| 480 | 480 | ] |
| 481 | 481 | ); |
| 482 | 482 | $this->assertEquals( 400, $response->status ); |
| 483 | - $this->assertEquals( 'Invalid parameter(s): status', $response->data['message'] ); |
|
| 483 | + $this->assertEquals( 'Invalid parameter(s): status', $response->data[ 'message' ] ); |
|
| 484 | 484 | |
| 485 | 485 | $response = $this->do_request( |
| 486 | 486 | '/wc/v4/orders/' . $order->get_id(), |
@@ -490,7 +490,7 @@ discard block |
||
| 490 | 490 | ] |
| 491 | 491 | ); |
| 492 | 492 | $this->assertEquals( 400, $response->status ); |
| 493 | - $this->assertEquals( 'Invalid parameter(s): currency', $response->data['message'] ); |
|
| 493 | + $this->assertEquals( 'Invalid parameter(s): currency', $response->data[ 'message' ] ); |
|
| 494 | 494 | } |
| 495 | 495 | |
| 496 | 496 | /** |
@@ -517,9 +517,9 @@ discard block |
||
| 517 | 517 | ), |
| 518 | 518 | ) |
| 519 | 519 | ); |
| 520 | - $this->assertEquals( 'updated', $result->data['update'][0]['payment_method'] ); |
|
| 521 | - $this->assertEquals( $order2->get_id(), $result->data['delete'][0]['previous']['id'] ); |
|
| 522 | - $this->assertEquals( $order3->get_id(), $result->data['delete'][1]['previous']['id'] ); |
|
| 520 | + $this->assertEquals( 'updated', $result->data[ 'update' ][ 0 ][ 'payment_method' ] ); |
|
| 521 | + $this->assertEquals( $order2->get_id(), $result->data[ 'delete' ][ 0 ][ 'previous' ][ 'id' ] ); |
|
| 522 | + $this->assertEquals( $order3->get_id(), $result->data[ 'delete' ][ 1 ][ 'previous' ][ 'id' ] ); |
|
| 523 | 523 | |
| 524 | 524 | $result = $this->do_request( '/wc/v4/orders' ); |
| 525 | 525 | $this->assertEquals( 1, count( $result->data ) ); |
@@ -558,7 +558,7 @@ discard block |
||
| 558 | 558 | ] |
| 559 | 559 | ); |
| 560 | 560 | $this->assertEquals( 200, $response->status ); |
| 561 | - $this->assertTrue( empty( $response->data['fee_lines'] ) ); |
|
| 561 | + $this->assertTrue( empty( $response->data[ 'fee_lines' ] ) ); |
|
| 562 | 562 | } |
| 563 | 563 | |
| 564 | 564 | /** |
@@ -585,8 +585,8 @@ discard block |
||
| 585 | 585 | ] |
| 586 | 586 | ); |
| 587 | 587 | $this->assertEquals( 200, $response->status ); |
| 588 | - $this->assertCount( 1, $response->data['coupon_lines'] ); |
|
| 589 | - $this->assertEquals( '45.00', $response->data['total'] ); |
|
| 588 | + $this->assertCount( 1, $response->data[ 'coupon_lines' ] ); |
|
| 589 | + $this->assertEquals( '45.00', $response->data[ 'total' ] ); |
|
| 590 | 590 | } |
| 591 | 591 | |
| 592 | 592 | /** |
@@ -627,8 +627,8 @@ discard block |
||
| 627 | 627 | ] |
| 628 | 628 | ); |
| 629 | 629 | $this->assertEquals( 200, $response->status ); |
| 630 | - $this->assertTrue( empty( $response->data['coupon_lines'] ) ); |
|
| 631 | - $this->assertEquals( '50.00', $response->data['total'] ); |
|
| 630 | + $this->assertTrue( empty( $response->data[ 'coupon_lines' ] ) ); |
|
| 631 | + $this->assertEquals( '50.00', $response->data[ 'total' ] ); |
|
| 632 | 632 | } |
| 633 | 633 | |
| 634 | 634 | /** |
@@ -650,7 +650,7 @@ discard block |
||
| 650 | 650 | ] |
| 651 | 651 | ); |
| 652 | 652 | $this->assertEquals( 400, $response->status ); |
| 653 | - $this->assertEquals( 'woocommerce_rest_invalid_coupon', $response->data['code'] ); |
|
| 654 | - $this->assertEquals( 'Coupon "non_existing_coupon" does not exist!', $response->data['message'] ); |
|
| 653 | + $this->assertEquals( 'woocommerce_rest_invalid_coupon', $response->data[ 'code' ] ); |
|
| 654 | + $this->assertEquals( 'Coupon "non_existing_coupon" does not exist!', $response->data[ 'message' ] ); |
|
| 655 | 655 | } |
| 656 | 656 | } |
@@ -22,7 +22,7 @@ |
||
| 22 | 22 | * |
| 23 | 23 | * @var array |
| 24 | 24 | */ |
| 25 | - protected $controllers = []; |
|
| 25 | + protected $controllers = [ ]; |
|
| 26 | 26 | |
| 27 | 27 | /** |
| 28 | 28 | * Hook into WordPress ready to init the REST API as needed. |
@@ -102,7 +102,7 @@ |
||
| 102 | 102 | |
| 103 | 103 | foreach ( $resources as $resource ) { |
| 104 | 104 | $item = $this->prepare_item_for_response( (object) $resource, $request ); |
| 105 | - $data[] = $this->prepare_response_for_collection( $item ); |
|
| 105 | + $data[ ] = $this->prepare_response_for_collection( $item ); |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | return rest_ensure_response( $data ); |
@@ -57,7 +57,7 @@ |
||
| 57 | 57 | |
| 58 | 58 | if ( ! is_null( $meta_data ) ) { |
| 59 | 59 | foreach ( $meta_data as $meta ) { |
| 60 | - $object->update_meta_data( $meta['key'], $meta['value'], isset( $meta['id'] ) ? $meta['id'] : '' ); |
|
| 60 | + $object->update_meta_data( $meta[ 'key' ], $meta[ 'value' ], isset( $meta[ 'id' ] ) ? $meta[ 'id' ] : '' ); |
|
| 61 | 61 | } |
| 62 | 62 | } |
| 63 | 63 | } |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | ]; |
| 55 | 55 | |
| 56 | 56 | $request_props = array_intersect_key( $this->request, array_flip( $props ) ); |
| 57 | - $prop_values = []; |
|
| 57 | + $prop_values = [ ]; |
|
| 58 | 58 | |
| 59 | 59 | foreach ( $request_props as $prop => $value ) { |
| 60 | 60 | switch ( $prop ) { |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | * @return array |
| 95 | 95 | */ |
| 96 | 96 | protected function parse_address_field( $data, $object, $type = 'billing' ) { |
| 97 | - $address = []; |
|
| 97 | + $address = [ ]; |
|
| 98 | 98 | foreach ( $data as $key => $value ) { |
| 99 | 99 | if ( is_callable( array( $object, "set_{$type}_{$key}" ) ) ) { |
| 100 | 100 | $address[ "{$type}_{$key}" ] = $value; |
@@ -77,22 +77,22 @@ discard block |
||
| 77 | 77 | ]; |
| 78 | 78 | |
| 79 | 79 | $request_props = array_intersect_key( $this->request, array_flip( $props ) ); |
| 80 | - $prop_values = []; |
|
| 80 | + $prop_values = [ ]; |
|
| 81 | 81 | |
| 82 | 82 | foreach ( $request_props as $prop => $value ) { |
| 83 | 83 | switch ( $prop ) { |
| 84 | 84 | case 'image': |
| 85 | - $prop_values['image_id'] = $this->parse_image_field( $value, $object ); |
|
| 85 | + $prop_values[ 'image_id' ] = $this->parse_image_field( $value, $object ); |
|
| 86 | 86 | break; |
| 87 | 87 | case 'attributes': |
| 88 | - $prop_values['attributes'] = $this->parse_attributes_field( $value, $object ); |
|
| 88 | + $prop_values[ 'attributes' ] = $this->parse_attributes_field( $value, $object ); |
|
| 89 | 89 | break; |
| 90 | 90 | case 'dimensions': |
| 91 | 91 | $dimensions = $this->parse_dimensions_fields( $value ); |
| 92 | 92 | $prop_values = array_merge( $prop_values, $dimensions ); |
| 93 | 93 | break; |
| 94 | 94 | case 'shipping_class': |
| 95 | - $prop_values['shipping_class_id'] = $this->parse_shipping_class( $value, $object ); |
|
| 95 | + $prop_values[ 'shipping_class_id' ] = $this->parse_shipping_class( $value, $object ); |
|
| 96 | 96 | break; |
| 97 | 97 | default: |
| 98 | 98 | $prop_values[ $prop ] = $value; |
@@ -120,11 +120,11 @@ discard block |
||
| 120 | 120 | $attribute_name = ''; |
| 121 | 121 | |
| 122 | 122 | // Check ID for global attributes or name for product attributes. |
| 123 | - if ( ! empty( $attribute['id'] ) ) { |
|
| 124 | - $attribute_id = absint( $attribute['id'] ); |
|
| 123 | + if ( ! empty( $attribute[ 'id' ] ) ) { |
|
| 124 | + $attribute_id = absint( $attribute[ 'id' ] ); |
|
| 125 | 125 | $attribute_name = wc_attribute_taxonomy_name_by_id( $attribute_id ); |
| 126 | - } elseif ( ! empty( $attribute['name'] ) ) { |
|
| 127 | - $attribute_name = sanitize_title( $attribute['name'] ); |
|
| 126 | + } elseif ( ! empty( $attribute[ 'name' ] ) ) { |
|
| 127 | + $attribute_name = sanitize_title( $attribute[ 'name' ] ); |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | if ( ! $attribute_id && ! $attribute_name ) { |
@@ -136,7 +136,7 @@ discard block |
||
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | $attribute_key = sanitize_title( $parent_attributes[ $attribute_name ]->get_name() ); |
| 139 | - $attribute_value = isset( $attribute['option'] ) ? wc_clean( stripslashes( $attribute['option'] ) ) : ''; |
|
| 139 | + $attribute_value = isset( $attribute[ 'option' ] ) ? wc_clean( stripslashes( $attribute[ 'option' ] ) ) : ''; |
|
| 140 | 140 | |
| 141 | 141 | if ( $parent_attributes[ $attribute_name ]->is_taxonomy() ) { |
| 142 | 142 | // If dealing with a taxonomy, we need to get the slug from the name posted to the API. |
@@ -168,19 +168,19 @@ discard block |
||
| 168 | 168 | return ''; |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | - $attachment_id = isset( $image['id'] ) ? absint( $image['id'] ) : 0; |
|
| 171 | + $attachment_id = isset( $image[ 'id' ] ) ? absint( $image[ 'id' ] ) : 0; |
|
| 172 | 172 | $attachment = new ImageAttachment( $attachment_id, $object->get_id() ); |
| 173 | 173 | |
| 174 | - if ( 0 === $attachment->id && ! empty( $image['src'] ) ) { |
|
| 175 | - $attachment->upload_image_from_src( $image['src'] ); |
|
| 174 | + if ( 0 === $attachment->id && ! empty( $image[ 'src' ] ) ) { |
|
| 175 | + $attachment->upload_image_from_src( $image[ 'src' ] ); |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | - if ( ! empty( $image['alt'] ) ) { |
|
| 179 | - $attachment->update_alt_text( $image['alt'] ); |
|
| 178 | + if ( ! empty( $image[ 'alt' ] ) ) { |
|
| 179 | + $attachment->update_alt_text( $image[ 'alt' ] ); |
|
| 180 | 180 | } |
| 181 | 181 | |
| 182 | - if ( ! empty( $image['name'] ) ) { |
|
| 183 | - $attachment->update_name( $image['name'] ); |
|
| 182 | + if ( ! empty( $image[ 'name' ] ) ) { |
|
| 183 | + $attachment->update_name( $image[ 'name' ] ); |
|
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | return $attachment->id; |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | ]; |
| 130 | 130 | |
| 131 | 131 | $request_props = array_intersect_key( $this->request, array_flip( $props ) ); |
| 132 | - $prop_values = []; |
|
| 132 | + $prop_values = [ ]; |
|
| 133 | 133 | |
| 134 | 134 | foreach ( $request_props as $prop => $value ) { |
| 135 | 135 | switch ( $prop ) { |
@@ -146,20 +146,20 @@ discard block |
||
| 146 | 146 | $prop_values = array_merge( $prop_values, $images ); |
| 147 | 147 | break; |
| 148 | 148 | case 'categories': |
| 149 | - $prop_values['category_ids'] = wp_list_pluck( $value, 'id' ); |
|
| 149 | + $prop_values[ 'category_ids' ] = wp_list_pluck( $value, 'id' ); |
|
| 150 | 150 | break; |
| 151 | 151 | case 'tags': |
| 152 | - $prop_values['tag_ids'] = wp_list_pluck( $value, 'id' ); |
|
| 152 | + $prop_values[ 'tag_ids' ] = wp_list_pluck( $value, 'id' ); |
|
| 153 | 153 | break; |
| 154 | 154 | case 'attributes': |
| 155 | - $prop_values['attributes'] = $this->parse_attributes_field( $value ); |
|
| 155 | + $prop_values[ 'attributes' ] = $this->parse_attributes_field( $value ); |
|
| 156 | 156 | break; |
| 157 | 157 | case 'dimensions': |
| 158 | 158 | $dimensions = $this->parse_dimensions_fields( $value ); |
| 159 | 159 | $prop_values = array_merge( $prop_values, $dimensions ); |
| 160 | 160 | break; |
| 161 | 161 | case 'shipping_class': |
| 162 | - $prop_values['shipping_class_id'] = $this->parse_shipping_class( $value, $object ); |
|
| 162 | + $prop_values[ 'shipping_class_id' ] = $this->parse_shipping_class( $value, $object ); |
|
| 163 | 163 | break; |
| 164 | 164 | default: |
| 165 | 165 | $prop_values[ $prop ] = $value; |
@@ -248,34 +248,34 @@ discard block |
||
| 248 | 248 | $attributes = array(); |
| 249 | 249 | |
| 250 | 250 | foreach ( $raw_attributes as $attribute ) { |
| 251 | - if ( ! empty( $attribute['id'] ) ) { |
|
| 252 | - $attribute_id = absint( $attribute['id'] ); |
|
| 251 | + if ( ! empty( $attribute[ 'id' ] ) ) { |
|
| 252 | + $attribute_id = absint( $attribute[ 'id' ] ); |
|
| 253 | 253 | $attribute_name = wc_attribute_taxonomy_name_by_id( $attribute_id ); |
| 254 | - } elseif ( ! empty( $attribute['name'] ) ) { |
|
| 254 | + } elseif ( ! empty( $attribute[ 'name' ] ) ) { |
|
| 255 | 255 | $attribute_id = 0; |
| 256 | - $attribute_name = wc_clean( $attribute['name'] ); |
|
| 256 | + $attribute_name = wc_clean( $attribute[ 'name' ] ); |
|
| 257 | 257 | } |
| 258 | 258 | |
| 259 | - if ( ! $attribute_name || ! isset( $attribute['options'] ) ) { |
|
| 259 | + if ( ! $attribute_name || ! isset( $attribute[ 'options' ] ) ) { |
|
| 260 | 260 | continue; |
| 261 | 261 | } |
| 262 | 262 | |
| 263 | - if ( ! is_array( $attribute['options'] ) ) { |
|
| 264 | - $attribute['options'] = explode( \WC_DELIMITER, $attribute['options'] ); |
|
| 263 | + if ( ! is_array( $attribute[ 'options' ] ) ) { |
|
| 264 | + $attribute[ 'options' ] = explode( \WC_DELIMITER, $attribute[ 'options' ] ); |
|
| 265 | 265 | } |
| 266 | 266 | |
| 267 | 267 | if ( $attribute_id ) { |
| 268 | - $attribute['options'] = array_filter( array_map( 'wc_sanitize_term_text_based', $attribute['options'] ), 'strlen' ); |
|
| 268 | + $attribute[ 'options' ] = array_filter( array_map( 'wc_sanitize_term_text_based', $attribute[ 'options' ] ), 'strlen' ); |
|
| 269 | 269 | } |
| 270 | 270 | |
| 271 | 271 | $attribute_object = new \WC_Product_Attribute(); |
| 272 | 272 | $attribute_object->set_id( $attribute_id ); |
| 273 | 273 | $attribute_object->set_name( $attribute_name ); |
| 274 | - $attribute_object->set_options( $attribute['options'] ); |
|
| 275 | - $attribute_object->set_position( isset( $attribute['position'] ) ? (string) absint( $attribute['position'] ) : '0' ); |
|
| 276 | - $attribute_object->set_visible( ! empty( $attribute['visible'] ) ? 1 : 0 ); |
|
| 277 | - $attribute_object->set_variation( ! empty( $attribute['variation'] ) ? 1 : 0 ); |
|
| 278 | - $attributes[] = $attribute_object; |
|
| 274 | + $attribute_object->set_options( $attribute[ 'options' ] ); |
|
| 275 | + $attribute_object->set_position( isset( $attribute[ 'position' ] ) ? (string) absint( $attribute[ 'position' ] ) : '0' ); |
|
| 276 | + $attribute_object->set_visible( ! empty( $attribute[ 'visible' ] ) ? 1 : 0 ); |
|
| 277 | + $attribute_object->set_variation( ! empty( $attribute[ 'variation' ] ) ? 1 : 0 ); |
|
| 278 | + $attributes[ ] = $attribute_object; |
|
| 279 | 279 | } |
| 280 | 280 | return $attributes; |
| 281 | 281 | } |
@@ -291,35 +291,35 @@ discard block |
||
| 291 | 291 | protected function parse_images_field( $images, $object ) { |
| 292 | 292 | $response = [ |
| 293 | 293 | 'image_id' => '', |
| 294 | - 'gallery_image_ids' => [], |
|
| 294 | + 'gallery_image_ids' => [ ], |
|
| 295 | 295 | ]; |
| 296 | 296 | |
| 297 | - $images = is_array( $images ) ? array_filter( $images ) : []; |
|
| 297 | + $images = is_array( $images ) ? array_filter( $images ) : [ ]; |
|
| 298 | 298 | |
| 299 | 299 | if ( empty( $images ) ) { |
| 300 | 300 | return $response; |
| 301 | 301 | } |
| 302 | 302 | |
| 303 | 303 | foreach ( $images as $index => $image ) { |
| 304 | - $attachment_id = isset( $image['id'] ) ? absint( $image['id'] ) : 0; |
|
| 304 | + $attachment_id = isset( $image[ 'id' ] ) ? absint( $image[ 'id' ] ) : 0; |
|
| 305 | 305 | $attachment = new ImageAttachment( $attachment_id, $object->get_id() ); |
| 306 | 306 | |
| 307 | - if ( 0 === $attachment->id && ! empty( $image['src'] ) ) { |
|
| 308 | - $attachment->upload_image_from_src( $image['src'] ); |
|
| 307 | + if ( 0 === $attachment->id && ! empty( $image[ 'src' ] ) ) { |
|
| 308 | + $attachment->upload_image_from_src( $image[ 'src' ] ); |
|
| 309 | 309 | } |
| 310 | 310 | |
| 311 | - if ( ! empty( $image['alt'] ) ) { |
|
| 312 | - $attachment->update_alt_text( $image['alt'] ); |
|
| 311 | + if ( ! empty( $image[ 'alt' ] ) ) { |
|
| 312 | + $attachment->update_alt_text( $image[ 'alt' ] ); |
|
| 313 | 313 | } |
| 314 | 314 | |
| 315 | - if ( ! empty( $image['name'] ) ) { |
|
| 316 | - $attachment->update_name( $image['name'] ); |
|
| 315 | + if ( ! empty( $image[ 'name' ] ) ) { |
|
| 316 | + $attachment->update_name( $image[ 'name' ] ); |
|
| 317 | 317 | } |
| 318 | 318 | |
| 319 | 319 | if ( 0 === $index ) { |
| 320 | - $response['image_id'] = $attachment->id; |
|
| 320 | + $response[ 'image_id' ] = $attachment->id; |
|
| 321 | 321 | } else { |
| 322 | - $response['gallery_image_ids'][] = $attachment->id; |
|
| 322 | + $response[ 'gallery_image_ids' ][ ] = $attachment->id; |
|
| 323 | 323 | } |
| 324 | 324 | } |
| 325 | 325 | |
@@ -333,18 +333,18 @@ discard block |
||
| 333 | 333 | * @return array |
| 334 | 334 | */ |
| 335 | 335 | protected function parse_dimensions_fields( $dimensions ) { |
| 336 | - $response = []; |
|
| 336 | + $response = [ ]; |
|
| 337 | 337 | |
| 338 | - if ( isset( $dimensions['length'] ) ) { |
|
| 339 | - $response['length'] = $dimensions['length']; |
|
| 338 | + if ( isset( $dimensions[ 'length' ] ) ) { |
|
| 339 | + $response[ 'length' ] = $dimensions[ 'length' ]; |
|
| 340 | 340 | } |
| 341 | 341 | |
| 342 | - if ( isset( $dimensions['width'] ) ) { |
|
| 343 | - $response['width'] = $dimensions['width']; |
|
| 342 | + if ( isset( $dimensions[ 'width' ] ) ) { |
|
| 343 | + $response[ 'width' ] = $dimensions[ 'width' ]; |
|
| 344 | 344 | } |
| 345 | 345 | |
| 346 | - if ( isset( $dimensions['height'] ) ) { |
|
| 347 | - $response['height'] = $dimensions['height']; |
|
| 346 | + if ( isset( $dimensions[ 'height' ] ) ) { |
|
| 347 | + $response[ 'height' ] = $dimensions[ 'height' ]; |
|
| 348 | 348 | } |
| 349 | 349 | |
| 350 | 350 | return $response; |
@@ -371,15 +371,15 @@ discard block |
||
| 371 | 371 | protected function parse_downloads_field( $downloads ) { |
| 372 | 372 | $files = array(); |
| 373 | 373 | foreach ( $downloads as $key => $file ) { |
| 374 | - if ( empty( $file['file'] ) ) { |
|
| 374 | + if ( empty( $file[ 'file' ] ) ) { |
|
| 375 | 375 | continue; |
| 376 | 376 | } |
| 377 | 377 | |
| 378 | 378 | $download = new \WC_Product_Download(); |
| 379 | - $download->set_id( ! empty( $file['id'] ) ? $file['id'] : wp_generate_uuid4() ); |
|
| 380 | - $download->set_name( $file['name'] ? $file['name'] : wc_get_filename_from_url( $file['file'] ) ); |
|
| 381 | - $download->set_file( $file['file'] ); |
|
| 382 | - $files[] = $download; |
|
| 379 | + $download->set_id( ! empty( $file[ 'id' ] ) ? $file[ 'id' ] : wp_generate_uuid4() ); |
|
| 380 | + $download->set_name( $file[ 'name' ] ? $file[ 'name' ] : wc_get_filename_from_url( $file[ 'file' ] ) ); |
|
| 381 | + $download->set_file( $file[ 'file' ] ); |
|
| 382 | + $files[ ] = $download; |
|
| 383 | 383 | } |
| 384 | 384 | return $files; |
| 385 | 385 | } |
@@ -400,11 +400,11 @@ discard block |
||
| 400 | 400 | $attribute_name = ''; |
| 401 | 401 | |
| 402 | 402 | // Check ID for global attributes or name for product attributes. |
| 403 | - if ( ! empty( $attribute['id'] ) ) { |
|
| 404 | - $attribute_id = absint( $attribute['id'] ); |
|
| 403 | + if ( ! empty( $attribute[ 'id' ] ) ) { |
|
| 404 | + $attribute_id = absint( $attribute[ 'id' ] ); |
|
| 405 | 405 | $attribute_name = wc_attribute_taxonomy_name_by_id( $attribute_id ); |
| 406 | - } elseif ( ! empty( $attribute['name'] ) ) { |
|
| 407 | - $attribute_name = sanitize_title( $attribute['name'] ); |
|
| 406 | + } elseif ( ! empty( $attribute[ 'name' ] ) ) { |
|
| 407 | + $attribute_name = sanitize_title( $attribute[ 'name' ] ); |
|
| 408 | 408 | } |
| 409 | 409 | |
| 410 | 410 | if ( ! $attribute_id && ! $attribute_name ) { |
@@ -414,10 +414,10 @@ discard block |
||
| 414 | 414 | if ( isset( $attributes[ $attribute_name ] ) ) { |
| 415 | 415 | $_attribute = $attributes[ $attribute_name ]; |
| 416 | 416 | |
| 417 | - if ( $_attribute['is_variation'] ) { |
|
| 418 | - $value = isset( $attribute['option'] ) ? wc_clean( stripslashes( $attribute['option'] ) ) : ''; |
|
| 417 | + if ( $_attribute[ 'is_variation' ] ) { |
|
| 418 | + $value = isset( $attribute[ 'option' ] ) ? wc_clean( stripslashes( $attribute[ 'option' ] ) ) : ''; |
|
| 419 | 419 | |
| 420 | - if ( ! empty( $_attribute['is_taxonomy'] ) ) { |
|
| 420 | + if ( ! empty( $_attribute[ 'is_taxonomy' ] ) ) { |
|
| 421 | 421 | // If dealing with a taxonomy, we need to get the slug from the name posted to the API. |
| 422 | 422 | $term = get_term_by( 'name', $value, $attribute_name ); |
| 423 | 423 | |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | if ( $image_id ) { |
| 57 | 57 | $attachment = get_post( $image_id ); |
| 58 | 58 | |
| 59 | - $data['image'] = array( |
|
| 59 | + $data[ 'image' ] = array( |
|
| 60 | 60 | 'id' => (int) $image_id, |
| 61 | 61 | 'date_created' => wc_rest_prepare_date_response( $attachment->post_date ), |
| 62 | 62 | 'date_created_gmt' => wc_rest_prepare_date_response( $attachment->post_date_gmt ), |
@@ -82,17 +82,17 @@ discard block |
||
| 82 | 82 | protected function update_term_meta_fields( $term, $request ) { |
| 83 | 83 | $id = (int) $term->term_id; |
| 84 | 84 | |
| 85 | - if ( isset( $request['display'] ) ) { |
|
| 86 | - update_term_meta( $id, 'display_type', 'default' === $request['display'] ? '' : $request['display'] ); |
|
| 85 | + if ( isset( $request[ 'display' ] ) ) { |
|
| 86 | + update_term_meta( $id, 'display_type', 'default' === $request[ 'display' ] ? '' : $request[ 'display' ] ); |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | - if ( isset( $request['menu_order'] ) ) { |
|
| 90 | - update_term_meta( $id, 'order', $request['menu_order'] ); |
|
| 89 | + if ( isset( $request[ 'menu_order' ] ) ) { |
|
| 90 | + update_term_meta( $id, 'order', $request[ 'menu_order' ] ); |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | - if ( isset( $request['image'] ) ) { |
|
| 94 | - if ( empty( $request['image']['id'] ) && ! empty( $request['image']['src'] ) ) { |
|
| 95 | - $upload = wc_rest_upload_image_from_url( esc_url_raw( $request['image']['src'] ) ); |
|
| 93 | + if ( isset( $request[ 'image' ] ) ) { |
|
| 94 | + if ( empty( $request[ 'image' ][ 'id' ] ) && ! empty( $request[ 'image' ][ 'src' ] ) ) { |
|
| 95 | + $upload = wc_rest_upload_image_from_url( esc_url_raw( $request[ 'image' ][ 'src' ] ) ); |
|
| 96 | 96 | |
| 97 | 97 | if ( is_wp_error( $upload ) ) { |
| 98 | 98 | return $upload; |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | |
| 101 | 101 | $image_id = wc_rest_set_uploaded_image_as_attachment( $upload ); |
| 102 | 102 | } else { |
| 103 | - $image_id = isset( $request['image']['id'] ) ? absint( $request['image']['id'] ) : 0; |
|
| 103 | + $image_id = isset( $request[ 'image' ][ 'id' ] ) ? absint( $request[ 'image' ][ 'id' ] ) : 0; |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | // Check if image_id is a valid image attachment before updating the term meta. |
@@ -108,16 +108,16 @@ discard block |
||
| 108 | 108 | update_term_meta( $id, 'thumbnail_id', $image_id ); |
| 109 | 109 | |
| 110 | 110 | // Set the image alt. |
| 111 | - if ( ! empty( $request['image']['alt'] ) ) { |
|
| 112 | - update_post_meta( $image_id, '_wp_attachment_image_alt', wc_clean( $request['image']['alt'] ) ); |
|
| 111 | + if ( ! empty( $request[ 'image' ][ 'alt' ] ) ) { |
|
| 112 | + update_post_meta( $image_id, '_wp_attachment_image_alt', wc_clean( $request[ 'image' ][ 'alt' ] ) ); |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | // Set the image title. |
| 116 | - if ( ! empty( $request['image']['name'] ) ) { |
|
| 116 | + if ( ! empty( $request[ 'image' ][ 'name' ] ) ) { |
|
| 117 | 117 | wp_update_post( |
| 118 | 118 | array( |
| 119 | 119 | 'ID' => $image_id, |
| 120 | - 'post_title' => wc_clean( $request['image']['name'] ), |
|
| 120 | + 'post_title' => wc_clean( $request[ 'image' ][ 'name' ] ), |
|
| 121 | 121 | ) |
| 122 | 122 | ); |
| 123 | 123 | } |
@@ -83,19 +83,19 @@ discard block |
||
| 83 | 83 | foreach ( $groups as $group ) { |
| 84 | 84 | $sub_groups = array(); |
| 85 | 85 | foreach ( $groups as $_group ) { |
| 86 | - if ( ! empty( $_group['parent_id'] ) && $group['id'] === $_group['parent_id'] ) { |
|
| 87 | - $sub_groups[] = $_group['id']; |
|
| 86 | + if ( ! empty( $_group[ 'parent_id' ] ) && $group[ 'id' ] === $_group[ 'parent_id' ] ) { |
|
| 87 | + $sub_groups[ ] = $_group[ 'id' ]; |
|
| 88 | 88 | } |
| 89 | 89 | } |
| 90 | - $group['sub_groups'] = $sub_groups; |
|
| 90 | + $group[ 'sub_groups' ] = $sub_groups; |
|
| 91 | 91 | |
| 92 | 92 | $group = wp_parse_args( $group, $defaults ); |
| 93 | - if ( ! is_null( $group['id'] ) && ! is_null( $group['label'] ) ) { |
|
| 93 | + if ( ! is_null( $group[ 'id' ] ) && ! is_null( $group[ 'label' ] ) ) { |
|
| 94 | 94 | $group_obj = $this->filter_group( $group ); |
| 95 | 95 | $group_data = $this->prepare_item_for_response( $group_obj, $request ); |
| 96 | 96 | $group_data = $this->prepare_response_for_collection( $group_data ); |
| 97 | 97 | |
| 98 | - $filtered_groups[] = $group_data; |
|
| 98 | + $filtered_groups[ ] = $group_data; |
|
| 99 | 99 | } |
| 100 | 100 | } |
| 101 | 101 | |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | $base = '/' . $this->namespace . '/' . $this->rest_base; |
| 115 | 115 | $links = array( |
| 116 | 116 | 'options' => array( |
| 117 | - 'href' => rest_url( trailingslashit( $base ) . $item['id'] ), |
|
| 117 | + 'href' => rest_url( trailingslashit( $base ) . $item[ 'id' ] ), |
|
| 118 | 118 | ), |
| 119 | 119 | ); |
| 120 | 120 | |