@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | * @return \WP_REST_Response|\WP_Error |
55 | 55 | */ |
56 | 56 | public function get_items( $request ) { |
57 | - $zone = $this->get_zone( (int) $request['id'] ); |
|
57 | + $zone = $this->get_zone( (int) $request[ 'id' ] ); |
|
58 | 58 | |
59 | 59 | if ( is_wp_error( $zone ) ) { |
60 | 60 | return $zone; |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | foreach ( $locations as $location_obj ) { |
67 | 67 | $location = $this->prepare_item_for_response( (array) $location_obj, $request ); |
68 | 68 | $location = $this->prepare_response_for_collection( $location ); |
69 | - $data[] = $location; |
|
69 | + $data[ ] = $location; |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | return rest_ensure_response( $data ); |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | * @return \WP_REST_Response|\WP_Error |
80 | 80 | */ |
81 | 81 | public function update_items( $request ) { |
82 | - $zone = $this->get_zone( (int) $request['id'] ); |
|
82 | + $zone = $this->get_zone( (int) $request[ 'id' ] ); |
|
83 | 83 | |
84 | 84 | if ( is_wp_error( $zone ) ) { |
85 | 85 | return $zone; |
@@ -93,18 +93,18 @@ discard block |
||
93 | 93 | $locations = array(); |
94 | 94 | |
95 | 95 | foreach ( (array) $raw_locations as $raw_location ) { |
96 | - if ( empty( $raw_location['code'] ) ) { |
|
96 | + if ( empty( $raw_location[ 'code' ] ) ) { |
|
97 | 97 | continue; |
98 | 98 | } |
99 | 99 | |
100 | - $type = ! empty( $raw_location['type'] ) ? sanitize_text_field( $raw_location['type'] ) : 'country'; |
|
100 | + $type = ! empty( $raw_location[ 'type' ] ) ? sanitize_text_field( $raw_location[ 'type' ] ) : 'country'; |
|
101 | 101 | |
102 | 102 | if ( ! in_array( $type, array( 'postcode', 'state', 'country', 'continent' ), true ) ) { |
103 | 103 | continue; |
104 | 104 | } |
105 | 105 | |
106 | - $locations[] = array( |
|
107 | - 'code' => sanitize_text_field( $raw_location['code'] ), |
|
106 | + $locations[ ] = array( |
|
107 | + 'code' => sanitize_text_field( $raw_location[ 'code' ] ), |
|
108 | 108 | 'type' => sanitize_text_field( $type ), |
109 | 109 | ); |
110 | 110 | } |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | * @return array |
124 | 124 | */ |
125 | 125 | protected function prepare_links( $item, $request ) { |
126 | - $base = '/' . $this->namespace . '/' . $this->rest_base . '/' . $request['id']; |
|
126 | + $base = '/' . $this->namespace . '/' . $this->rest_base . '/' . $request[ 'id' ]; |
|
127 | 127 | $links = array( |
128 | 128 | 'collection' => array( |
129 | 129 | 'href' => rest_url( $base . '/locations' ), |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | foreach ( $zones as $zone_obj ) { |
125 | 125 | $zone = $this->prepare_item_for_response( $zone_obj, $request ); |
126 | 126 | $zone = $this->prepare_response_for_collection( $zone ); |
127 | - $data[] = $zone; |
|
127 | + $data[ ] = $zone; |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | return rest_ensure_response( $data ); |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | return $zone; |
210 | 210 | } |
211 | 211 | |
212 | - $force = $request['force']; |
|
212 | + $force = $request[ 'force' ]; |
|
213 | 213 | |
214 | 214 | // We don't support trashing for this type, error out. |
215 | 215 | if ( ! $force ) { |
@@ -238,9 +238,9 @@ discard block |
||
238 | 238 | */ |
239 | 239 | protected function get_data_for_response( $object, $request ) { |
240 | 240 | return array( |
241 | - 'id' => (int) $object['id'], |
|
242 | - 'name' => $object['zone_name'], |
|
243 | - 'order' => (int) $object['zone_order'], |
|
241 | + 'id' => (int) $object[ 'id' ], |
|
242 | + 'name' => $object[ 'zone_name' ], |
|
243 | + 'order' => (int) $object[ 'zone_order' ], |
|
244 | 244 | ); |
245 | 245 | } |
246 | 246 | |
@@ -255,13 +255,13 @@ discard block |
||
255 | 255 | $base = '/' . $this->namespace . '/' . $this->rest_base; |
256 | 256 | $links = array( |
257 | 257 | 'self' => array( |
258 | - 'href' => rest_url( trailingslashit( $base ) . $item['id'] ), |
|
258 | + 'href' => rest_url( trailingslashit( $base ) . $item[ 'id' ] ), |
|
259 | 259 | ), |
260 | 260 | 'collection' => array( |
261 | 261 | 'href' => rest_url( $base ), |
262 | 262 | ), |
263 | 263 | 'describedby' => array( |
264 | - 'href' => rest_url( trailingslashit( $base ) . $item['id'] . '/locations' ), |
|
264 | + 'href' => rest_url( trailingslashit( $base ) . $item[ 'id' ] . '/locations' ), |
|
265 | 265 | ), |
266 | 266 | ); |
267 | 267 |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | } |
27 | 27 | |
28 | 28 | $batches = [ 'create', 'update', 'delete' ]; |
29 | - $response = []; |
|
29 | + $response = [ ]; |
|
30 | 30 | |
31 | 31 | foreach ( $batches as $batch ) { |
32 | 32 | $response[ $batch ] = $this->{"batch_$batch"}( $this->get_batch_of_items_from_request( $request, $batch ) ); |
@@ -164,11 +164,11 @@ discard block |
||
164 | 164 | * @return array |
165 | 165 | */ |
166 | 166 | protected function get_default_params() { |
167 | - $defaults = []; |
|
167 | + $defaults = [ ]; |
|
168 | 168 | $schema = $this->get_public_item_schema(); |
169 | - foreach ( $schema['properties'] as $arg => $options ) { |
|
170 | - if ( isset( $options['default'] ) ) { |
|
171 | - $defaults[ $arg ] = $options['default']; |
|
169 | + foreach ( $schema[ 'properties' ] as $arg => $options ) { |
|
170 | + if ( isset( $options[ 'default' ] ) ) { |
|
171 | + $defaults[ $arg ] = $options[ 'default' ]; |
|
172 | 172 | } |
173 | 173 | } |
174 | 174 | return $defaults; |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | * @return array Response data. |
182 | 182 | */ |
183 | 183 | protected function batch_create( $items ) { |
184 | - $batch_response = []; |
|
184 | + $batch_response = [ ]; |
|
185 | 185 | |
186 | 186 | foreach ( $items as $item ) { |
187 | 187 | $request = new \WP_REST_Request( 'POST' ); |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | $request->set_body_params( $item ); |
190 | 190 | |
191 | 191 | $response = $this->create_item( $request ); |
192 | - $batch_response[] = $this->format_response( 0, $response ); |
|
192 | + $batch_response[ ] = $this->format_response( 0, $response ); |
|
193 | 193 | } |
194 | 194 | |
195 | 195 | return $batch_response; |
@@ -202,14 +202,14 @@ discard block |
||
202 | 202 | * @return array Response data. |
203 | 203 | */ |
204 | 204 | protected function batch_update( $items ) { |
205 | - $batch_response = []; |
|
205 | + $batch_response = [ ]; |
|
206 | 206 | |
207 | 207 | foreach ( $items as $item ) { |
208 | 208 | $request = new \WP_REST_Request( 'PUT' ); |
209 | 209 | $request->set_body_params( $item ); |
210 | 210 | |
211 | 211 | $response = $this->update_item( $request ); |
212 | - $batch_response[] = $this->format_response( $item['id'], $response ); |
|
212 | + $batch_response[ ] = $this->format_response( $item[ 'id' ], $response ); |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | return $batch_response; |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | * @return array Response data. |
223 | 223 | */ |
224 | 224 | protected function batch_delete( $items ) { |
225 | - $batch_response = []; |
|
225 | + $batch_response = [ ]; |
|
226 | 226 | $items = wp_parse_id_list( $items ); |
227 | 227 | |
228 | 228 | foreach ( $items as $id ) { |
@@ -234,7 +234,7 @@ discard block |
||
234 | 234 | ] |
235 | 235 | ); |
236 | 236 | $response = $this->delete_item( $request ); |
237 | - $batch_response[] = $this->format_response( $id, $response ); |
|
237 | + $batch_response[ ] = $this->format_response( $id, $response ); |
|
238 | 238 | } |
239 | 239 | |
240 | 240 | return $batch_response; |
@@ -108,13 +108,13 @@ discard block |
||
108 | 108 | * @return \WP_REST_Response|\WP_Error |
109 | 109 | */ |
110 | 110 | public function get_item( $request ) { |
111 | - $zone = $this->get_zone( $request['zone_id'] ); |
|
111 | + $zone = $this->get_zone( $request[ 'zone_id' ] ); |
|
112 | 112 | |
113 | 113 | if ( is_wp_error( $zone ) ) { |
114 | 114 | return $zone; |
115 | 115 | } |
116 | 116 | |
117 | - $instance_id = (int) $request['instance_id']; |
|
117 | + $instance_id = (int) $request[ 'instance_id' ]; |
|
118 | 118 | $methods = $zone->get_shipping_methods(); |
119 | 119 | $method = false; |
120 | 120 | |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | * @return \WP_REST_Response|\WP_Error |
142 | 142 | */ |
143 | 143 | public function get_items( $request ) { |
144 | - $zone = $this->get_zone( $request['zone_id'] ); |
|
144 | + $zone = $this->get_zone( $request[ 'zone_id' ] ); |
|
145 | 145 | |
146 | 146 | if ( is_wp_error( $zone ) ) { |
147 | 147 | return $zone; |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | |
153 | 153 | foreach ( $methods as $method_obj ) { |
154 | 154 | $method = $this->prepare_item_for_response( $method_obj, $request ); |
155 | - $data[] = $method; |
|
155 | + $data[ ] = $method; |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | return rest_ensure_response( $data ); |
@@ -165,8 +165,8 @@ discard block |
||
165 | 165 | * @return \WP_REST_Request|\WP_Error |
166 | 166 | */ |
167 | 167 | public function create_item( $request ) { |
168 | - $method_id = $request['method_id']; |
|
169 | - $zone = $this->get_zone( $request['zone_id'] ); |
|
168 | + $method_id = $request[ 'method_id' ]; |
|
169 | + $zone = $this->get_zone( $request[ 'zone_id' ] ); |
|
170 | 170 | if ( is_wp_error( $zone ) ) { |
171 | 171 | return $zone; |
172 | 172 | } |
@@ -201,13 +201,13 @@ discard block |
||
201 | 201 | * @return \WP_Error|boolean |
202 | 202 | */ |
203 | 203 | public function delete_item( $request ) { |
204 | - $zone = $this->get_zone( $request['zone_id'] ); |
|
204 | + $zone = $this->get_zone( $request[ 'zone_id' ] ); |
|
205 | 205 | if ( is_wp_error( $zone ) ) { |
206 | 206 | return $zone; |
207 | 207 | } |
208 | 208 | |
209 | - $instance_id = (int) $request['instance_id']; |
|
210 | - $force = $request['force']; |
|
209 | + $instance_id = (int) $request[ 'instance_id' ]; |
|
210 | + $force = $request[ 'force' ]; |
|
211 | 211 | |
212 | 212 | // We don't support trashing for this type, error out. |
213 | 213 | if ( ! $force ) { |
@@ -265,12 +265,12 @@ discard block |
||
265 | 265 | * @return \WP_REST_Response|\WP_Error |
266 | 266 | */ |
267 | 267 | public function update_item( $request ) { |
268 | - $zone = $this->get_zone( $request['zone_id'] ); |
|
268 | + $zone = $this->get_zone( $request[ 'zone_id' ] ); |
|
269 | 269 | if ( is_wp_error( $zone ) ) { |
270 | 270 | return $zone; |
271 | 271 | } |
272 | 272 | |
273 | - $instance_id = (int) $request['instance_id']; |
|
273 | + $instance_id = (int) $request[ 'instance_id' ]; |
|
274 | 274 | $methods = $zone->get_shipping_methods(); |
275 | 275 | $method = false; |
276 | 276 | |
@@ -307,16 +307,16 @@ discard block |
||
307 | 307 | global $wpdb; |
308 | 308 | |
309 | 309 | // Update settings if present. |
310 | - if ( isset( $request['settings'] ) ) { |
|
310 | + if ( isset( $request[ 'settings' ] ) ) { |
|
311 | 311 | $method->init_instance_settings(); |
312 | 312 | $instance_settings = $method->instance_settings; |
313 | 313 | $errors_found = false; |
314 | 314 | foreach ( $method->get_instance_form_fields() as $key => $field ) { |
315 | - if ( isset( $request['settings'][ $key ] ) ) { |
|
316 | - if ( is_callable( array( $this, 'validate_setting_' . $field['type'] . '_field' ) ) ) { |
|
317 | - $value = $this->{'validate_setting_' . $field['type'] . '_field'}( $request['settings'][ $key ], $field ); |
|
315 | + if ( isset( $request[ 'settings' ][ $key ] ) ) { |
|
316 | + if ( is_callable( array( $this, 'validate_setting_' . $field[ 'type' ] . '_field' ) ) ) { |
|
317 | + $value = $this->{'validate_setting_' . $field[ 'type' ] . '_field'}( $request[ 'settings' ][ $key ], $field ); |
|
318 | 318 | } else { |
319 | - $value = $this->validate_setting_text_field( $request['settings'][ $key ], $field ); |
|
319 | + $value = $this->validate_setting_text_field( $request[ 'settings' ][ $key ], $field ); |
|
320 | 320 | } |
321 | 321 | if ( is_wp_error( $value ) ) { |
322 | 322 | $errors_found = true; |
@@ -334,16 +334,16 @@ discard block |
||
334 | 334 | } |
335 | 335 | |
336 | 336 | // Update order. |
337 | - if ( isset( $request['order'] ) ) { |
|
338 | - $wpdb->update( "{$wpdb->prefix}woocommerce_shipping_zone_methods", array( 'method_order' => absint( $request['order'] ) ), array( 'instance_id' => absint( $instance_id ) ) ); |
|
339 | - $method->method_order = absint( $request['order'] ); |
|
337 | + if ( isset( $request[ 'order' ] ) ) { |
|
338 | + $wpdb->update( "{$wpdb->prefix}woocommerce_shipping_zone_methods", array( 'method_order' => absint( $request[ 'order' ] ) ), array( 'instance_id' => absint( $instance_id ) ) ); |
|
339 | + $method->method_order = absint( $request[ 'order' ] ); |
|
340 | 340 | } |
341 | 341 | |
342 | 342 | // Update if this method is enabled or not. |
343 | - if ( isset( $request['enabled'] ) ) { |
|
344 | - if ( $wpdb->update( "{$wpdb->prefix}woocommerce_shipping_zone_methods", array( 'is_enabled' => $request['enabled'] ), array( 'instance_id' => absint( $instance_id ) ) ) ) { |
|
345 | - do_action( 'woocommerce_shipping_zone_method_status_toggled', $instance_id, $method->id, $request['zone_id'], $request['enabled'] ); |
|
346 | - $method->enabled = ( true === $request['enabled'] ? 'yes' : 'no' ); |
|
343 | + if ( isset( $request[ 'enabled' ] ) ) { |
|
344 | + if ( $wpdb->update( "{$wpdb->prefix}woocommerce_shipping_zone_methods", array( 'is_enabled' => $request[ 'enabled' ] ), array( 'instance_id' => absint( $instance_id ) ) ) ) { |
|
345 | + do_action( 'woocommerce_shipping_zone_method_status_toggled', $instance_id, $method->id, $request[ 'zone_id' ], $request[ 'enabled' ] ); |
|
346 | + $method->enabled = ( true === $request[ 'enabled' ] ? 'yes' : 'no' ); |
|
347 | 347 | } |
348 | 348 | } |
349 | 349 | |
@@ -361,7 +361,7 @@ discard block |
||
361 | 361 | return array( |
362 | 362 | 'id' => $object->instance_id, |
363 | 363 | 'instance_id' => $object->instance_id, |
364 | - 'title' => $object->instance_settings['title'], |
|
364 | + 'title' => $object->instance_settings[ 'title' ], |
|
365 | 365 | 'order' => $object->method_order, |
366 | 366 | 'enabled' => ( 'yes' === $object->enabled ), |
367 | 367 | 'method_id' => $object->id, |
@@ -397,16 +397,16 @@ discard block |
||
397 | 397 | foreach ( $item->get_instance_form_fields() as $id => $field ) { |
398 | 398 | $data = array( |
399 | 399 | 'id' => $id, |
400 | - 'label' => $field['title'], |
|
401 | - 'description' => empty( $field['description'] ) ? '' : $field['description'], |
|
402 | - 'type' => $field['type'], |
|
400 | + 'label' => $field[ 'title' ], |
|
401 | + 'description' => empty( $field[ 'description' ] ) ? '' : $field[ 'description' ], |
|
402 | + 'type' => $field[ 'type' ], |
|
403 | 403 | 'value' => $item->instance_settings[ $id ], |
404 | - 'default' => empty( $field['default'] ) ? '' : $field['default'], |
|
405 | - 'tip' => empty( $field['description'] ) ? '' : $field['description'], |
|
406 | - 'placeholder' => empty( $field['placeholder'] ) ? '' : $field['placeholder'], |
|
404 | + 'default' => empty( $field[ 'default' ] ) ? '' : $field[ 'default' ], |
|
405 | + 'tip' => empty( $field[ 'description' ] ) ? '' : $field[ 'description' ], |
|
406 | + 'placeholder' => empty( $field[ 'placeholder' ] ) ? '' : $field[ 'placeholder' ], |
|
407 | 407 | ); |
408 | - if ( ! empty( $field['options'] ) ) { |
|
409 | - $data['options'] = $field['options']; |
|
408 | + if ( ! empty( $field[ 'options' ] ) ) { |
|
409 | + $data[ 'options' ] = $field[ 'options' ]; |
|
410 | 410 | } |
411 | 411 | $settings[ $id ] = $data; |
412 | 412 | } |
@@ -421,7 +421,7 @@ discard block |
||
421 | 421 | * @return array |
422 | 422 | */ |
423 | 423 | protected function prepare_links( $item, $request ) { |
424 | - $base = '/' . $this->namespace . '/' . $this->rest_base . '/' . $request['zone_id']; |
|
424 | + $base = '/' . $this->namespace . '/' . $this->rest_base . '/' . $request[ 'zone_id' ]; |
|
425 | 425 | $links = array( |
426 | 426 | 'self' => array( |
427 | 427 | 'href' => rest_url( $base . '/methods/' . $item->instance_id ), |
@@ -160,7 +160,7 @@ |
||
160 | 160 | protected function update_term_meta_fields( $term, $request ) { |
161 | 161 | $id = (int) $term->term_id; |
162 | 162 | |
163 | - update_term_meta( $id, 'order_' . $this->taxonomy, $request['menu_order'] ); |
|
163 | + update_term_meta( $id, 'order_' . $this->taxonomy, $request[ 'menu_order' ] ); |
|
164 | 164 | |
165 | 165 | return true; |
166 | 166 | } |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | $payment_gateway->id = $payment_gateway_id; |
95 | 95 | $gateway = $this->prepare_item_for_response( $payment_gateway, $request ); |
96 | 96 | $gateway = $this->prepare_response_for_collection( $gateway ); |
97 | - $response[] = $gateway; |
|
97 | + $response[ ] = $gateway; |
|
98 | 98 | } |
99 | 99 | return rest_ensure_response( $response ); |
100 | 100 | } |
@@ -134,14 +134,14 @@ discard block |
||
134 | 134 | $settings = $gateway->settings; |
135 | 135 | |
136 | 136 | // Update settings. |
137 | - if ( isset( $request['settings'] ) ) { |
|
137 | + if ( isset( $request[ 'settings' ] ) ) { |
|
138 | 138 | $errors_found = false; |
139 | 139 | foreach ( $gateway->form_fields as $key => $field ) { |
140 | - if ( isset( $request['settings'][ $key ] ) ) { |
|
141 | - if ( is_callable( array( $this, 'validate_setting_' . $field['type'] . '_field' ) ) ) { |
|
142 | - $value = $this->{'validate_setting_' . $field['type'] . '_field'}( $request['settings'][ $key ], $field ); |
|
140 | + if ( isset( $request[ 'settings' ][ $key ] ) ) { |
|
141 | + if ( is_callable( array( $this, 'validate_setting_' . $field[ 'type' ] . '_field' ) ) ) { |
|
142 | + $value = $this->{'validate_setting_' . $field[ 'type' ] . '_field'}( $request[ 'settings' ][ $key ], $field ); |
|
143 | 143 | } else { |
144 | - $value = $this->validate_setting_text_field( $request['settings'][ $key ], $field ); |
|
144 | + $value = $this->validate_setting_text_field( $request[ 'settings' ][ $key ], $field ); |
|
145 | 145 | } |
146 | 146 | if ( is_wp_error( $value ) ) { |
147 | 147 | $errors_found = true; |
@@ -157,21 +157,21 @@ discard block |
||
157 | 157 | } |
158 | 158 | |
159 | 159 | // Update if this method is enabled or not. |
160 | - if ( isset( $request['enabled'] ) ) { |
|
161 | - $settings['enabled'] = wc_bool_to_string( $request['enabled'] ); |
|
162 | - $gateway->enabled = $settings['enabled']; |
|
160 | + if ( isset( $request[ 'enabled' ] ) ) { |
|
161 | + $settings[ 'enabled' ] = wc_bool_to_string( $request[ 'enabled' ] ); |
|
162 | + $gateway->enabled = $settings[ 'enabled' ]; |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | // Update title. |
166 | - if ( isset( $request['title'] ) ) { |
|
167 | - $settings['title'] = $request['title']; |
|
168 | - $gateway->title = $settings['title']; |
|
166 | + if ( isset( $request[ 'title' ] ) ) { |
|
167 | + $settings[ 'title' ] = $request[ 'title' ]; |
|
168 | + $gateway->title = $settings[ 'title' ]; |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | // Update description. |
172 | - if ( isset( $request['description'] ) ) { |
|
173 | - $settings['description'] = $request['description']; |
|
174 | - $gateway->description = $settings['description']; |
|
172 | + if ( isset( $request[ 'description' ] ) ) { |
|
173 | + $settings[ 'description' ] = $request[ 'description' ]; |
|
174 | + $gateway->description = $settings[ 'description' ]; |
|
175 | 175 | } |
176 | 176 | |
177 | 177 | // Update options. |
@@ -179,11 +179,11 @@ discard block |
||
179 | 179 | update_option( $gateway->get_option_key(), apply_filters( 'woocommerce_gateway_' . $gateway->id . '_settings_values', $settings, $gateway ) ); |
180 | 180 | |
181 | 181 | // Update order. |
182 | - if ( isset( $request['order'] ) ) { |
|
182 | + if ( isset( $request[ 'order' ] ) ) { |
|
183 | 183 | $order = (array) get_option( 'woocommerce_gateway_order' ); |
184 | - $order[ $gateway->id ] = $request['order']; |
|
184 | + $order[ $gateway->id ] = $request[ 'order' ]; |
|
185 | 185 | update_option( 'woocommerce_gateway_order', $order ); |
186 | - $gateway->order = absint( $request['order'] ); |
|
186 | + $gateway->order = absint( $request[ 'order' ] ); |
|
187 | 187 | } |
188 | 188 | |
189 | 189 | $gateway = $this->prepare_item_for_response( $gateway, $request ); |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | $gateway = null; |
201 | 201 | $payment_gateways = WC()->payment_gateways->payment_gateways(); |
202 | 202 | foreach ( $payment_gateways as $payment_gateway_id => $payment_gateway ) { |
203 | - if ( $request['id'] !== $payment_gateway_id ) { |
|
203 | + if ( $request[ 'id' ] !== $payment_gateway_id ) { |
|
204 | 204 | continue; |
205 | 205 | } |
206 | 206 | $payment_gateway->id = $payment_gateway_id; |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | $gateway->init_form_fields(); |
244 | 244 | foreach ( $gateway->form_fields as $id => $field ) { |
245 | 245 | // Make sure we at least have a title and type. |
246 | - if ( empty( $field['title'] ) || empty( $field['type'] ) ) { |
|
246 | + if ( empty( $field[ 'title' ] ) || empty( $field[ 'type' ] ) ) { |
|
247 | 247 | continue; |
248 | 248 | } |
249 | 249 | |
@@ -254,16 +254,16 @@ discard block |
||
254 | 254 | |
255 | 255 | $data = array( |
256 | 256 | 'id' => $id, |
257 | - 'label' => empty( $field['label'] ) ? $field['title'] : $field['label'], |
|
258 | - 'description' => empty( $field['description'] ) ? '' : $field['description'], |
|
259 | - 'type' => $field['type'], |
|
257 | + 'label' => empty( $field[ 'label' ] ) ? $field[ 'title' ] : $field[ 'label' ], |
|
258 | + 'description' => empty( $field[ 'description' ] ) ? '' : $field[ 'description' ], |
|
259 | + 'type' => $field[ 'type' ], |
|
260 | 260 | 'value' => empty( $gateway->settings[ $id ] ) ? '' : $gateway->settings[ $id ], |
261 | - 'default' => empty( $field['default'] ) ? '' : $field['default'], |
|
262 | - 'tip' => empty( $field['description'] ) ? '' : $field['description'], |
|
263 | - 'placeholder' => empty( $field['placeholder'] ) ? '' : $field['placeholder'], |
|
261 | + 'default' => empty( $field[ 'default' ] ) ? '' : $field[ 'default' ], |
|
262 | + 'tip' => empty( $field[ 'description' ] ) ? '' : $field[ 'description' ], |
|
263 | + 'placeholder' => empty( $field[ 'placeholder' ] ) ? '' : $field[ 'placeholder' ], |
|
264 | 264 | ); |
265 | - if ( ! empty( $field['options'] ) ) { |
|
266 | - $data['options'] = $field['options']; |
|
265 | + if ( ! empty( $field[ 'options' ] ) ) { |
|
266 | + $data[ 'options' ] = $field[ 'options' ]; |
|
267 | 267 | } |
268 | 268 | $settings[ $id ] = $data; |
269 | 269 | } |
@@ -37,7 +37,7 @@ |
||
37 | 37 | ); |
38 | 38 | |
39 | 39 | if ( 'view' === $context ) { |
40 | - $data['review'] = wpautop( $data['review'] ); |
|
40 | + $data[ 'review' ] = wpautop( $data[ 'review' ] ); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | return $data; |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | } |
64 | 64 | |
65 | 65 | // Format the order status. |
66 | - $data['status'] = 'wc-' === substr( $data['status'], 0, 3 ) ? substr( $data['status'], 3 ) : $data['status']; |
|
66 | + $data[ 'status' ] = 'wc-' === substr( $data[ 'status' ], 0, 3 ) ? substr( $data[ 'status' ], 3 ) : $data[ 'status' ]; |
|
67 | 67 | |
68 | 68 | // Format line items. |
69 | 69 | foreach ( $format_line_items as $key ) { |
@@ -71,9 +71,9 @@ discard block |
||
71 | 71 | } |
72 | 72 | |
73 | 73 | // Refunds. |
74 | - $data['refunds'] = array(); |
|
74 | + $data[ 'refunds' ] = array(); |
|
75 | 75 | foreach ( $object->get_refunds() as $refund ) { |
76 | - $data['refunds'][] = array( |
|
76 | + $data[ 'refunds' ][ ] = array( |
|
77 | 77 | 'id' => $refund->get_id(), |
78 | 78 | 'reason' => $refund->get_reason() ? $refund->get_reason() : '', |
79 | 79 | 'total' => '-' . wc_format_decimal( $refund->get_amount(), $this->dp ), |
@@ -81,52 +81,52 @@ discard block |
||
81 | 81 | } |
82 | 82 | |
83 | 83 | // Currency symbols. |
84 | - $currency_symbol = get_woocommerce_currency_symbol( $data['currency'] ); |
|
85 | - $data['currency_symbol'] = html_entity_decode( $currency_symbol ); |
|
84 | + $currency_symbol = get_woocommerce_currency_symbol( $data[ 'currency' ] ); |
|
85 | + $data[ 'currency_symbol' ] = html_entity_decode( $currency_symbol ); |
|
86 | 86 | |
87 | 87 | return array( |
88 | 88 | 'id' => $object->get_id(), |
89 | - 'parent_id' => $data['parent_id'], |
|
90 | - 'number' => $data['number'], |
|
91 | - 'order_key' => $data['order_key'], |
|
92 | - 'created_via' => $data['created_via'], |
|
93 | - 'version' => $data['version'], |
|
94 | - 'status' => $data['status'], |
|
95 | - 'currency' => $data['currency'], |
|
96 | - 'currency_symbol' => $data['currency_symbol'], |
|
97 | - 'date_created' => $data['date_created'], |
|
98 | - 'date_created_gmt' => $data['date_created_gmt'], |
|
99 | - 'date_modified' => $data['date_modified'], |
|
100 | - 'date_modified_gmt' => $data['date_modified_gmt'], |
|
101 | - 'discount_total' => $data['discount_total'], |
|
102 | - 'discount_tax' => $data['discount_tax'], |
|
103 | - 'shipping_total' => $data['shipping_total'], |
|
104 | - 'shipping_tax' => $data['shipping_tax'], |
|
105 | - 'cart_tax' => $data['cart_tax'], |
|
106 | - 'total' => $data['total'], |
|
107 | - 'total_tax' => $data['total_tax'], |
|
108 | - 'prices_include_tax' => $data['prices_include_tax'], |
|
109 | - 'customer_id' => $data['customer_id'], |
|
110 | - 'customer_ip_address' => $data['customer_ip_address'], |
|
111 | - 'customer_user_agent' => $data['customer_user_agent'], |
|
112 | - 'customer_note' => $data['customer_note'], |
|
113 | - 'billing' => $data['billing'], |
|
114 | - 'shipping' => $data['shipping'], |
|
115 | - 'payment_method' => $data['payment_method'], |
|
116 | - 'payment_method_title' => $data['payment_method_title'], |
|
117 | - 'transaction_id' => $data['transaction_id'], |
|
118 | - 'date_paid' => $data['date_paid'], |
|
119 | - 'date_paid_gmt' => $data['date_paid_gmt'], |
|
120 | - 'date_completed' => $data['date_completed'], |
|
121 | - 'date_completed_gmt' => $data['date_completed_gmt'], |
|
122 | - 'cart_hash' => $data['cart_hash'], |
|
123 | - 'meta_data' => $data['meta_data'], |
|
124 | - 'line_items' => $data['line_items'], |
|
125 | - 'tax_lines' => $data['tax_lines'], |
|
126 | - 'shipping_lines' => $data['shipping_lines'], |
|
127 | - 'fee_lines' => $data['fee_lines'], |
|
128 | - 'coupon_lines' => $data['coupon_lines'], |
|
129 | - 'refunds' => $data['refunds'], |
|
89 | + 'parent_id' => $data[ 'parent_id' ], |
|
90 | + 'number' => $data[ 'number' ], |
|
91 | + 'order_key' => $data[ 'order_key' ], |
|
92 | + 'created_via' => $data[ 'created_via' ], |
|
93 | + 'version' => $data[ 'version' ], |
|
94 | + 'status' => $data[ 'status' ], |
|
95 | + 'currency' => $data[ 'currency' ], |
|
96 | + 'currency_symbol' => $data[ 'currency_symbol' ], |
|
97 | + 'date_created' => $data[ 'date_created' ], |
|
98 | + 'date_created_gmt' => $data[ 'date_created_gmt' ], |
|
99 | + 'date_modified' => $data[ 'date_modified' ], |
|
100 | + 'date_modified_gmt' => $data[ 'date_modified_gmt' ], |
|
101 | + 'discount_total' => $data[ 'discount_total' ], |
|
102 | + 'discount_tax' => $data[ 'discount_tax' ], |
|
103 | + 'shipping_total' => $data[ 'shipping_total' ], |
|
104 | + 'shipping_tax' => $data[ 'shipping_tax' ], |
|
105 | + 'cart_tax' => $data[ 'cart_tax' ], |
|
106 | + 'total' => $data[ 'total' ], |
|
107 | + 'total_tax' => $data[ 'total_tax' ], |
|
108 | + 'prices_include_tax' => $data[ 'prices_include_tax' ], |
|
109 | + 'customer_id' => $data[ 'customer_id' ], |
|
110 | + 'customer_ip_address' => $data[ 'customer_ip_address' ], |
|
111 | + 'customer_user_agent' => $data[ 'customer_user_agent' ], |
|
112 | + 'customer_note' => $data[ 'customer_note' ], |
|
113 | + 'billing' => $data[ 'billing' ], |
|
114 | + 'shipping' => $data[ 'shipping' ], |
|
115 | + 'payment_method' => $data[ 'payment_method' ], |
|
116 | + 'payment_method_title' => $data[ 'payment_method_title' ], |
|
117 | + 'transaction_id' => $data[ 'transaction_id' ], |
|
118 | + 'date_paid' => $data[ 'date_paid' ], |
|
119 | + 'date_paid_gmt' => $data[ 'date_paid_gmt' ], |
|
120 | + 'date_completed' => $data[ 'date_completed' ], |
|
121 | + 'date_completed_gmt' => $data[ 'date_completed_gmt' ], |
|
122 | + 'cart_hash' => $data[ 'cart_hash' ], |
|
123 | + 'meta_data' => $data[ 'meta_data' ], |
|
124 | + 'line_items' => $data[ 'line_items' ], |
|
125 | + 'tax_lines' => $data[ 'tax_lines' ], |
|
126 | + 'shipping_lines' => $data[ 'shipping_lines' ], |
|
127 | + 'fee_lines' => $data[ 'fee_lines' ], |
|
128 | + 'coupon_lines' => $data[ 'coupon_lines' ], |
|
129 | + 'refunds' => $data[ 'refunds' ], |
|
130 | 130 | ); |
131 | 131 | } |
132 | 132 | |
@@ -149,34 +149,34 @@ discard block |
||
149 | 149 | |
150 | 150 | // Add SKU and PRICE to products. |
151 | 151 | if ( is_callable( array( $item, 'get_product' ) ) ) { |
152 | - $data['sku'] = $item->get_product() ? $item->get_product()->get_sku() : null; |
|
153 | - $data['price'] = $item->get_quantity() ? $item->get_total() / $item->get_quantity() : 0; |
|
152 | + $data[ 'sku' ] = $item->get_product() ? $item->get_product()->get_sku() : null; |
|
153 | + $data[ 'price' ] = $item->get_quantity() ? $item->get_total() / $item->get_quantity() : 0; |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | // Format taxes. |
157 | - if ( ! empty( $data['taxes']['total'] ) ) { |
|
157 | + if ( ! empty( $data[ 'taxes' ][ 'total' ] ) ) { |
|
158 | 158 | $taxes = array(); |
159 | 159 | |
160 | - foreach ( $data['taxes']['total'] as $tax_rate_id => $tax ) { |
|
161 | - $taxes[] = array( |
|
160 | + foreach ( $data[ 'taxes' ][ 'total' ] as $tax_rate_id => $tax ) { |
|
161 | + $taxes[ ] = array( |
|
162 | 162 | 'id' => $tax_rate_id, |
163 | 163 | 'total' => $tax, |
164 | - 'subtotal' => isset( $data['taxes']['subtotal'][ $tax_rate_id ] ) ? $data['taxes']['subtotal'][ $tax_rate_id ] : '', |
|
164 | + 'subtotal' => isset( $data[ 'taxes' ][ 'subtotal' ][ $tax_rate_id ] ) ? $data[ 'taxes' ][ 'subtotal' ][ $tax_rate_id ] : '', |
|
165 | 165 | ); |
166 | 166 | } |
167 | - $data['taxes'] = $taxes; |
|
168 | - } elseif ( isset( $data['taxes'] ) ) { |
|
169 | - $data['taxes'] = array(); |
|
167 | + $data[ 'taxes' ] = $taxes; |
|
168 | + } elseif ( isset( $data[ 'taxes' ] ) ) { |
|
169 | + $data[ 'taxes' ] = array(); |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | // Remove names for coupons, taxes and shipping. |
173 | - if ( isset( $data['code'] ) || isset( $data['rate_code'] ) || isset( $data['method_title'] ) ) { |
|
174 | - unset( $data['name'] ); |
|
173 | + if ( isset( $data[ 'code' ] ) || isset( $data[ 'rate_code' ] ) || isset( $data[ 'method_title' ] ) ) { |
|
174 | + unset( $data[ 'name' ] ); |
|
175 | 175 | } |
176 | 176 | |
177 | 177 | // Remove props we don't want to expose. |
178 | - unset( $data['order_id'] ); |
|
179 | - unset( $data['type'] ); |
|
178 | + unset( $data[ 'order_id' ] ); |
|
179 | + unset( $data[ 'type' ] ); |
|
180 | 180 | |
181 | 181 | return $data; |
182 | 182 | } |
@@ -96,25 +96,25 @@ discard block |
||
96 | 96 | |
97 | 97 | // Add variations to variable products. |
98 | 98 | if ( $object->is_type( 'variable' ) ) { |
99 | - $data['variations'] = $object->get_children(); |
|
99 | + $data[ 'variations' ] = $object->get_children(); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | // Add grouped products data. |
103 | 103 | if ( $object->is_type( 'grouped' ) ) { |
104 | - $data['grouped_products'] = $object->get_children(); |
|
104 | + $data[ 'grouped_products' ] = $object->get_children(); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | // Add external product data. |
108 | 108 | if ( $object->is_type( 'external' ) ) { |
109 | - $data['external_url'] = $object->get_product_url( $context ); |
|
110 | - $data['button_text'] = $object->get_button_text( $context ); |
|
109 | + $data[ 'external_url' ] = $object->get_product_url( $context ); |
|
110 | + $data[ 'button_text' ] = $object->get_button_text( $context ); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | if ( 'view' === $context ) { |
114 | - $data['description'] = wpautop( do_shortcode( $data['description'] ) ); |
|
115 | - $data['short_description'] = apply_filters( 'woocommerce_short_description', $data['short_description'] ); |
|
116 | - $data['average_rating'] = wc_format_decimal( $data['average_rating'], 2 ); |
|
117 | - $data['purchase_note'] = wpautop( do_shortcode( $data['purchase_note'] ) ); |
|
114 | + $data[ 'description' ] = wpautop( do_shortcode( $data[ 'description' ] ) ); |
|
115 | + $data[ 'short_description' ] = apply_filters( 'woocommerce_short_description', $data[ 'short_description' ] ); |
|
116 | + $data[ 'average_rating' ] = wc_format_decimal( $data[ 'average_rating' ], 2 ); |
|
117 | + $data[ 'purchase_note' ] = wpautop( do_shortcode( $data[ 'purchase_note' ] ) ); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | return $data; |
@@ -132,10 +132,10 @@ discard block |
||
132 | 132 | |
133 | 133 | if ( $object->is_downloadable() ) { |
134 | 134 | foreach ( $object->get_downloads() as $file_id => $file ) { |
135 | - $downloads[] = array( |
|
135 | + $downloads[ ] = array( |
|
136 | 136 | 'id' => $file_id, // MD5 hash. |
137 | - 'name' => $file['name'], |
|
138 | - 'file' => $file['file'], |
|
137 | + 'name' => $file[ 'name' ], |
|
138 | + 'file' => $file[ 'file' ], |
|
139 | 139 | ); |
140 | 140 | } |
141 | 141 | } |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | $terms = array(); |
156 | 156 | |
157 | 157 | foreach ( wc_get_object_terms( $object->get_id(), 'product_' . $taxonomy ) as $term ) { |
158 | - $terms[] = array( |
|
158 | + $terms[ ] = array( |
|
159 | 159 | 'id' => $term->term_id, |
160 | 160 | 'name' => $term->name, |
161 | 161 | 'slug' => $term->slug, |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | |
178 | 178 | // Add featured image. |
179 | 179 | if ( $object->get_image_id() ) { |
180 | - $attachment_ids[] = $object->get_image_id(); |
|
180 | + $attachment_ids[ ] = $object->get_image_id(); |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | // Add gallery images. |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | continue; |
196 | 196 | } |
197 | 197 | |
198 | - $images[] = array( |
|
198 | + $images[ ] = array( |
|
199 | 199 | 'id' => (int) $attachment_id, |
200 | 200 | 'date_created' => wc_rest_prepare_date_response( $attachment_post->post_date, false ), |
201 | 201 | 'date_created_gmt' => wc_rest_prepare_date_response( strtotime( $attachment_post->post_date_gmt ) ), |
@@ -223,13 +223,13 @@ discard block |
||
223 | 223 | if ( $object->is_type( 'variable' ) ) { |
224 | 224 | foreach ( array_filter( (array) $object->get_default_attributes(), 'strlen' ) as $key => $value ) { |
225 | 225 | if ( 0 === strpos( $key, 'pa_' ) ) { |
226 | - $default[] = array( |
|
226 | + $default[ ] = array( |
|
227 | 227 | 'id' => wc_attribute_taxonomy_id_by_name( $key ), |
228 | 228 | 'name' => $this->get_attribute_taxonomy_name( $key, $object ), |
229 | 229 | 'option' => $value, |
230 | 230 | ); |
231 | 231 | } else { |
232 | - $default[] = array( |
|
232 | + $default[ ] = array( |
|
233 | 233 | 'id' => 0, |
234 | 234 | 'name' => $this->get_attribute_taxonomy_name( $key, $object ), |
235 | 235 | 'option' => $value, |
@@ -263,13 +263,13 @@ discard block |
||
263 | 263 | // Taxonomy-based attributes are prefixed with `pa_`, otherwise simply `attribute_`. |
264 | 264 | if ( 0 === strpos( $attribute_name, 'attribute_pa_' ) ) { |
265 | 265 | $option_term = get_term_by( 'slug', $attribute, $name ); |
266 | - $attributes[] = array( |
|
266 | + $attributes[ ] = array( |
|
267 | 267 | 'id' => wc_attribute_taxonomy_id_by_name( $name ), |
268 | 268 | 'name' => $this->get_attribute_taxonomy_name( $name, $_product ), |
269 | 269 | 'option' => $option_term && ! is_wp_error( $option_term ) ? $option_term->name : $attribute, |
270 | 270 | ); |
271 | 271 | } else { |
272 | - $attributes[] = array( |
|
272 | + $attributes[ ] = array( |
|
273 | 273 | 'id' => 0, |
274 | 274 | 'name' => $this->get_attribute_taxonomy_name( $name, $_product ), |
275 | 275 | 'option' => $attribute, |
@@ -278,12 +278,12 @@ discard block |
||
278 | 278 | } |
279 | 279 | } else { |
280 | 280 | foreach ( $object->get_attributes() as $attribute ) { |
281 | - $attributes[] = array( |
|
282 | - 'id' => $attribute['is_taxonomy'] ? wc_attribute_taxonomy_id_by_name( $attribute['name'] ) : 0, |
|
283 | - 'name' => $this->get_attribute_taxonomy_name( $attribute['name'], $object ), |
|
284 | - 'position' => (int) $attribute['position'], |
|
285 | - 'visible' => (bool) $attribute['is_visible'], |
|
286 | - 'variation' => (bool) $attribute['is_variation'], |
|
281 | + $attributes[ ] = array( |
|
282 | + 'id' => $attribute[ 'is_taxonomy' ] ? wc_attribute_taxonomy_id_by_name( $attribute[ 'name' ] ) : 0, |
|
283 | + 'name' => $this->get_attribute_taxonomy_name( $attribute[ 'name' ], $object ), |
|
284 | + 'position' => (int) $attribute[ 'position' ], |
|
285 | + 'visible' => (bool) $attribute[ 'is_visible' ], |
|
286 | + 'variation' => (bool) $attribute[ 'is_variation' ], |
|
287 | 287 | 'options' => $this->get_attribute_options( $object->get_id(), $attribute ), |
288 | 288 | ); |
289 | 289 | } |
@@ -337,16 +337,16 @@ discard block |
||
337 | 337 | * @return array |
338 | 338 | */ |
339 | 339 | protected function get_attribute_options( $object_id, $attribute ) { |
340 | - if ( isset( $attribute['is_taxonomy'] ) && $attribute['is_taxonomy'] ) { |
|
340 | + if ( isset( $attribute[ 'is_taxonomy' ] ) && $attribute[ 'is_taxonomy' ] ) { |
|
341 | 341 | return wc_get_product_terms( |
342 | 342 | $object_id, |
343 | - $attribute['name'], |
|
343 | + $attribute[ 'name' ], |
|
344 | 344 | array( |
345 | 345 | 'fields' => 'names', |
346 | 346 | ) |
347 | 347 | ); |
348 | - } elseif ( isset( $attribute['value'] ) ) { |
|
349 | - return array_map( 'trim', explode( '|', $attribute['value'] ) ); |
|
348 | + } elseif ( isset( $attribute[ 'value' ] ) ) { |
|
349 | + return array_map( 'trim', explode( '|', $attribute[ 'value' ] ) ); |
|
350 | 350 | } |
351 | 351 | |
352 | 352 | return array(); |