@@ -86,11 +86,11 @@ discard block |
||
86 | 86 | |
87 | 87 | $continent = array( |
88 | 88 | 'code' => $continent_code, |
89 | - 'name' => $continent_list['name'], |
|
89 | + 'name' => $continent_list[ 'name' ], |
|
90 | 90 | ); |
91 | 91 | |
92 | 92 | $local_countries = array(); |
93 | - foreach ( $continent_list['countries'] as $country_code ) { |
|
93 | + foreach ( $continent_list[ 'countries' ] as $country_code ) { |
|
94 | 94 | if ( isset( $countries[ $country_code ] ) ) { |
95 | 95 | $country = array( |
96 | 96 | 'code' => $country_code, |
@@ -119,13 +119,13 @@ discard block |
||
119 | 119 | $local_states = array(); |
120 | 120 | if ( isset( $states[ $country_code ] ) ) { |
121 | 121 | foreach ( $states[ $country_code ] as $state_code => $state_name ) { |
122 | - $local_states[] = array( |
|
122 | + $local_states[ ] = array( |
|
123 | 123 | 'code' => $state_code, |
124 | 124 | 'name' => $state_name, |
125 | 125 | ); |
126 | 126 | } |
127 | 127 | } |
128 | - $country['states'] = $local_states; |
|
128 | + $country[ 'states' ] = $local_states; |
|
129 | 129 | |
130 | 130 | // Allow only desired keys (e.g. filter out tax rates). |
131 | 131 | $allowed = array( |
@@ -142,11 +142,11 @@ discard block |
||
142 | 142 | ); |
143 | 143 | $country = array_intersect_key( $country, array_flip( $allowed ) ); |
144 | 144 | |
145 | - $local_countries[] = $country; |
|
145 | + $local_countries[ ] = $country; |
|
146 | 146 | } |
147 | 147 | } |
148 | 148 | |
149 | - $continent['countries'] = $local_countries; |
|
149 | + $continent[ 'countries' ] = $local_countries; |
|
150 | 150 | return $continent; |
151 | 151 | } |
152 | 152 | |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | foreach ( array_keys( $continents ) as $continent_code ) { |
165 | 165 | $continent = $this->get_continent( $continent_code, $request ); |
166 | 166 | $response = $this->prepare_item_for_response( $continent, $request ); |
167 | - $data[] = $this->prepare_response_for_collection( $response ); |
|
167 | + $data[ ] = $this->prepare_response_for_collection( $response ); |
|
168 | 168 | } |
169 | 169 | |
170 | 170 | return rest_ensure_response( $data ); |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | * @return \WP_Error|\WP_REST_Response |
179 | 179 | */ |
180 | 180 | public function get_item( $request ) { |
181 | - $data = $this->get_continent( strtoupper( $request['location'] ), $request ); |
|
181 | + $data = $this->get_continent( strtoupper( $request[ 'location' ] ), $request ); |
|
182 | 182 | if ( empty( $data ) ) { |
183 | 183 | return new \WP_Error( 'woocommerce_rest_data_invalid_location', __( 'There are no locations matching these parameters.', 'woocommerce-rest-api' ), array( 'status' => 404 ) ); |
184 | 184 | } |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | * @return array |
205 | 205 | */ |
206 | 206 | protected function prepare_links( $item, $request ) { |
207 | - $continent_code = strtolower( $item['code'] ); |
|
207 | + $continent_code = strtolower( $item[ 'code' ] ); |
|
208 | 208 | $links = array( |
209 | 209 | 'self' => array( |
210 | 210 | 'href' => rest_url( sprintf( '/%s/%s/%s', $this->namespace, $this->rest_base, $continent_code ) ), |
@@ -87,13 +87,13 @@ discard block |
||
87 | 87 | $local_states = array(); |
88 | 88 | if ( isset( $states[ $country_code ] ) ) { |
89 | 89 | foreach ( $states[ $country_code ] as $state_code => $state_name ) { |
90 | - $local_states[] = array( |
|
90 | + $local_states[ ] = array( |
|
91 | 91 | 'code' => $state_code, |
92 | 92 | 'name' => $state_name, |
93 | 93 | ); |
94 | 94 | } |
95 | 95 | } |
96 | - $country['states'] = $local_states; |
|
96 | + $country[ 'states' ] = $local_states; |
|
97 | 97 | return $country; |
98 | 98 | } |
99 | 99 | |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | foreach ( array_keys( $countries ) as $country_code ) { |
112 | 112 | $country = $this->get_country( $country_code, $request ); |
113 | 113 | $response = $this->prepare_item_for_response( $country, $request ); |
114 | - $data[] = $this->prepare_response_for_collection( $response ); |
|
114 | + $data[ ] = $this->prepare_response_for_collection( $response ); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | return rest_ensure_response( $data ); |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | * @return \WP_Error|\WP_REST_Response |
126 | 126 | */ |
127 | 127 | public function get_item( $request ) { |
128 | - $data = $this->get_country( strtoupper( $request['location'] ), $request ); |
|
128 | + $data = $this->get_country( strtoupper( $request[ 'location' ] ), $request ); |
|
129 | 129 | if ( empty( $data ) ) { |
130 | 130 | return new \WP_Error( 'woocommerce_rest_data_invalid_location', __( 'There are no locations matching these parameters.', 'woocommerce-rest-api' ), array( 'status' => 404 ) ); |
131 | 131 | } |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | * @return array |
152 | 152 | */ |
153 | 153 | protected function prepare_links( $item, $request ) { |
154 | - $country_code = strtolower( $item['code'] ); |
|
154 | + $country_code = strtolower( $item[ 'code' ] ); |
|
155 | 155 | $links = array( |
156 | 156 | 'self' => array( |
157 | 157 | 'href' => rest_url( sprintf( '/%s/%s/%s', $this->namespace, $this->rest_base, $country_code ) ), |
@@ -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-rest-api' ), 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-rest-api' ), 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 | ); |
@@ -55,11 +55,11 @@ discard block |
||
55 | 55 | * @param array $methods Supported methods. read, create. |
56 | 56 | */ |
57 | 57 | protected function register_items_route( $methods = [ 'read', 'create' ] ) { |
58 | - $routes = []; |
|
59 | - $routes['schema'] = [ $this, 'get_public_item_schema' ]; |
|
58 | + $routes = [ ]; |
|
59 | + $routes[ 'schema' ] = [ $this, 'get_public_item_schema' ]; |
|
60 | 60 | |
61 | 61 | if ( in_array( 'read', $methods, true ) ) { |
62 | - $routes[] = array( |
|
62 | + $routes[ ] = array( |
|
63 | 63 | 'methods' => \WP_REST_Server::READABLE, |
64 | 64 | 'callback' => array( $this, 'get_items' ), |
65 | 65 | 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | } |
69 | 69 | |
70 | 70 | if ( in_array( 'create', $methods, true ) ) { |
71 | - $routes[] = array( |
|
71 | + $routes[ ] = array( |
|
72 | 72 | 'methods' => \WP_REST_Server::CREATABLE, |
73 | 73 | 'callback' => array( $this, 'create_item' ), |
74 | 74 | 'permission_callback' => array( $this, 'create_item_permissions_check' ), |
@@ -90,9 +90,9 @@ discard block |
||
90 | 90 | * @param array $methods Supported methods. read, create. |
91 | 91 | */ |
92 | 92 | protected function register_item_route( $methods = [ 'read', 'edit', 'delete' ] ) { |
93 | - $routes = []; |
|
94 | - $routes['schema'] = [ $this, 'get_public_item_schema' ]; |
|
95 | - $routes['args'] = [ |
|
93 | + $routes = [ ]; |
|
94 | + $routes[ 'schema' ] = [ $this, 'get_public_item_schema' ]; |
|
95 | + $routes[ 'args' ] = [ |
|
96 | 96 | 'id' => [ |
97 | 97 | 'description' => __( 'Unique identifier for the resource.', 'woocommerce-rest-api' ), |
98 | 98 | 'type' => 'integer', |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | ]; |
101 | 101 | |
102 | 102 | if ( in_array( 'read', $methods, true ) ) { |
103 | - $routes[] = array( |
|
103 | + $routes[ ] = array( |
|
104 | 104 | 'methods' => \WP_REST_Server::READABLE, |
105 | 105 | 'callback' => array( $this, 'get_item' ), |
106 | 106 | 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | } |
116 | 116 | |
117 | 117 | if ( in_array( 'edit', $methods, true ) ) { |
118 | - $routes[] = array( |
|
118 | + $routes[ ] = array( |
|
119 | 119 | 'methods' => \WP_REST_Server::EDITABLE, |
120 | 120 | 'callback' => array( $this, 'update_item' ), |
121 | 121 | 'permission_callback' => array( $this, 'update_item_permissions_check' ), |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | } |
125 | 125 | |
126 | 126 | if ( in_array( 'delete', $methods, true ) ) { |
127 | - $routes[] = array( |
|
127 | + $routes[ ] = array( |
|
128 | 128 | 'methods' => \WP_REST_Server::DELETABLE, |
129 | 129 | 'callback' => array( $this, 'delete_item' ), |
130 | 130 | 'permission_callback' => array( $this, 'delete_item_permissions_check' ), |
@@ -154,8 +154,8 @@ discard block |
||
154 | 154 | */ |
155 | 155 | protected function add_additional_fields_schema( $schema ) { |
156 | 156 | $schema = parent::add_additional_fields_schema( $schema ); |
157 | - $object_type = $schema['title']; |
|
158 | - $schema['properties'] = apply_filters( 'woocommerce_rest_' . $object_type . '_schema', $schema['properties'] ); |
|
157 | + $object_type = $schema[ 'title' ]; |
|
158 | + $schema[ 'properties' ] = apply_filters( 'woocommerce_rest_' . $object_type . '_schema', $schema[ 'properties' ] ); |
|
159 | 159 | return $schema; |
160 | 160 | } |
161 | 161 | |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | * @return string |
272 | 272 | */ |
273 | 273 | protected function get_request_context( $request ) { |
274 | - return ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
274 | + return ! empty( $request[ 'context' ] ) ? $request[ 'context' ] : 'view'; |
|
275 | 275 | } |
276 | 276 | |
277 | 277 | /** |
@@ -312,7 +312,7 @@ discard block |
||
312 | 312 | */ |
313 | 313 | protected function get_item_title() { |
314 | 314 | $schema = $this->get_item_schema(); |
315 | - return $schema['title']; |
|
315 | + return $schema[ 'title' ]; |
|
316 | 316 | } |
317 | 317 | |
318 | 318 | /** |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | ]; |
52 | 52 | |
53 | 53 | $request_props = array_intersect_key( $this->request, array_flip( $props ) ); |
54 | - $prop_values = []; |
|
54 | + $prop_values = [ ]; |
|
55 | 55 | |
56 | 56 | foreach ( $request_props as $prop => $value ) { |
57 | 57 | switch ( $prop ) { |
@@ -95,8 +95,8 @@ discard block |
||
95 | 95 | if ( ! is_array( $item ) ) { |
96 | 96 | continue; |
97 | 97 | } |
98 | - if ( $this->item_is_null( $item ) || ( isset( $item['quantity'] ) && 0 === $item['quantity'] ) ) { |
|
99 | - $object->remove_item( $item['id'] ); |
|
98 | + if ( $this->item_is_null( $item ) || ( isset( $item[ 'quantity' ] ) && 0 === $item[ 'quantity' ] ) ) { |
|
99 | + $object->remove_item( $item[ 'id' ] ); |
|
100 | 100 | } else { |
101 | 101 | $this->set_item( $object, $type, $item ); |
102 | 102 | } |
@@ -156,11 +156,11 @@ discard block |
||
156 | 156 | * @param array $posted Request data. |
157 | 157 | */ |
158 | 158 | protected function maybe_set_item_meta_data( $item, $posted ) { |
159 | - if ( ! empty( $posted['meta_data'] ) && is_array( $posted['meta_data'] ) ) { |
|
160 | - foreach ( $posted['meta_data'] as $meta ) { |
|
161 | - if ( isset( $meta['key'] ) ) { |
|
162 | - $value = isset( $meta['value'] ) ? $meta['value'] : null; |
|
163 | - $item->update_meta_data( $meta['key'], $value, isset( $meta['id'] ) ? $meta['id'] : '' ); |
|
159 | + if ( ! empty( $posted[ 'meta_data' ] ) && is_array( $posted[ 'meta_data' ] ) ) { |
|
160 | + foreach ( $posted[ 'meta_data' ] as $meta ) { |
|
161 | + if ( isset( $meta[ 'key' ] ) ) { |
|
162 | + $value = isset( $meta[ 'value' ] ) ? $meta[ 'value' ] : null; |
|
163 | + $item->update_meta_data( $meta[ 'key' ], $value, isset( $meta[ 'id' ] ) ? $meta[ 'id' ] : '' ); |
|
164 | 164 | } |
165 | 165 | } |
166 | 166 | } |
@@ -174,12 +174,12 @@ discard block |
||
174 | 174 | * @throws \WC_REST_Exception When SKU or ID is not valid. |
175 | 175 | */ |
176 | 176 | protected function get_product_id_from_line_item( $posted ) { |
177 | - if ( ! empty( $posted['sku'] ) ) { |
|
178 | - $product_id = (int) wc_get_product_id_by_sku( $posted['sku'] ); |
|
179 | - } elseif ( ! empty( $posted['product_id'] ) && empty( $posted['variation_id'] ) ) { |
|
180 | - $product_id = (int) $posted['product_id']; |
|
181 | - } elseif ( ! empty( $posted['variation_id'] ) ) { |
|
182 | - $product_id = (int) $posted['variation_id']; |
|
177 | + if ( ! empty( $posted[ 'sku' ] ) ) { |
|
178 | + $product_id = (int) wc_get_product_id_by_sku( $posted[ 'sku' ] ); |
|
179 | + } elseif ( ! empty( $posted[ 'product_id' ] ) && empty( $posted[ 'variation_id' ] ) ) { |
|
180 | + $product_id = (int) $posted[ 'product_id' ]; |
|
181 | + } elseif ( ! empty( $posted[ 'variation_id' ] ) ) { |
|
182 | + $product_id = (int) $posted[ 'variation_id' ]; |
|
183 | 183 | } else { |
184 | 184 | throw new \WC_REST_Exception( 'woocommerce_rest_required_product_reference', __( 'Product ID or SKU is required.', 'woocommerce-rest-api' ), 400 ); |
185 | 185 | } |
@@ -196,14 +196,14 @@ discard block |
||
196 | 196 | * @throws \WC_REST_Exception Invalid data, server error. |
197 | 197 | */ |
198 | 198 | protected function prepare_line_items( $posted, $action = 'create', $item = null ) { |
199 | - $item = is_null( $item ) ? new \WC_Order_Item_Product( ! empty( $posted['id'] ) ? $posted['id'] : '' ) : $item; |
|
199 | + $item = is_null( $item ) ? new \WC_Order_Item_Product( ! empty( $posted[ 'id' ] ) ? $posted[ 'id' ] : '' ) : $item; |
|
200 | 200 | $product = wc_get_product( $this->get_product_id_from_line_item( $posted ) ); |
201 | 201 | |
202 | 202 | if ( $product !== $item->get_product() ) { |
203 | 203 | $item->set_product( $product ); |
204 | 204 | |
205 | 205 | if ( 'create' === $action ) { |
206 | - $quantity = isset( $posted['quantity'] ) ? $posted['quantity'] : 1; |
|
206 | + $quantity = isset( $posted[ 'quantity' ] ) ? $posted[ 'quantity' ] : 1; |
|
207 | 207 | $total = wc_get_price_excluding_tax( $product, array( 'qty' => $quantity ) ); |
208 | 208 | $item->set_total( $total ); |
209 | 209 | $item->set_subtotal( $total ); |
@@ -226,10 +226,10 @@ discard block |
||
226 | 226 | * @throws \WC_REST_Exception Invalid data, server error. |
227 | 227 | */ |
228 | 228 | protected function prepare_shipping_lines( $posted, $action = 'create', $item = null ) { |
229 | - $item = is_null( $item ) ? new \WC_Order_Item_Shipping( ! empty( $posted['id'] ) ? $posted['id'] : '' ) : $item; |
|
229 | + $item = is_null( $item ) ? new \WC_Order_Item_Shipping( ! empty( $posted[ 'id' ] ) ? $posted[ 'id' ] : '' ) : $item; |
|
230 | 230 | |
231 | 231 | if ( 'create' === $action ) { |
232 | - if ( empty( $posted['method_id'] ) ) { |
|
232 | + if ( empty( $posted[ 'method_id' ] ) ) { |
|
233 | 233 | throw new \WC_REST_Exception( 'woocommerce_rest_invalid_shipping_item', __( 'Shipping method ID is required.', 'woocommerce-rest-api' ), 400 ); |
234 | 234 | } |
235 | 235 | } |
@@ -250,10 +250,10 @@ discard block |
||
250 | 250 | * @throws \WC_REST_Exception Invalid data, server error. |
251 | 251 | */ |
252 | 252 | protected function prepare_fee_lines( $posted, $action = 'create', $item = null ) { |
253 | - $item = is_null( $item ) ? new \WC_Order_Item_Fee( ! empty( $posted['id'] ) ? $posted['id'] : '' ) : $item; |
|
253 | + $item = is_null( $item ) ? new \WC_Order_Item_Fee( ! empty( $posted[ 'id' ] ) ? $posted[ 'id' ] : '' ) : $item; |
|
254 | 254 | |
255 | 255 | if ( 'create' === $action ) { |
256 | - if ( empty( $posted['name'] ) ) { |
|
256 | + if ( empty( $posted[ 'name' ] ) ) { |
|
257 | 257 | throw new \WC_REST_Exception( 'woocommerce_rest_invalid_fee_item', __( 'Fee name is required.', 'woocommerce-rest-api' ), 400 ); |
258 | 258 | } |
259 | 259 | } |
@@ -275,7 +275,7 @@ discard block |
||
275 | 275 | * @throws \WC_REST_Exception If item ID is not associated with order. |
276 | 276 | */ |
277 | 277 | protected function set_item( &$order, $item_type, $posted ) { |
278 | - if ( ! empty( $posted['id'] ) ) { |
|
278 | + if ( ! empty( $posted[ 'id' ] ) ) { |
|
279 | 279 | $action = 'update'; |
280 | 280 | } else { |
281 | 281 | $action = 'create'; |
@@ -286,7 +286,7 @@ discard block |
||
286 | 286 | |
287 | 287 | // Verify provided line item ID is associated with order. |
288 | 288 | if ( 'update' === $action ) { |
289 | - $item = $order->get_item( absint( $posted['id'] ), false ); |
|
289 | + $item = $order->get_item( absint( $posted[ 'id' ] ), false ); |
|
290 | 290 | |
291 | 291 | if ( ! $item ) { |
292 | 292 | throw new \WC_REST_Exception( 'woocommerce_rest_invalid_item_id', __( 'Order item ID provided is not associated with order.', 'woocommerce-rest-api' ), 400 ); |
@@ -315,7 +315,7 @@ discard block |
||
315 | 315 | * @return array |
316 | 316 | */ |
317 | 317 | protected function parse_address_field( $data, $object, $type = 'billing' ) { |
318 | - $address = []; |
|
318 | + $address = [ ]; |
|
319 | 319 | foreach ( $data as $key => $value ) { |
320 | 320 | if ( is_callable( array( $object, "set_{$type}_{$key}" ) ) ) { |
321 | 321 | $address[ "{$type}_{$key}" ] = $value; |
@@ -368,12 +368,12 @@ discard block |
||
368 | 368 | |
369 | 369 | foreach ( $coupon_lines as $item ) { |
370 | 370 | if ( is_array( $item ) ) { |
371 | - if ( empty( $item['id'] ) ) { |
|
372 | - if ( empty( $item['code'] ) ) { |
|
371 | + if ( empty( $item[ 'id' ] ) ) { |
|
372 | + if ( empty( $item[ 'code' ] ) ) { |
|
373 | 373 | throw new \WC_REST_Exception( 'woocommerce_rest_invalid_coupon', __( 'Coupon code is required.', 'woocommerce-rest-api' ), 400 ); |
374 | 374 | } |
375 | 375 | |
376 | - $results = $order->apply_coupon( wc_clean( $item['code'] ) ); |
|
376 | + $results = $order->apply_coupon( wc_clean( $item[ 'code' ] ) ); |
|
377 | 377 | |
378 | 378 | if ( is_wp_error( $results ) ) { |
379 | 379 | throw new \WC_REST_Exception( 'woocommerce_rest_' . $results->get_error_code(), $results->get_error_message(), 400 ); |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | foreach ( $wc_shipping->get_shipping_methods() as $id => $shipping_method ) { |
85 | 85 | $method = $this->prepare_item_for_response( $shipping_method, $request ); |
86 | 86 | $method = $this->prepare_response_for_collection( $method ); |
87 | - $response[] = $method; |
|
87 | + $response[ ] = $method; |
|
88 | 88 | } |
89 | 89 | return rest_ensure_response( $response ); |
90 | 90 | } |
@@ -98,11 +98,11 @@ discard block |
||
98 | 98 | public function get_item( $request ) { |
99 | 99 | $wc_shipping = \WC_Shipping::instance(); |
100 | 100 | $methods = $wc_shipping->get_shipping_methods(); |
101 | - if ( empty( $methods[ $request['id'] ] ) ) { |
|
101 | + if ( empty( $methods[ $request[ 'id' ] ] ) ) { |
|
102 | 102 | return new \WP_Error( 'woocommerce_rest_shipping_method_invalid', __( 'Resource does not exist.', 'woocommerce-rest-api' ), array( 'status' => 404 ) ); |
103 | 103 | } |
104 | 104 | |
105 | - $method = $methods[ $request['id'] ]; |
|
105 | + $method = $methods[ $request[ 'id' ] ]; |
|
106 | 106 | $response = $this->prepare_item_for_response( $method, $request ); |
107 | 107 | |
108 | 108 | return rest_ensure_response( $response ); |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | * @return \WP_Error|boolean |
120 | 120 | */ |
121 | 121 | public function get_item_permissions_check( $request ) { |
122 | - $order = wc_get_order( (int) $request['order_id'] ); |
|
122 | + $order = wc_get_order( (int) $request[ 'order_id' ] ); |
|
123 | 123 | |
124 | 124 | if ( $order && ! Permissions::user_can_read( $this->post_type, $order->get_id() ) ) { |
125 | 125 | return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce-rest-api' ), array( 'status' => rest_authorization_required_code() ) ); |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | * @return bool|\WP_Error |
137 | 137 | */ |
138 | 138 | public function delete_item_permissions_check( $request ) { |
139 | - $order = wc_get_order( (int) $request['order_id'] ); |
|
139 | + $order = wc_get_order( (int) $request[ 'order_id' ] ); |
|
140 | 140 | |
141 | 141 | if ( $order && ! Permissions::user_can_delete( $this->post_type, $order->get_id() ) ) { |
142 | 142 | return new \WP_Error( 'woocommerce_rest_cannot_delete', __( 'Sorry, you are not allowed to delete this resource.', 'woocommerce-rest-api' ), array( 'status' => rest_authorization_required_code() ) ); |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | * @return array|\WP_Error |
154 | 154 | */ |
155 | 155 | public function get_items( $request ) { |
156 | - $order = wc_get_order( (int) $request['order_id'] ); |
|
156 | + $order = wc_get_order( (int) $request[ 'order_id' ] ); |
|
157 | 157 | |
158 | 158 | if ( ! $order || $this->post_type !== $order->get_type() ) { |
159 | 159 | return new \WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'Invalid order ID.', 'woocommerce-rest-api' ), array( 'status' => 404 ) ); |
@@ -166,16 +166,16 @@ discard block |
||
166 | 166 | ); |
167 | 167 | |
168 | 168 | // Allow filter by order note type. |
169 | - if ( 'customer' === $request['type'] ) { |
|
170 | - $args['meta_query'] = array( // WPCS: slow query ok. |
|
169 | + if ( 'customer' === $request[ 'type' ] ) { |
|
170 | + $args[ 'meta_query' ] = array( // WPCS: slow query ok. |
|
171 | 171 | array( |
172 | 172 | 'key' => 'is_customer_note', |
173 | 173 | 'value' => 1, |
174 | 174 | 'compare' => '=', |
175 | 175 | ), |
176 | 176 | ); |
177 | - } elseif ( 'internal' === $request['type'] ) { |
|
178 | - $args['meta_query'] = array( // WPCS: slow query ok. |
|
177 | + } elseif ( 'internal' === $request[ 'type' ] ) { |
|
178 | + $args[ 'meta_query' ] = array( // WPCS: slow query ok. |
|
179 | 179 | array( |
180 | 180 | 'key' => 'is_customer_note', |
181 | 181 | 'compare' => 'NOT EXISTS', |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | foreach ( $notes as $note ) { |
194 | 194 | $order_note = $this->prepare_item_for_response( $note, $request ); |
195 | 195 | $order_note = $this->prepare_response_for_collection( $order_note ); |
196 | - $data[] = $order_note; |
|
196 | + $data[ ] = $order_note; |
|
197 | 197 | } |
198 | 198 | |
199 | 199 | return rest_ensure_response( $data ); |
@@ -206,19 +206,19 @@ discard block |
||
206 | 206 | * @return \WP_Error|\WP_REST_Response |
207 | 207 | */ |
208 | 208 | public function create_item( $request ) { |
209 | - if ( ! empty( $request['id'] ) ) { |
|
209 | + if ( ! empty( $request[ 'id' ] ) ) { |
|
210 | 210 | /* translators: %s: post type */ |
211 | 211 | return new \WP_Error( "woocommerce_rest_{$this->post_type}_exists", sprintf( __( 'Cannot create existing %s.', 'woocommerce-rest-api' ), $this->post_type ), array( 'status' => 400 ) ); |
212 | 212 | } |
213 | 213 | |
214 | - $order = wc_get_order( (int) $request['order_id'] ); |
|
214 | + $order = wc_get_order( (int) $request[ 'order_id' ] ); |
|
215 | 215 | |
216 | 216 | if ( ! $order || $this->post_type !== $order->get_type() ) { |
217 | 217 | return new \WP_Error( 'woocommerce_rest_order_invalid_id', __( 'Invalid order ID.', 'woocommerce-rest-api' ), array( 'status' => 404 ) ); |
218 | 218 | } |
219 | 219 | |
220 | 220 | // Create the note. |
221 | - $note_id = $order->add_order_note( $request['note'], $request['customer_note'], $request['added_by_user'] ); |
|
221 | + $note_id = $order->add_order_note( $request[ 'note' ], $request[ 'customer_note' ], $request[ 'added_by_user' ] ); |
|
222 | 222 | |
223 | 223 | if ( ! $note_id ) { |
224 | 224 | return new \WP_Error( 'woocommerce_api_cannot_create_order_note', __( 'Cannot create order note, please try again.', 'woocommerce-rest-api' ), array( 'status' => 500 ) ); |
@@ -252,8 +252,8 @@ discard block |
||
252 | 252 | * @return \WP_Error|\WP_REST_Response |
253 | 253 | */ |
254 | 254 | public function get_item( $request ) { |
255 | - $id = (int) $request['id']; |
|
256 | - $order = wc_get_order( (int) $request['order_id'] ); |
|
255 | + $id = (int) $request[ 'id' ]; |
|
256 | + $order = wc_get_order( (int) $request[ 'order_id' ] ); |
|
257 | 257 | |
258 | 258 | if ( ! $order || $this->post_type !== $order->get_type() ) { |
259 | 259 | return new \WP_Error( 'woocommerce_rest_order_invalid_id', __( 'Invalid order ID.', 'woocommerce-rest-api' ), array( 'status' => 404 ) ); |
@@ -278,15 +278,15 @@ discard block |
||
278 | 278 | * @return \WP_REST_Response|\WP_Error |
279 | 279 | */ |
280 | 280 | public function delete_item( $request ) { |
281 | - $id = (int) $request['id']; |
|
282 | - $force = isset( $request['force'] ) ? (bool) $request['force'] : false; |
|
281 | + $id = (int) $request[ 'id' ]; |
|
282 | + $force = isset( $request[ 'force' ] ) ? (bool) $request[ 'force' ] : false; |
|
283 | 283 | |
284 | 284 | // We don't support trashing for this type, error out. |
285 | 285 | if ( ! $force ) { |
286 | 286 | return new \WP_Error( 'woocommerce_rest_trash_not_supported', __( 'Webhooks do not support trashing.', 'woocommerce-rest-api' ), array( 'status' => 501 ) ); |
287 | 287 | } |
288 | 288 | |
289 | - $order = wc_get_order( (int) $request['order_id'] ); |
|
289 | + $order = wc_get_order( (int) $request[ 'order_id' ] ); |
|
290 | 290 | |
291 | 291 | if ( ! $order || $this->post_type !== $order->get_type() ) { |
292 | 292 | return new \WP_Error( 'woocommerce_rest_order_invalid_id', __( 'Invalid order ID.', 'woocommerce-rest-api' ), array( 'status' => 404 ) ); |
@@ -434,8 +434,8 @@ discard block |
||
434 | 434 | */ |
435 | 435 | public function get_collection_params() { |
436 | 436 | $params = array(); |
437 | - $params['context'] = $this->get_context_param( array( 'default' => 'view' ) ); |
|
438 | - $params['type'] = array( |
|
437 | + $params[ 'context' ] = $this->get_context_param( array( 'default' => 'view' ) ); |
|
438 | + $params[ 'type' ] = array( |
|
439 | 439 | 'default' => 'any', |
440 | 440 | 'description' => __( 'Limit result to customers or internal notes.', 'woocommerce-rest-api' ), |
441 | 441 | 'type' => 'string', |
@@ -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-rest-api' ), 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-rest-api' ), |
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-rest-api' ), |
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-rest-api' ), |
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-rest-api' ), |
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-rest-api' ), |
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-rest-api' ), |
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-rest-api' ), |
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-rest-api' ), |
613 | 613 | 'type' => 'array', |
614 | 614 | 'items' => array( |
@@ -100,7 +100,7 @@ |
||
100 | 100 | |
101 | 101 | \WC_Install::install(); |
102 | 102 | |
103 | - $GLOBALS['wp_roles'] = null; // WPCS: override ok. |
|
103 | + $GLOBALS[ 'wp_roles' ] = null; // WPCS: override ok. |
|
104 | 104 | \wp_roles(); |
105 | 105 | } ); |
106 | 106 | } |