@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | * @return string|\WP_Error |
34 | 34 | */ |
35 | 35 | public function validate_setting_select_field( $value, $setting ) { |
36 | - if ( array_key_exists( $value, $setting['options'] ) ) { |
|
36 | + if ( array_key_exists( $value, $setting[ 'options' ] ) ) { |
|
37 | 37 | return $value; |
38 | 38 | } else { |
39 | 39 | return new \WP_Error( 'rest_setting_value_invalid', __( 'An invalid setting value was passed.', 'woocommerce' ), array( 'status' => 400 ) ); |
@@ -59,8 +59,8 @@ discard block |
||
59 | 59 | |
60 | 60 | $final_values = array(); |
61 | 61 | foreach ( $values as $value ) { |
62 | - if ( array_key_exists( $value, $setting['options'] ) ) { |
|
63 | - $final_values[] = $value; |
|
62 | + if ( array_key_exists( $value, $setting[ 'options' ] ) ) { |
|
63 | + $final_values[ ] = $value; |
|
64 | 64 | } |
65 | 65 | } |
66 | 66 | |
@@ -80,15 +80,15 @@ discard block |
||
80 | 80 | return new \WP_Error( 'rest_setting_value_invalid', __( 'An invalid setting value was passed.', 'woocommerce' ), array( 'status' => 400 ) ); |
81 | 81 | } |
82 | 82 | |
83 | - $current = $setting['value']; |
|
84 | - if ( isset( $values['width'] ) ) { |
|
85 | - $current['width'] = intval( $values['width'] ); |
|
83 | + $current = $setting[ 'value' ]; |
|
84 | + if ( isset( $values[ 'width' ] ) ) { |
|
85 | + $current[ 'width' ] = intval( $values[ 'width' ] ); |
|
86 | 86 | } |
87 | - if ( isset( $values['height'] ) ) { |
|
88 | - $current['height'] = intval( $values['height'] ); |
|
87 | + if ( isset( $values[ 'height' ] ) ) { |
|
88 | + $current[ 'height' ] = intval( $values[ 'height' ] ); |
|
89 | 89 | } |
90 | - if ( isset( $values['crop'] ) ) { |
|
91 | - $current['crop'] = (bool) $values['crop']; |
|
90 | + if ( isset( $values[ 'crop' ] ) ) { |
|
91 | + $current[ 'crop' ] = (bool) $values[ 'crop' ]; |
|
92 | 92 | } |
93 | 93 | return $current; |
94 | 94 | } |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | if ( in_array( $value, array( 'yes', 'no' ), true ) ) { |
118 | 118 | return $value; |
119 | 119 | } elseif ( empty( $value ) ) { |
120 | - $value = isset( $setting['default'] ) ? $setting['default'] : 'no'; |
|
120 | + $value = isset( $setting[ 'default' ] ) ? $setting[ 'default' ] : 'no'; |
|
121 | 121 | return $value; |
122 | 122 | } else { |
123 | 123 | return new \WP_Error( 'rest_setting_value_invalid', __( 'An invalid setting value was passed.', 'woocommerce' ), array( 'status' => 400 ) ); |
@@ -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 | } |
@@ -111,21 +111,21 @@ discard block |
||
111 | 111 | global $wpdb; |
112 | 112 | |
113 | 113 | $prepared_args = array(); |
114 | - $prepared_args['order'] = $request['order']; |
|
115 | - $prepared_args['number'] = $request['per_page']; |
|
116 | - if ( ! empty( $request['offset'] ) ) { |
|
117 | - $prepared_args['offset'] = $request['offset']; |
|
114 | + $prepared_args[ 'order' ] = $request[ 'order' ]; |
|
115 | + $prepared_args[ 'number' ] = $request[ 'per_page' ]; |
|
116 | + if ( ! empty( $request[ 'offset' ] ) ) { |
|
117 | + $prepared_args[ 'offset' ] = $request[ 'offset' ]; |
|
118 | 118 | } else { |
119 | - $prepared_args['offset'] = ( $request['page'] - 1 ) * $prepared_args['number']; |
|
119 | + $prepared_args[ 'offset' ] = ( $request[ 'page' ] - 1 ) * $prepared_args[ 'number' ]; |
|
120 | 120 | } |
121 | 121 | $orderby_possibles = array( |
122 | 122 | 'id' => 'tax_rate_id', |
123 | 123 | 'order' => 'tax_rate_order', |
124 | 124 | ); |
125 | - $prepared_args['orderby'] = $orderby_possibles[ $request['orderby'] ]; |
|
126 | - $prepared_args['class'] = $request['class']; |
|
127 | - $prepared_args['code'] = $request['code']; |
|
128 | - $prepared_args['include'] = $request['include']; |
|
125 | + $prepared_args[ 'orderby' ] = $orderby_possibles[ $request[ 'orderby' ] ]; |
|
126 | + $prepared_args[ 'class' ] = $request[ 'class' ]; |
|
127 | + $prepared_args[ 'code' ] = $request[ 'code' ]; |
|
128 | + $prepared_args[ 'include' ] = $request[ 'include' ]; |
|
129 | 129 | |
130 | 130 | /** |
131 | 131 | * Filter arguments, before passing to $wpdb->get_results(), when querying taxes via the REST API. |
@@ -142,13 +142,13 @@ discard block |
||
142 | 142 | "; |
143 | 143 | |
144 | 144 | // Filter by tax class. |
145 | - if ( ! empty( $prepared_args['class'] ) ) { |
|
146 | - $class = 'standard' !== $prepared_args['class'] ? sanitize_title( $prepared_args['class'] ) : ''; |
|
145 | + if ( ! empty( $prepared_args[ 'class' ] ) ) { |
|
146 | + $class = 'standard' !== $prepared_args[ 'class' ] ? sanitize_title( $prepared_args[ 'class' ] ) : ''; |
|
147 | 147 | $query .= " AND tax_rate_class = '$class'"; |
148 | 148 | } |
149 | 149 | |
150 | 150 | // Filter by tax code. |
151 | - $tax_code_search = $prepared_args['code']; |
|
151 | + $tax_code_search = $prepared_args[ 'code' ]; |
|
152 | 152 | if ( $tax_code_search ) { |
153 | 153 | $tax_code_search = $wpdb->esc_like( $tax_code_search ); |
154 | 154 | $tax_code_search = ' \'%' . $tax_code_search . '%\''; |
@@ -156,17 +156,17 @@ discard block |
||
156 | 156 | } |
157 | 157 | |
158 | 158 | // Filter by included tax rate IDs. |
159 | - $included_taxes = $prepared_args['include']; |
|
159 | + $included_taxes = $prepared_args[ 'include' ]; |
|
160 | 160 | if ( ! empty( $included_taxes ) ) { |
161 | - $included_taxes = implode( ',', $prepared_args['include'] ); |
|
161 | + $included_taxes = implode( ',', $prepared_args[ 'include' ] ); |
|
162 | 162 | $query .= " AND tax_rate_id IN ({$included_taxes})"; |
163 | 163 | } |
164 | 164 | |
165 | 165 | // Order tax rates. |
166 | - $order_by = sprintf( ' ORDER BY %s', sanitize_key( $prepared_args['orderby'] ) ); |
|
166 | + $order_by = sprintf( ' ORDER BY %s', sanitize_key( $prepared_args[ 'orderby' ] ) ); |
|
167 | 167 | |
168 | 168 | // Pagination. |
169 | - $pagination = sprintf( ' LIMIT %d, %d', $prepared_args['offset'], $prepared_args['number'] ); |
|
169 | + $pagination = sprintf( ' LIMIT %d, %d', $prepared_args[ 'offset' ], $prepared_args[ 'number' ] ); |
|
170 | 170 | |
171 | 171 | // Query taxes. |
172 | 172 | $results = $wpdb->get_results( $query . $order_by . $pagination ); // @codingStandardsIgnoreLine. |
@@ -174,12 +174,12 @@ discard block |
||
174 | 174 | $taxes = array(); |
175 | 175 | foreach ( $results as $tax ) { |
176 | 176 | $data = $this->prepare_item_for_response( $tax, $request ); |
177 | - $taxes[] = $this->prepare_response_for_collection( $data ); |
|
177 | + $taxes[ ] = $this->prepare_response_for_collection( $data ); |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | // Store pagination values for headers then unset for count query. |
181 | - $per_page = (int) $prepared_args['number']; |
|
182 | - $page = ceil( ( ( (int) $prepared_args['offset'] ) / $per_page ) + 1 ); |
|
181 | + $per_page = (int) $prepared_args[ 'number' ]; |
|
182 | + $page = ceil( ( ( (int) $prepared_args[ 'offset' ] ) / $per_page ) + 1 ); |
|
183 | 183 | |
184 | 184 | // Query only for ids. |
185 | 185 | $wpdb->get_results( str_replace( 'SELECT *', 'SELECT tax_rate_id', $query ) ); // @codingStandardsIgnoreLine. |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | * @return object |
203 | 203 | */ |
204 | 204 | protected function create_or_update_tax( $request, $current = null ) { |
205 | - $id = absint( isset( $request['id'] ) ? $request['id'] : 0 ); |
|
205 | + $id = absint( isset( $request[ 'id' ] ) ? $request[ 'id' ] : 0 ); |
|
206 | 206 | $data = array(); |
207 | 207 | $fields = array( |
208 | 208 | 'tax_rate_country', |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | $data[ $field ] = absint( $request[ $key ] ); |
240 | 240 | break; |
241 | 241 | case 'tax_rate_class': |
242 | - $data[ $field ] = 'standard' !== $request['tax_rate_class'] ? $request['tax_rate_class'] : ''; |
|
242 | + $data[ $field ] = 'standard' !== $request[ 'tax_rate_class' ] ? $request[ 'tax_rate_class' ] : ''; |
|
243 | 243 | break; |
244 | 244 | default: |
245 | 245 | $data[ $field ] = wc_clean( $request[ $key ] ); |
@@ -254,11 +254,11 @@ discard block |
||
254 | 254 | } |
255 | 255 | |
256 | 256 | // Add locales. |
257 | - if ( ! empty( $request['postcode'] ) ) { |
|
258 | - \WC_Tax::_update_tax_rate_postcodes( $id, wc_clean( $request['postcode'] ) ); |
|
257 | + if ( ! empty( $request[ 'postcode' ] ) ) { |
|
258 | + \WC_Tax::_update_tax_rate_postcodes( $id, wc_clean( $request[ 'postcode' ] ) ); |
|
259 | 259 | } |
260 | - if ( ! empty( $request['city'] ) ) { |
|
261 | - \WC_Tax::_update_tax_rate_cities( $id, wc_clean( $request['city'] ) ); |
|
260 | + if ( ! empty( $request[ 'city' ] ) ) { |
|
261 | + \WC_Tax::_update_tax_rate_cities( $id, wc_clean( $request[ 'city' ] ) ); |
|
262 | 262 | } |
263 | 263 | |
264 | 264 | return \WC_Tax::_get_tax_rate( $id, OBJECT ); |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | * @return \WP_Error|\WP_REST_Response |
272 | 272 | */ |
273 | 273 | public function create_item( $request ) { |
274 | - if ( ! empty( $request['id'] ) ) { |
|
274 | + if ( ! empty( $request[ 'id' ] ) ) { |
|
275 | 275 | return new \WP_Error( 'woocommerce_rest_tax_exists', __( 'Cannot create existing resource.', 'woocommerce' ), array( 'status' => 400 ) ); |
276 | 276 | } |
277 | 277 | |
@@ -304,7 +304,7 @@ discard block |
||
304 | 304 | * @return \WP_Error|\WP_REST_Response |
305 | 305 | */ |
306 | 306 | public function get_item( $request ) { |
307 | - $id = (int) $request['id']; |
|
307 | + $id = (int) $request[ 'id' ]; |
|
308 | 308 | $tax_obj = \WC_Tax::_get_tax_rate( $id, OBJECT ); |
309 | 309 | |
310 | 310 | if ( empty( $id ) || empty( $tax_obj ) ) { |
@@ -324,7 +324,7 @@ discard block |
||
324 | 324 | * @return \WP_Error|\WP_REST_Response |
325 | 325 | */ |
326 | 326 | public function update_item( $request ) { |
327 | - $id = (int) $request['id']; |
|
327 | + $id = (int) $request[ 'id' ]; |
|
328 | 328 | $tax_obj = \WC_Tax::_get_tax_rate( $id, OBJECT ); |
329 | 329 | |
330 | 330 | if ( empty( $id ) || empty( $tax_obj ) ) { |
@@ -360,8 +360,8 @@ discard block |
||
360 | 360 | public function delete_item( $request ) { |
361 | 361 | global $wpdb; |
362 | 362 | |
363 | - $id = (int) $request['id']; |
|
364 | - $force = isset( $request['force'] ) ? (bool) $request['force'] : false; |
|
363 | + $id = (int) $request[ 'id' ]; |
|
364 | + $force = isset( $request[ 'force' ] ) ? (bool) $request[ 'force' ] : false; |
|
365 | 365 | |
366 | 366 | // We don't support trashing for this type, error out. |
367 | 367 | if ( ! $force ) { |
@@ -551,10 +551,10 @@ discard block |
||
551 | 551 | */ |
552 | 552 | public function get_collection_params() { |
553 | 553 | $params = array(); |
554 | - $params['context'] = $this->get_context_param(); |
|
555 | - $params['context']['default'] = 'view'; |
|
554 | + $params[ 'context' ] = $this->get_context_param(); |
|
555 | + $params[ 'context' ][ 'default' ] = 'view'; |
|
556 | 556 | |
557 | - $params['page'] = array( |
|
557 | + $params[ 'page' ] = array( |
|
558 | 558 | 'description' => __( 'Current page of the collection.', 'woocommerce' ), |
559 | 559 | 'type' => 'integer', |
560 | 560 | 'default' => 1, |
@@ -562,7 +562,7 @@ discard block |
||
562 | 562 | 'validate_callback' => 'rest_validate_request_arg', |
563 | 563 | 'minimum' => 1, |
564 | 564 | ); |
565 | - $params['per_page'] = array( |
|
565 | + $params[ 'per_page' ] = array( |
|
566 | 566 | 'description' => __( 'Maximum number of items to be returned in result set.', 'woocommerce' ), |
567 | 567 | 'type' => 'integer', |
568 | 568 | 'default' => 10, |
@@ -571,13 +571,13 @@ discard block |
||
571 | 571 | 'sanitize_callback' => 'absint', |
572 | 572 | 'validate_callback' => 'rest_validate_request_arg', |
573 | 573 | ); |
574 | - $params['offset'] = array( |
|
574 | + $params[ 'offset' ] = array( |
|
575 | 575 | 'description' => __( 'Offset the result set by a specific number of items.', 'woocommerce' ), |
576 | 576 | 'type' => 'integer', |
577 | 577 | 'sanitize_callback' => 'absint', |
578 | 578 | 'validate_callback' => 'rest_validate_request_arg', |
579 | 579 | ); |
580 | - $params['order'] = array( |
|
580 | + $params[ 'order' ] = array( |
|
581 | 581 | 'default' => 'asc', |
582 | 582 | 'description' => __( 'Order sort attribute ascending or descending.', 'woocommerce' ), |
583 | 583 | 'enum' => array( 'asc', 'desc' ), |
@@ -585,7 +585,7 @@ discard block |
||
585 | 585 | 'type' => 'string', |
586 | 586 | 'validate_callback' => 'rest_validate_request_arg', |
587 | 587 | ); |
588 | - $params['orderby'] = array( |
|
588 | + $params[ 'orderby' ] = array( |
|
589 | 589 | 'default' => 'order', |
590 | 590 | 'description' => __( 'Sort collection by object attribute.', 'woocommerce' ), |
591 | 591 | 'enum' => array( |
@@ -596,19 +596,19 @@ discard block |
||
596 | 596 | 'type' => 'string', |
597 | 597 | 'validate_callback' => 'rest_validate_request_arg', |
598 | 598 | ); |
599 | - $params['class'] = array( |
|
599 | + $params[ 'class' ] = array( |
|
600 | 600 | 'description' => __( 'Sort by tax class.', 'woocommerce' ), |
601 | 601 | 'enum' => array_merge( array( 'standard' ), \WC_Tax::get_tax_class_slugs() ), |
602 | 602 | 'sanitize_callback' => 'sanitize_title', |
603 | 603 | 'type' => 'string', |
604 | 604 | 'validate_callback' => 'rest_validate_request_arg', |
605 | 605 | ); |
606 | - $params['code'] = array( |
|
606 | + $params[ 'code' ] = array( |
|
607 | 607 | 'description' => __( 'Search by similar tax code.', 'woocommerce' ), |
608 | 608 | 'type' => 'string', |
609 | 609 | 'validate_callback' => 'rest_validate_request_arg', |
610 | 610 | ); |
611 | - $params['include'] = array( |
|
611 | + $params[ 'include' ] = array( |
|
612 | 612 | 'description' => __( 'Limit result set to items that have the specified rate ID(s) assigned.', 'woocommerce' ), |
613 | 613 | 'type' => 'array', |
614 | 614 | 'items' => array( |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | * @return \WP_Error|\WP_REST_Response |
120 | 120 | */ |
121 | 121 | public function get_item( $request ) { |
122 | - $setting = $this->get_setting( $request['group_id'], $request['id'] ); |
|
122 | + $setting = $this->get_setting( $request[ 'group_id' ], $request[ 'id' ] ); |
|
123 | 123 | |
124 | 124 | if ( is_wp_error( $setting ) ) { |
125 | 125 | return $setting; |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | * @return \WP_Error|\WP_REST_Response |
139 | 139 | */ |
140 | 140 | public function get_items( $request ) { |
141 | - $settings = $this->get_group_settings( $request['group_id'] ); |
|
141 | + $settings = $this->get_group_settings( $request[ 'group_id' ] ); |
|
142 | 142 | |
143 | 143 | if ( is_wp_error( $settings ) ) { |
144 | 144 | return $settings; |
@@ -149,8 +149,8 @@ discard block |
||
149 | 149 | foreach ( $settings as $setting_obj ) { |
150 | 150 | $setting = $this->prepare_item_for_response( $setting_obj, $request ); |
151 | 151 | $setting = $this->prepare_response_for_collection( $setting ); |
152 | - if ( $this->is_setting_type_valid( $setting['type'] ) ) { |
|
153 | - $data[] = $setting; |
|
152 | + if ( $this->is_setting_type_valid( $setting[ 'type' ] ) ) { |
|
153 | + $data[ ] = $setting; |
|
154 | 154 | } |
155 | 155 | } |
156 | 156 | |
@@ -176,26 +176,26 @@ discard block |
||
176 | 176 | |
177 | 177 | $filtered_settings = array(); |
178 | 178 | foreach ( $settings as $setting ) { |
179 | - $option_key = $setting['option_key']; |
|
179 | + $option_key = $setting[ 'option_key' ]; |
|
180 | 180 | $setting = $this->filter_setting( $setting ); |
181 | - $default = isset( $setting['default'] ) ? $setting['default'] : ''; |
|
181 | + $default = isset( $setting[ 'default' ] ) ? $setting[ 'default' ] : ''; |
|
182 | 182 | // Get the option value. |
183 | 183 | if ( is_array( $option_key ) ) { |
184 | - $option = get_option( $option_key[0] ); |
|
185 | - $setting['value'] = isset( $option[ $option_key[1] ] ) ? $option[ $option_key[1] ] : $default; |
|
184 | + $option = get_option( $option_key[ 0 ] ); |
|
185 | + $setting[ 'value' ] = isset( $option[ $option_key[ 1 ] ] ) ? $option[ $option_key[ 1 ] ] : $default; |
|
186 | 186 | } else { |
187 | 187 | $admin_setting_value = \WC_Admin_Settings::get_option( $option_key, $default ); |
188 | - $setting['value'] = $admin_setting_value; |
|
188 | + $setting[ 'value' ] = $admin_setting_value; |
|
189 | 189 | } |
190 | 190 | |
191 | - if ( 'multi_select_countries' === $setting['type'] ) { |
|
192 | - $setting['options'] = WC()->countries->get_countries(); |
|
193 | - $setting['type'] = 'multiselect'; |
|
194 | - } elseif ( 'single_select_country' === $setting['type'] ) { |
|
195 | - $setting['type'] = 'select'; |
|
196 | - $setting['options'] = $this->get_countries_and_states(); |
|
197 | - } elseif ( 'single_select_page' === $setting['type'] ) { |
|
198 | - $pages = get_pages( |
|
191 | + if ( 'multi_select_countries' === $setting[ 'type' ] ) { |
|
192 | + $setting[ 'options' ] = WC()->countries->get_countries(); |
|
193 | + $setting[ 'type' ] = 'multiselect'; |
|
194 | + } elseif ( 'single_select_country' === $setting[ 'type' ] ) { |
|
195 | + $setting[ 'type' ] = 'select'; |
|
196 | + $setting[ 'options' ] = $this->get_countries_and_states(); |
|
197 | + } elseif ( 'single_select_page' === $setting[ 'type' ] ) { |
|
198 | + $pages = get_pages( |
|
199 | 199 | array( |
200 | 200 | 'sort_column' => 'menu_order', |
201 | 201 | 'sort_order' => 'ASC', |
@@ -206,11 +206,11 @@ discard block |
||
206 | 206 | foreach ( $pages as $page ) { |
207 | 207 | $options[ $page->ID ] = ! empty( $page->post_title ) ? $page->post_title : '#' . $page->ID; |
208 | 208 | } |
209 | - $setting['type'] = 'select'; |
|
210 | - $setting['options'] = $options; |
|
209 | + $setting[ 'type' ] = 'select'; |
|
210 | + $setting[ 'options' ] = $options; |
|
211 | 211 | } |
212 | 212 | |
213 | - $filtered_settings[] = $setting; |
|
213 | + $filtered_settings[ ] = $setting; |
|
214 | 214 | } |
215 | 215 | |
216 | 216 | return $filtered_settings; |
@@ -267,9 +267,9 @@ discard block |
||
267 | 267 | return new \WP_Error( 'rest_setting_setting_invalid', __( 'Invalid setting.', 'woocommerce' ), array( 'status' => 404 ) ); |
268 | 268 | } |
269 | 269 | |
270 | - $setting = $settings[ $array_key[0] ]; |
|
270 | + $setting = $settings[ $array_key[ 0 ] ]; |
|
271 | 271 | |
272 | - if ( ! $this->is_setting_type_valid( $setting['type'] ) ) { |
|
272 | + if ( ! $this->is_setting_type_valid( $setting[ 'type' ] ) ) { |
|
273 | 273 | return new \WP_Error( 'rest_setting_setting_invalid', __( 'Invalid setting.', 'woocommerce' ), array( 'status' => 404 ) ); |
274 | 274 | } |
275 | 275 | |
@@ -277,7 +277,7 @@ discard block |
||
277 | 277 | return $setting; |
278 | 278 | } |
279 | 279 | |
280 | - $setting['group_id'] = $group_id; |
|
280 | + $setting[ 'group_id' ] = $group_id; |
|
281 | 281 | |
282 | 282 | return $setting; |
283 | 283 | } |
@@ -319,32 +319,32 @@ discard block |
||
319 | 319 | * @return \WP_Error|\WP_REST_Response |
320 | 320 | */ |
321 | 321 | public function update_item( $request ) { |
322 | - $setting = $this->get_setting( $request['group_id'], $request['id'] ); |
|
322 | + $setting = $this->get_setting( $request[ 'group_id' ], $request[ 'id' ] ); |
|
323 | 323 | |
324 | 324 | if ( is_wp_error( $setting ) ) { |
325 | 325 | return $setting; |
326 | 326 | } |
327 | 327 | |
328 | - if ( is_callable( array( $this, 'validate_setting_' . $setting['type'] . '_field' ) ) ) { |
|
329 | - $value = $this->{'validate_setting_' . $setting['type'] . '_field'}( $request['value'], $setting ); |
|
328 | + if ( is_callable( array( $this, 'validate_setting_' . $setting[ 'type' ] . '_field' ) ) ) { |
|
329 | + $value = $this->{'validate_setting_' . $setting[ 'type' ] . '_field'}( $request[ 'value' ], $setting ); |
|
330 | 330 | } else { |
331 | - $value = $this->validate_setting_text_field( $request['value'], $setting ); |
|
331 | + $value = $this->validate_setting_text_field( $request[ 'value' ], $setting ); |
|
332 | 332 | } |
333 | 333 | |
334 | 334 | if ( is_wp_error( $value ) ) { |
335 | 335 | return $value; |
336 | 336 | } |
337 | 337 | |
338 | - if ( is_array( $setting['option_key'] ) ) { |
|
339 | - $setting['value'] = $value; |
|
340 | - $option_key = $setting['option_key']; |
|
341 | - $prev = get_option( $option_key[0] ); |
|
342 | - $prev[ $option_key[1] ] = $request['value']; |
|
343 | - update_option( $option_key[0], $prev ); |
|
338 | + if ( is_array( $setting[ 'option_key' ] ) ) { |
|
339 | + $setting[ 'value' ] = $value; |
|
340 | + $option_key = $setting[ 'option_key' ]; |
|
341 | + $prev = get_option( $option_key[ 0 ] ); |
|
342 | + $prev[ $option_key[ 1 ] ] = $request[ 'value' ]; |
|
343 | + update_option( $option_key[ 0 ], $prev ); |
|
344 | 344 | } else { |
345 | 345 | $update_data = array(); |
346 | - $update_data[ $setting['option_key'] ] = $value; |
|
347 | - $setting['value'] = $value; |
|
346 | + $update_data[ $setting[ 'option_key' ] ] = $value; |
|
347 | + $setting[ 'value' ] = $value; |
|
348 | 348 | \WC_Admin_Settings::save_fields( array( $setting ), $update_data ); |
349 | 349 | } |
350 | 350 | |
@@ -361,7 +361,7 @@ discard block |
||
361 | 361 | * @return array Array of data in the correct format. |
362 | 362 | */ |
363 | 363 | protected function get_data_for_response( $object, $request ) { |
364 | - unset( $object['option_key'] ); |
|
364 | + unset( $object[ 'option_key' ] ); |
|
365 | 365 | return $this->filter_setting( $object ); |
366 | 366 | } |
367 | 367 | |
@@ -373,10 +373,10 @@ discard block |
||
373 | 373 | * @return array |
374 | 374 | */ |
375 | 375 | protected function prepare_links( $item, $request ) { |
376 | - $base = str_replace( '(?P<group_id>[\w-]+)', $request['group_id'], $this->rest_base ); |
|
376 | + $base = str_replace( '(?P<group_id>[\w-]+)', $request[ 'group_id' ], $this->rest_base ); |
|
377 | 377 | $links = array( |
378 | 378 | 'self' => array( |
379 | - 'href' => rest_url( sprintf( '/%s/%s/%s', $this->namespace, $base, $item['id'] ) ), |
|
379 | + 'href' => rest_url( sprintf( '/%s/%s/%s', $this->namespace, $base, $item[ 'id' ] ) ), |
|
380 | 380 | ), |
381 | 381 | 'collection' => array( |
382 | 382 | 'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $base ) ), |
@@ -400,11 +400,11 @@ discard block |
||
400 | 400 | array_flip( array_filter( array_keys( $setting ), array( $this, 'allowed_setting_keys' ) ) ) |
401 | 401 | ); |
402 | 402 | |
403 | - if ( empty( $setting['options'] ) ) { |
|
404 | - unset( $setting['options'] ); |
|
403 | + if ( empty( $setting[ 'options' ] ) ) { |
|
404 | + unset( $setting[ 'options' ] ); |
|
405 | 405 | } |
406 | 406 | |
407 | - if ( 'image_width' === $setting['type'] ) { |
|
407 | + if ( 'image_width' === $setting[ 'type' ] ) { |
|
408 | 408 | $setting = $this->cast_image_width( $setting ); |
409 | 409 | } |
410 | 410 | |
@@ -423,9 +423,9 @@ discard block |
||
423 | 423 | public function cast_image_width( $setting ) { |
424 | 424 | foreach ( array( 'default', 'value' ) as $key ) { |
425 | 425 | if ( isset( $setting[ $key ] ) ) { |
426 | - $setting[ $key ]['width'] = intval( $setting[ $key ]['width'] ); |
|
427 | - $setting[ $key ]['height'] = intval( $setting[ $key ]['height'] ); |
|
428 | - $setting[ $key ]['crop'] = (bool) $setting[ $key ]['crop']; |
|
426 | + $setting[ $key ][ 'width' ] = intval( $setting[ $key ][ 'width' ] ); |
|
427 | + $setting[ $key ][ 'height' ] = intval( $setting[ $key ][ 'height' ] ); |
|
428 | + $setting[ $key ][ 'crop' ] = (bool) $setting[ $key ][ 'crop' ]; |
|
429 | 429 | } |
430 | 430 | } |
431 | 431 | return $setting; |
@@ -465,17 +465,17 @@ discard block |
||
465 | 465 | public function is_setting_type_valid( $type ) { |
466 | 466 | return in_array( |
467 | 467 | $type, array( |
468 | - 'text', // Validates with validate_setting_text_field. |
|
469 | - 'email', // Validates with validate_setting_text_field. |
|
470 | - 'number', // Validates with validate_setting_text_field. |
|
471 | - 'color', // Validates with validate_setting_text_field. |
|
472 | - 'password', // Validates with validate_setting_text_field. |
|
473 | - 'textarea', // Validates with validate_setting_textarea_field. |
|
474 | - 'select', // Validates with validate_setting_select_field. |
|
475 | - 'multiselect', // Validates with validate_setting_multiselect_field. |
|
476 | - 'radio', // Validates with validate_setting_radio_field (-> validate_setting_select_field). |
|
477 | - 'checkbox', // Validates with validate_setting_checkbox_field. |
|
478 | - 'image_width', // Validates with validate_setting_image_width_field. |
|
468 | + 'text', // Validates with validate_setting_text_field. |
|
469 | + 'email', // Validates with validate_setting_text_field. |
|
470 | + 'number', // Validates with validate_setting_text_field. |
|
471 | + 'color', // Validates with validate_setting_text_field. |
|
472 | + 'password', // Validates with validate_setting_text_field. |
|
473 | + 'textarea', // Validates with validate_setting_textarea_field. |
|
474 | + 'select', // Validates with validate_setting_select_field. |
|
475 | + 'multiselect', // Validates with validate_setting_multiselect_field. |
|
476 | + 'radio', // Validates with validate_setting_radio_field (-> validate_setting_select_field). |
|
477 | + 'checkbox', // Validates with validate_setting_checkbox_field. |
|
478 | + 'image_width', // Validates with validate_setting_image_width_field. |
|
479 | 479 | 'thumbnail_cropping', // Validates with validate_setting_text_field. |
480 | 480 | ) |
481 | 481 | ); |
@@ -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 | } |
@@ -522,17 +522,17 @@ discard block |
||
522 | 522 | $params = parent::get_collection_params(); |
523 | 523 | |
524 | 524 | unset( |
525 | - $params['in_stock'], |
|
526 | - $params['type'], |
|
527 | - $params['featured'], |
|
528 | - $params['category'], |
|
529 | - $params['tag'], |
|
530 | - $params['shipping_class'], |
|
531 | - $params['attribute'], |
|
532 | - $params['attribute_term'] |
|
525 | + $params[ 'in_stock' ], |
|
526 | + $params[ 'type' ], |
|
527 | + $params[ 'featured' ], |
|
528 | + $params[ 'category' ], |
|
529 | + $params[ 'tag' ], |
|
530 | + $params[ 'shipping_class' ], |
|
531 | + $params[ 'attribute' ], |
|
532 | + $params[ 'attribute_term' ] |
|
533 | 533 | ); |
534 | 534 | |
535 | - $params['stock_status'] = array( |
|
535 | + $params[ 'stock_status' ] = array( |
|
536 | 536 | 'description' => __( 'Limit result set to products with specified stock status.', 'woocommerce' ), |
537 | 537 | 'type' => 'string', |
538 | 538 | 'enum' => array_keys( wc_get_product_stock_status_options() ), |
@@ -540,7 +540,7 @@ discard block |
||
540 | 540 | 'validate_callback' => 'rest_validate_request_arg', |
541 | 541 | ); |
542 | 542 | |
543 | - $params['search'] = array( |
|
543 | + $params[ 'search' ] = array( |
|
544 | 544 | 'description' => __( 'Search by similar product name or sku.', 'woocommerce' ), |
545 | 545 | 'type' => 'string', |
546 | 546 | 'validate_callback' => 'rest_validate_request_arg', |
@@ -575,7 +575,7 @@ discard block |
||
575 | 575 | } |
576 | 576 | |
577 | 577 | // Check if variation belongs to the correct parent product. |
578 | - if ( $object && 0 !== $object->get_parent_id() && absint( $request['product_id'] ) !== $object->get_parent_id() ) { |
|
578 | + if ( $object && 0 !== $object->get_parent_id() && absint( $request[ 'product_id' ] ) !== $object->get_parent_id() ) { |
|
579 | 579 | return new \WP_Error( 'woocommerce_rest_cannot_edit', __( 'Parent product does not match current variation.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
580 | 580 | } |
581 | 581 | return true; |
@@ -653,7 +653,7 @@ discard block |
||
653 | 653 | $args = parent::prepare_objects_query( $request ); |
654 | 654 | |
655 | 655 | // Set post_status. |
656 | - $args['post_status'] = $request['status']; |
|
656 | + $args[ 'post_status' ] = $request[ 'status' ]; |
|
657 | 657 | |
658 | 658 | // Set custom args to handle later during clauses. |
659 | 659 | $custom_keys = array( |
@@ -670,19 +670,19 @@ discard block |
||
670 | 670 | } |
671 | 671 | |
672 | 672 | // Filter by tax class. |
673 | - if ( ! empty( $request['tax_class'] ) ) { |
|
674 | - $args['meta_query'] = $this->add_meta_query( // WPCS: slow query ok. |
|
673 | + if ( ! empty( $request[ 'tax_class' ] ) ) { |
|
674 | + $args[ 'meta_query' ] = $this->add_meta_query( // WPCS: slow query ok. |
|
675 | 675 | $args, |
676 | 676 | array( |
677 | 677 | 'key' => '_tax_class', |
678 | - 'value' => 'standard' !== $request['tax_class'] ? $request['tax_class'] : '', |
|
678 | + 'value' => 'standard' !== $request[ 'tax_class' ] ? $request[ 'tax_class' ] : '', |
|
679 | 679 | ) |
680 | 680 | ); |
681 | 681 | } |
682 | 682 | |
683 | 683 | // Filter by on sale products. |
684 | - if ( is_bool( $request['on_sale'] ) ) { |
|
685 | - $on_sale_key = $request['on_sale'] ? 'post__in' : 'post__not_in'; |
|
684 | + if ( is_bool( $request[ 'on_sale' ] ) ) { |
|
685 | + $on_sale_key = $request[ 'on_sale' ] ? 'post__in' : 'post__not_in'; |
|
686 | 686 | $on_sale_ids = wc_get_product_ids_on_sale(); |
687 | 687 | |
688 | 688 | // Use 0 when there's no on sale products to avoid return all products. |
@@ -692,17 +692,17 @@ discard block |
||
692 | 692 | } |
693 | 693 | |
694 | 694 | // Force the post_type argument, since it's not a user input variable. |
695 | - if ( ! empty( $request['sku'] ) ) { |
|
696 | - $args['post_type'] = array( 'product', 'product_variation' ); |
|
695 | + if ( ! empty( $request[ 'sku' ] ) ) { |
|
696 | + $args[ 'post_type' ] = array( 'product', 'product_variation' ); |
|
697 | 697 | } else { |
698 | - $args['post_type'] = $this->post_type; |
|
698 | + $args[ 'post_type' ] = $this->post_type; |
|
699 | 699 | } |
700 | 700 | |
701 | - $args['post_parent'] = $request['product_id']; |
|
701 | + $args[ 'post_parent' ] = $request[ 'product_id' ]; |
|
702 | 702 | |
703 | - if ( ! empty( $request['search'] ) ) { |
|
704 | - $args['search'] = $request['search']; |
|
705 | - unset( $args['s'] ); |
|
703 | + if ( ! empty( $request[ 'search' ] ) ) { |
|
704 | + $args[ 'search' ] = $request[ 'search' ]; |
|
705 | + unset( $args[ 's' ] ); |
|
706 | 706 | } |
707 | 707 | |
708 | 708 | return $args; |
@@ -745,8 +745,8 @@ discard block |
||
745 | 745 | * @return bool|\WP_Error|\WP_REST_Response |
746 | 746 | */ |
747 | 747 | public function delete_item( $request ) { |
748 | - $force = (bool) $request['force']; |
|
749 | - $object = $this->get_object( (int) $request['id'] ); |
|
748 | + $force = (bool) $request[ 'force' ]; |
|
749 | + $object = $this->get_object( (int) $request[ 'id' ] ); |
|
750 | 750 | $result = false; |
751 | 751 | |
752 | 752 | if ( ! $object || 0 === $object->get_id() ) { |
@@ -854,7 +854,7 @@ discard block |
||
854 | 854 | protected function get_batch_of_items_from_request( $request, $batch_type ) { |
855 | 855 | $params = $request->get_params(); |
856 | 856 | $url_params = $request->get_url_params(); |
857 | - $product_id = $url_params['product_id']; |
|
857 | + $product_id = $url_params[ 'product_id' ]; |
|
858 | 858 | |
859 | 859 | if ( ! isset( $params[ $batch_type ] ) ) { |
860 | 860 | return array(); |
@@ -884,7 +884,7 @@ discard block |
||
884 | 884 | * @return array |
885 | 885 | */ |
886 | 886 | protected function prepare_links( $item, $request ) { |
887 | - $product_id = (int) $request['product_id']; |
|
887 | + $product_id = (int) $request[ 'product_id' ]; |
|
888 | 888 | $base = str_replace( '(?P<product_id>[\d]+)', $product_id, $this->rest_base ); |
889 | 889 | $links = array( |
890 | 890 | 'self' => array( |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | foreach ( array_keys( $currencies ) as $code ) { |
109 | 109 | $currency = $this->get_currency( $code, $request ); |
110 | 110 | $response = $this->prepare_item_for_response( $currency, $request ); |
111 | - $data[] = $this->prepare_response_for_collection( $response ); |
|
111 | + $data[ ] = $this->prepare_response_for_collection( $response ); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | return rest_ensure_response( $data ); |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | * @return \WP_Error|\WP_REST_Response |
122 | 122 | */ |
123 | 123 | public function get_item( $request ) { |
124 | - $data = $this->get_currency( strtoupper( $request['currency'] ), $request ); |
|
124 | + $data = $this->get_currency( strtoupper( $request[ 'currency' ] ), $request ); |
|
125 | 125 | if ( empty( $data ) ) { |
126 | 126 | return new \WP_Error( 'woocommerce_rest_data_invalid_currency', __( 'There are no currencies matching these parameters.', 'woocommerce' ), array( 'status' => 404 ) ); |
127 | 127 | } |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | * @return array |
159 | 159 | */ |
160 | 160 | protected function prepare_links( $item, $request ) { |
161 | - $code = strtoupper( $item['code'] ); |
|
161 | + $code = strtoupper( $item[ 'code' ] ); |
|
162 | 162 | $links = array( |
163 | 163 | 'self' => array( |
164 | 164 | 'href' => rest_url( sprintf( '/%s/%s/%s', $this->namespace, $this->rest_base, $code ) ), |