@@ -102,19 +102,19 @@ discard block |
||
102 | 102 | foreach ( $groups as $group ) { |
103 | 103 | $sub_groups = array(); |
104 | 104 | foreach ( $groups as $_group ) { |
105 | - if ( ! empty( $_group['parent_id'] ) && $group['id'] === $_group['parent_id'] ) { |
|
106 | - $sub_groups[] = $_group['id']; |
|
105 | + if ( ! empty( $_group[ 'parent_id' ] ) && $group[ 'id' ] === $_group[ 'parent_id' ] ) { |
|
106 | + $sub_groups[ ] = $_group[ 'id' ]; |
|
107 | 107 | } |
108 | 108 | } |
109 | - $group['sub_groups'] = $sub_groups; |
|
109 | + $group[ 'sub_groups' ] = $sub_groups; |
|
110 | 110 | |
111 | 111 | $group = wp_parse_args( $group, $defaults ); |
112 | - if ( ! is_null( $group['id'] ) && ! is_null( $group['label'] ) ) { |
|
112 | + if ( ! is_null( $group[ 'id' ] ) && ! is_null( $group[ 'label' ] ) ) { |
|
113 | 113 | $group_obj = $this->filter_group( $group ); |
114 | 114 | $group_data = $this->prepare_item_for_response( $group_obj, $request ); |
115 | 115 | $group_data = $this->prepare_response_for_collection( $group_data ); |
116 | 116 | |
117 | - $filtered_groups[] = $group_data; |
|
117 | + $filtered_groups[ ] = $group_data; |
|
118 | 118 | } |
119 | 119 | } |
120 | 120 | |
@@ -148,13 +148,13 @@ discard block |
||
148 | 148 | * @return \WP_REST_Response $response Response data. |
149 | 149 | */ |
150 | 150 | public function prepare_item_for_response( $item, $request ) { |
151 | - $context = empty( $request['context'] ) ? 'view' : $request['context']; |
|
151 | + $context = empty( $request[ 'context' ] ) ? 'view' : $request[ 'context' ]; |
|
152 | 152 | $data = $this->add_additional_fields_to_object( $item, $request ); |
153 | 153 | $data = $this->filter_response_by_context( $data, $context ); |
154 | 154 | |
155 | 155 | $response = rest_ensure_response( $data ); |
156 | 156 | |
157 | - $response->add_links( $this->prepare_links( $item['id'] ) ); |
|
157 | + $response->add_links( $this->prepare_links( $item[ 'id' ] ) ); |
|
158 | 158 | |
159 | 159 | return $response; |
160 | 160 | } |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | * @return \WP_REST_Response|\WP_Error |
55 | 55 | */ |
56 | 56 | public function get_items( $request ) { |
57 | - $zone = $this->get_zone( (int) $request['id'] ); |
|
57 | + $zone = $this->get_zone( (int) $request[ 'id' ] ); |
|
58 | 58 | |
59 | 59 | if ( is_wp_error( $zone ) ) { |
60 | 60 | return $zone; |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | foreach ( $locations as $location_obj ) { |
67 | 67 | $location = $this->prepare_item_for_response( $location_obj, $request ); |
68 | 68 | $location = $this->prepare_response_for_collection( $location ); |
69 | - $data[] = $location; |
|
69 | + $data[ ] = $location; |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | return rest_ensure_response( $data ); |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | * @return \WP_REST_Response|\WP_Error |
80 | 80 | */ |
81 | 81 | public function update_items( $request ) { |
82 | - $zone = $this->get_zone( (int) $request['id'] ); |
|
82 | + $zone = $this->get_zone( (int) $request[ 'id' ] ); |
|
83 | 83 | |
84 | 84 | if ( is_wp_error( $zone ) ) { |
85 | 85 | return $zone; |
@@ -93,18 +93,18 @@ discard block |
||
93 | 93 | $locations = array(); |
94 | 94 | |
95 | 95 | foreach ( (array) $raw_locations as $raw_location ) { |
96 | - if ( empty( $raw_location['code'] ) ) { |
|
96 | + if ( empty( $raw_location[ 'code' ] ) ) { |
|
97 | 97 | continue; |
98 | 98 | } |
99 | 99 | |
100 | - $type = ! empty( $raw_location['type'] ) ? sanitize_text_field( $raw_location['type'] ) : 'country'; |
|
100 | + $type = ! empty( $raw_location[ 'type' ] ) ? sanitize_text_field( $raw_location[ 'type' ] ) : 'country'; |
|
101 | 101 | |
102 | 102 | if ( ! in_array( $type, array( 'postcode', 'state', 'country', 'continent' ), true ) ) { |
103 | 103 | continue; |
104 | 104 | } |
105 | 105 | |
106 | - $locations[] = array( |
|
107 | - 'code' => sanitize_text_field( $raw_location['code'] ), |
|
106 | + $locations[ ] = array( |
|
107 | + 'code' => sanitize_text_field( $raw_location[ 'code' ] ), |
|
108 | 108 | 'type' => sanitize_text_field( $type ), |
109 | 109 | ); |
110 | 110 | } |
@@ -123,14 +123,14 @@ discard block |
||
123 | 123 | * @return \WP_REST_Response $response |
124 | 124 | */ |
125 | 125 | public function prepare_item_for_response( $item, $request ) { |
126 | - $context = empty( $request['context'] ) ? 'view' : $request['context']; |
|
126 | + $context = empty( $request[ 'context' ] ) ? 'view' : $request[ 'context' ]; |
|
127 | 127 | $data = $this->add_additional_fields_to_object( $item, $request ); |
128 | 128 | $data = $this->filter_response_by_context( $data, $context ); |
129 | 129 | |
130 | 130 | // Wrap the data in a response object. |
131 | 131 | $response = rest_ensure_response( $data ); |
132 | 132 | |
133 | - $response->add_links( $this->prepare_links( (int) $request['id'] ) ); |
|
133 | + $response->add_links( $this->prepare_links( (int) $request[ 'id' ] ) ); |
|
134 | 134 | |
135 | 135 | return $response; |
136 | 136 | } |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | foreach ( $zones as $zone_obj ) { |
125 | 125 | $zone = $this->prepare_item_for_response( $zone_obj, $request ); |
126 | 126 | $zone = $this->prepare_response_for_collection( $zone ); |
127 | - $data[] = $zone; |
|
127 | + $data[ ] = $zone; |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | return rest_ensure_response( $data ); |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | return $zone; |
210 | 210 | } |
211 | 211 | |
212 | - $force = $request['force']; |
|
212 | + $force = $request[ 'force' ]; |
|
213 | 213 | |
214 | 214 | // We don't support trashing for this type, error out. |
215 | 215 | if ( ! $force ) { |
@@ -238,19 +238,19 @@ discard block |
||
238 | 238 | */ |
239 | 239 | public function prepare_item_for_response( $item, $request ) { |
240 | 240 | $data = array( |
241 | - 'id' => (int) $item['id'], |
|
242 | - 'name' => $item['zone_name'], |
|
243 | - 'order' => (int) $item['zone_order'], |
|
241 | + 'id' => (int) $item[ 'id' ], |
|
242 | + 'name' => $item[ 'zone_name' ], |
|
243 | + 'order' => (int) $item[ 'zone_order' ], |
|
244 | 244 | ); |
245 | 245 | |
246 | - $context = empty( $request['context'] ) ? 'view' : $request['context']; |
|
246 | + $context = empty( $request[ 'context' ] ) ? 'view' : $request[ 'context' ]; |
|
247 | 247 | $data = $this->add_additional_fields_to_object( $data, $request ); |
248 | 248 | $data = $this->filter_response_by_context( $data, $context ); |
249 | 249 | |
250 | 250 | // Wrap the data in a response object. |
251 | 251 | $response = rest_ensure_response( $data ); |
252 | 252 | |
253 | - $response->add_links( $this->prepare_links( $data['id'] ) ); |
|
253 | + $response->add_links( $this->prepare_links( $data[ 'id' ] ) ); |
|
254 | 254 | |
255 | 255 | return $response; |
256 | 256 | } |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | $tax_classes = array(); |
131 | 131 | |
132 | 132 | // Add standard class. |
133 | - $tax_classes[] = array( |
|
133 | + $tax_classes[ ] = array( |
|
134 | 134 | 'slug' => 'standard', |
135 | 135 | 'name' => __( 'Standard rate', 'woocommerce' ), |
136 | 136 | ); |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | $classes = \WC_Tax::get_tax_classes(); |
139 | 139 | |
140 | 140 | foreach ( $classes as $class ) { |
141 | - $tax_classes[] = array( |
|
141 | + $tax_classes[ ] = array( |
|
142 | 142 | 'slug' => sanitize_title( $class ), |
143 | 143 | 'name' => $class, |
144 | 144 | ); |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | foreach ( $tax_classes as $tax_class ) { |
149 | 149 | $class = $this->prepare_item_for_response( $tax_class, $request ); |
150 | 150 | $class = $this->prepare_response_for_collection( $class ); |
151 | - $data[] = $class; |
|
151 | + $data[ ] = $class; |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | return rest_ensure_response( $data ); |
@@ -164,13 +164,13 @@ discard block |
||
164 | 164 | $exists = false; |
165 | 165 | $classes = \WC_Tax::get_tax_classes(); |
166 | 166 | $tax_class = array( |
167 | - 'slug' => sanitize_title( $request['name'] ), |
|
168 | - 'name' => $request['name'], |
|
167 | + 'slug' => sanitize_title( $request[ 'name' ] ), |
|
168 | + 'name' => $request[ 'name' ], |
|
169 | 169 | ); |
170 | 170 | |
171 | 171 | // Check if class exists. |
172 | 172 | foreach ( $classes as $key => $class ) { |
173 | - if ( sanitize_title( $class ) === $tax_class['slug'] ) { |
|
173 | + if ( sanitize_title( $class ) === $tax_class[ 'slug' ] ) { |
|
174 | 174 | $exists = true; |
175 | 175 | break; |
176 | 176 | } |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | } |
183 | 183 | |
184 | 184 | // Add the new class. |
185 | - $classes[] = $tax_class['name']; |
|
185 | + $classes[ ] = $tax_class[ 'name' ]; |
|
186 | 186 | |
187 | 187 | update_option( 'woocommerce_tax_classes', implode( "\n", $classes ) ); |
188 | 188 | |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | $response = $this->prepare_item_for_response( $tax_class, $request ); |
202 | 202 | $response = rest_ensure_response( $response ); |
203 | 203 | $response->set_status( 201 ); |
204 | - $response->header( 'Location', rest_url( sprintf( '/%s/%s/%s', $this->namespace, $this->rest_base, $tax_class['slug'] ) ) ); |
|
204 | + $response->header( 'Location', rest_url( sprintf( '/%s/%s/%s', $this->namespace, $this->rest_base, $tax_class[ 'slug' ] ) ) ); |
|
205 | 205 | |
206 | 206 | return $response; |
207 | 207 | } |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | public function delete_item( $request ) { |
216 | 216 | global $wpdb; |
217 | 217 | |
218 | - $force = isset( $request['force'] ) ? (bool) $request['force'] : false; |
|
218 | + $force = isset( $request[ 'force' ] ) ? (bool) $request[ 'force' ] : false; |
|
219 | 219 | |
220 | 220 | // We don't support trashing for this type, error out. |
221 | 221 | if ( ! $force ) { |
@@ -223,15 +223,15 @@ discard block |
||
223 | 223 | } |
224 | 224 | |
225 | 225 | $tax_class = array( |
226 | - 'slug' => sanitize_title( $request['slug'] ), |
|
226 | + 'slug' => sanitize_title( $request[ 'slug' ] ), |
|
227 | 227 | 'name' => '', |
228 | 228 | ); |
229 | 229 | $classes = \WC_Tax::get_tax_classes(); |
230 | 230 | $deleted = false; |
231 | 231 | |
232 | 232 | foreach ( $classes as $key => $class ) { |
233 | - if ( sanitize_title( $class ) === $tax_class['slug'] ) { |
|
234 | - $tax_class['name'] = $class; |
|
233 | + if ( sanitize_title( $class ) === $tax_class[ 'slug' ] ) { |
|
234 | + $tax_class[ 'name' ] = $class; |
|
235 | 235 | unset( $classes[ $key ] ); |
236 | 236 | $deleted = true; |
237 | 237 | break; |
@@ -258,12 +258,12 @@ discard block |
||
258 | 258 | ON rates.tax_rate_id = locations.tax_rate_id |
259 | 259 | WHERE rates.tax_rate_class = %s |
260 | 260 | ", |
261 | - $tax_class['slug'] |
|
261 | + $tax_class[ 'slug' ] |
|
262 | 262 | ) |
263 | 263 | ); |
264 | 264 | |
265 | 265 | // Delete tax rates in the selected class. |
266 | - $wpdb->delete( $wpdb->prefix . 'woocommerce_tax_rates', array( 'tax_rate_class' => $tax_class['slug'] ), array( '%s' ) ); |
|
266 | + $wpdb->delete( $wpdb->prefix . 'woocommerce_tax_rates', array( 'tax_rate_class' => $tax_class[ 'slug' ] ), array( '%s' ) ); |
|
267 | 267 | |
268 | 268 | $response = new \WP_REST_Response(); |
269 | 269 | $response->set_data( |
@@ -295,7 +295,7 @@ discard block |
||
295 | 295 | public function prepare_item_for_response( $tax_class, $request ) { |
296 | 296 | $data = $tax_class; |
297 | 297 | |
298 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
298 | + $context = ! empty( $request[ 'context' ] ) ? $request[ 'context' ] : 'view'; |
|
299 | 299 | $data = $this->add_additional_fields_to_object( $data, $request ); |
300 | 300 | $data = $this->filter_response_by_context( $data, $context ); |
301 | 301 |
@@ -69,11 +69,11 @@ discard block |
||
69 | 69 | |
70 | 70 | foreach ( $mappings as $section => $values ) { |
71 | 71 | foreach ( $values as $key => $value ) { |
72 | - if ( isset( $schema['properties'][ $section ]['properties'][ $key ]['type'] ) ) { |
|
73 | - settype( $values[ $key ], $schema['properties'][ $section ]['properties'][ $key ]['type'] ); |
|
72 | + if ( isset( $schema[ 'properties' ][ $section ][ 'properties' ][ $key ][ 'type' ] ) ) { |
|
73 | + settype( $values[ $key ], $schema[ 'properties' ][ $section ][ 'properties' ][ $key ][ 'type' ] ); |
|
74 | 74 | } |
75 | 75 | } |
76 | - settype( $values, $schema['properties'][ $section ]['type'] ); |
|
76 | + settype( $values, $schema[ 'properties' ][ $section ][ 'type' ] ); |
|
77 | 77 | $response[ $section ] = $values; |
78 | 78 | } |
79 | 79 | |
@@ -593,7 +593,7 @@ discard block |
||
593 | 593 | $curl_version = ''; |
594 | 594 | if ( function_exists( 'curl_version' ) ) { |
595 | 595 | $curl_version = curl_version(); |
596 | - $curl_version = $curl_version['version'] . ', ' . $curl_version['ssl_version']; |
|
596 | + $curl_version = $curl_version[ 'version' ] . ', ' . $curl_version[ 'ssl_version' ]; |
|
597 | 597 | } elseif ( extension_loaded( 'curl' ) ) { |
598 | 598 | $curl_version = __( 'cURL installed but unable to retrieve version.', 'woocommerce' ); |
599 | 599 | } |
@@ -620,7 +620,7 @@ discard block |
||
620 | 620 | ) |
621 | 621 | ); |
622 | 622 | if ( ! is_wp_error( $response ) ) { |
623 | - $post_response_code = $response['response']['code']; |
|
623 | + $post_response_code = $response[ 'response' ][ 'code' ]; |
|
624 | 624 | } |
625 | 625 | set_transient( 'woocommerce_test_remote_post', $post_response_code, HOUR_IN_SECONDS ); |
626 | 626 | } |
@@ -633,7 +633,7 @@ discard block |
||
633 | 633 | if ( false === $get_response_code || is_wp_error( $get_response_code ) ) { |
634 | 634 | $response = wp_safe_remote_get( 'https://woocommerce.com/wc-api/product-key-api?request=ping&network=' . ( is_multisite() ? '1' : '0' ) ); |
635 | 635 | if ( ! is_wp_error( $response ) ) { |
636 | - $get_response_code = $response['response']['code']; |
|
636 | + $get_response_code = $response[ 'response' ][ 'code' ]; |
|
637 | 637 | } |
638 | 638 | set_transient( 'woocommerce_test_remote_get', $get_response_code, HOUR_IN_SECONDS ); |
639 | 639 | } |
@@ -656,7 +656,7 @@ discard block |
||
656 | 656 | 'wp_cron' => ! ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ), |
657 | 657 | 'language' => get_locale(), |
658 | 658 | 'external_object_cache' => wp_using_ext_object_cache(), |
659 | - 'server_info' => isset( $_SERVER['SERVER_SOFTWARE'] ) ? wc_clean( wp_unslash( $_SERVER['SERVER_SOFTWARE'] ) ) : '', |
|
659 | + 'server_info' => isset( $_SERVER[ 'SERVER_SOFTWARE' ] ) ? wc_clean( wp_unslash( $_SERVER[ 'SERVER_SOFTWARE' ] ) ) : '', |
|
660 | 660 | 'php_version' => phpversion(), |
661 | 661 | 'php_post_max_size' => wc_let_to_num( ini_get( 'post_max_size' ) ), |
662 | 662 | 'php_max_execution_time' => ini_get( 'max_execution_time' ), |
@@ -664,8 +664,8 @@ discard block |
||
664 | 664 | 'curl_version' => $curl_version, |
665 | 665 | 'suhosin_installed' => extension_loaded( 'suhosin' ), |
666 | 666 | 'max_upload_size' => wp_max_upload_size(), |
667 | - 'mysql_version' => $database_version['number'], |
|
668 | - 'mysql_version_string' => $database_version['string'], |
|
667 | + 'mysql_version' => $database_version[ 'number' ], |
|
668 | + 'mysql_version_string' => $database_version[ 'string' ], |
|
669 | 669 | 'default_timezone' => date_default_timezone_get(), |
670 | 670 | 'fsockopen_or_curl_enabled' => ( function_exists( 'fsockopen' ) || function_exists( 'curl_init' ) ), |
671 | 671 | 'soapclient_enabled' => class_exists( 'SoapClient' ), |
@@ -770,8 +770,8 @@ discard block |
||
770 | 770 | 'engine' => $table->engine, |
771 | 771 | ); |
772 | 772 | |
773 | - $database_size['data'] += $table->data; |
|
774 | - $database_size['index'] += $table->index; |
|
773 | + $database_size[ 'data' ] += $table->data; |
|
774 | + $database_size[ 'index' ] += $table->index; |
|
775 | 775 | } |
776 | 776 | |
777 | 777 | // Return all database info. Described by JSON Schema. |
@@ -819,7 +819,7 @@ discard block |
||
819 | 819 | |
820 | 820 | foreach ( $active_plugins as $plugin ) { |
821 | 821 | $data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin ); |
822 | - $active_plugins_data[] = $this->format_plugin_data( $plugin, $data ); |
|
822 | + $active_plugins_data[ ] = $this->format_plugin_data( $plugin, $data ); |
|
823 | 823 | } |
824 | 824 | |
825 | 825 | return $active_plugins_data; |
@@ -851,7 +851,7 @@ discard block |
||
851 | 851 | if ( in_array( $plugin, $active_plugins, true ) ) { |
852 | 852 | continue; |
853 | 853 | } |
854 | - $plugins_data[] = $this->format_plugin_data( $plugin, $data ); |
|
854 | + $plugins_data[ ] = $this->format_plugin_data( $plugin, $data ); |
|
855 | 855 | } |
856 | 856 | |
857 | 857 | return $plugins_data; |
@@ -877,7 +877,7 @@ discard block |
||
877 | 877 | $this->available_updates = get_plugin_updates(); |
878 | 878 | } |
879 | 879 | |
880 | - $version_latest = $data['Version']; |
|
880 | + $version_latest = $data[ 'Version' ]; |
|
881 | 881 | |
882 | 882 | // Find latest version. |
883 | 883 | if ( isset( $this->available_updates[ $plugin ]->update->new_version ) ) { |
@@ -886,13 +886,13 @@ discard block |
||
886 | 886 | |
887 | 887 | return array( |
888 | 888 | 'plugin' => $plugin, |
889 | - 'name' => $data['Name'], |
|
890 | - 'version' => $data['Version'], |
|
889 | + 'name' => $data[ 'Name' ], |
|
890 | + 'version' => $data[ 'Version' ], |
|
891 | 891 | 'version_latest' => $version_latest, |
892 | - 'url' => $data['PluginURI'], |
|
893 | - 'author_name' => $data['AuthorName'], |
|
894 | - 'author_url' => esc_url_raw( $data['AuthorURI'] ), |
|
895 | - 'network_activated' => $data['Network'], |
|
892 | + 'url' => $data[ 'PluginURI' ], |
|
893 | + 'author_name' => $data[ 'AuthorName' ], |
|
894 | + 'author_url' => esc_url_raw( $data[ 'AuthorURI' ] ), |
|
895 | + 'network_activated' => $data[ 'Network' ], |
|
896 | 896 | ); |
897 | 897 | } |
898 | 898 | |
@@ -909,21 +909,21 @@ discard block |
||
909 | 909 | 'mu_plugins' => array(), |
910 | 910 | ); |
911 | 911 | foreach ( $dropins as $key => $dropin ) { |
912 | - $plugins['dropins'][] = array( |
|
912 | + $plugins[ 'dropins' ][ ] = array( |
|
913 | 913 | 'plugin' => $key, |
914 | - 'name' => $dropin['Name'], |
|
914 | + 'name' => $dropin[ 'Name' ], |
|
915 | 915 | ); |
916 | 916 | } |
917 | 917 | |
918 | 918 | $mu_plugins = get_mu_plugins(); |
919 | 919 | foreach ( $mu_plugins as $plugin => $mu_plugin ) { |
920 | - $plugins['mu_plugins'][] = array( |
|
920 | + $plugins[ 'mu_plugins' ][ ] = array( |
|
921 | 921 | 'plugin' => $plugin, |
922 | - 'name' => $mu_plugin['Name'], |
|
923 | - 'version' => $mu_plugin['Version'], |
|
924 | - 'url' => $mu_plugin['PluginURI'], |
|
925 | - 'author_name' => $mu_plugin['AuthorName'], |
|
926 | - 'author_url' => esc_url_raw( $mu_plugin['AuthorURI'] ), |
|
922 | + 'name' => $mu_plugin[ 'Name' ], |
|
923 | + 'version' => $mu_plugin[ 'Version' ], |
|
924 | + 'url' => $mu_plugin[ 'PluginURI' ], |
|
925 | + 'author_name' => $mu_plugin[ 'AuthorName' ], |
|
926 | + 'author_url' => esc_url_raw( $mu_plugin[ 'AuthorURI' ] ), |
|
927 | 927 | ); |
928 | 928 | } |
929 | 929 | return $plugins; |
@@ -989,7 +989,7 @@ discard block |
||
989 | 989 | $outdated_templates = true; |
990 | 990 | } |
991 | 991 | } |
992 | - $override_files[] = array( |
|
992 | + $override_files[ ] = array( |
|
993 | 993 | 'file' => str_replace( WP_CONTENT_DIR . '/themes/', '', $theme_file ), |
994 | 994 | 'version' => $theme_version, |
995 | 995 | 'core_version' => $core_version, |
@@ -1036,7 +1036,7 @@ discard block |
||
1036 | 1036 | // Check if WooCommerce.com account is connected. |
1037 | 1037 | $woo_com_connected = 'no'; |
1038 | 1038 | $helper_options = get_option( 'woocommerce_helper_data', array() ); |
1039 | - if ( array_key_exists( 'auth', $helper_options ) && ! empty( $helper_options['auth'] ) ) { |
|
1039 | + if ( array_key_exists( 'auth', $helper_options ) && ! empty( $helper_options[ 'auth' ] ) ) { |
|
1040 | 1040 | $woo_com_connected = 'yes'; |
1041 | 1041 | } |
1042 | 1042 | |
@@ -1103,7 +1103,7 @@ discard block |
||
1103 | 1103 | |
1104 | 1104 | $pages_output = array(); |
1105 | 1105 | foreach ( $check_pages as $page_name => $values ) { |
1106 | - $page_id = get_option( $values['option'] ); |
|
1106 | + $page_id = get_option( $values[ 'option' ] ); |
|
1107 | 1107 | $page_set = false; |
1108 | 1108 | $page_exists = false; |
1109 | 1109 | $page_visible = false; |
@@ -1122,22 +1122,22 @@ discard block |
||
1122 | 1122 | } |
1123 | 1123 | |
1124 | 1124 | // Shortcode checks. |
1125 | - if ( $values['shortcode'] && get_post( $page_id ) ) { |
|
1125 | + if ( $values[ 'shortcode' ] && get_post( $page_id ) ) { |
|
1126 | 1126 | $shortcode_required = true; |
1127 | 1127 | $page = get_post( $page_id ); |
1128 | - if ( strstr( $page->post_content, $values['shortcode'] ) ) { |
|
1128 | + if ( strstr( $page->post_content, $values[ 'shortcode' ] ) ) { |
|
1129 | 1129 | $shortcode_present = true; |
1130 | 1130 | } |
1131 | 1131 | } |
1132 | 1132 | |
1133 | 1133 | // Wrap up our findings into an output array. |
1134 | - $pages_output[] = array( |
|
1134 | + $pages_output[ ] = array( |
|
1135 | 1135 | 'page_name' => $page_name, |
1136 | 1136 | 'page_id' => $page_id, |
1137 | 1137 | 'page_set' => $page_set, |
1138 | 1138 | 'page_exists' => $page_exists, |
1139 | 1139 | 'page_visible' => $page_visible, |
1140 | - 'shortcode' => $values['shortcode'], |
|
1140 | + 'shortcode' => $values[ 'shortcode' ], |
|
1141 | 1141 | 'shortcode_required' => $shortcode_required, |
1142 | 1142 | 'shortcode_present' => $shortcode_present, |
1143 | 1143 | ); |
@@ -105,13 +105,13 @@ discard block |
||
105 | 105 | * @return \WP_REST_Response|\WP_Error |
106 | 106 | */ |
107 | 107 | public function get_item( $request ) { |
108 | - $zone = $this->get_zone( $request['zone_id'] ); |
|
108 | + $zone = $this->get_zone( $request[ 'zone_id' ] ); |
|
109 | 109 | |
110 | 110 | if ( is_wp_error( $zone ) ) { |
111 | 111 | return $zone; |
112 | 112 | } |
113 | 113 | |
114 | - $instance_id = (int) $request['instance_id']; |
|
114 | + $instance_id = (int) $request[ 'instance_id' ]; |
|
115 | 115 | $methods = $zone->get_shipping_methods(); |
116 | 116 | $method = false; |
117 | 117 | |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | * @return \WP_REST_Response|\WP_Error |
139 | 139 | */ |
140 | 140 | public function get_items( $request ) { |
141 | - $zone = $this->get_zone( $request['zone_id'] ); |
|
141 | + $zone = $this->get_zone( $request[ 'zone_id' ] ); |
|
142 | 142 | |
143 | 143 | if ( is_wp_error( $zone ) ) { |
144 | 144 | return $zone; |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | |
150 | 150 | foreach ( $methods as $method_obj ) { |
151 | 151 | $method = $this->prepare_item_for_response( $method_obj, $request ); |
152 | - $data[] = $method; |
|
152 | + $data[ ] = $method; |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | return rest_ensure_response( $data ); |
@@ -162,8 +162,8 @@ discard block |
||
162 | 162 | * @return \WP_REST_Request|\WP_Error |
163 | 163 | */ |
164 | 164 | public function create_item( $request ) { |
165 | - $method_id = $request['method_id']; |
|
166 | - $zone = $this->get_zone( $request['zone_id'] ); |
|
165 | + $method_id = $request[ 'method_id' ]; |
|
166 | + $zone = $this->get_zone( $request[ 'zone_id' ] ); |
|
167 | 167 | if ( is_wp_error( $zone ) ) { |
168 | 168 | return $zone; |
169 | 169 | } |
@@ -198,13 +198,13 @@ discard block |
||
198 | 198 | * @return \WP_Error|boolean |
199 | 199 | */ |
200 | 200 | public function delete_item( $request ) { |
201 | - $zone = $this->get_zone( $request['zone_id'] ); |
|
201 | + $zone = $this->get_zone( $request[ 'zone_id' ] ); |
|
202 | 202 | if ( is_wp_error( $zone ) ) { |
203 | 203 | return $zone; |
204 | 204 | } |
205 | 205 | |
206 | - $instance_id = (int) $request['instance_id']; |
|
207 | - $force = $request['force']; |
|
206 | + $instance_id = (int) $request[ 'instance_id' ]; |
|
207 | + $force = $request[ 'force' ]; |
|
208 | 208 | |
209 | 209 | // We don't support trashing for this type, error out. |
210 | 210 | if ( ! $force ) { |
@@ -262,12 +262,12 @@ discard block |
||
262 | 262 | * @return \WP_REST_Response|\WP_Error |
263 | 263 | */ |
264 | 264 | public function update_item( $request ) { |
265 | - $zone = $this->get_zone( $request['zone_id'] ); |
|
265 | + $zone = $this->get_zone( $request[ 'zone_id' ] ); |
|
266 | 266 | if ( is_wp_error( $zone ) ) { |
267 | 267 | return $zone; |
268 | 268 | } |
269 | 269 | |
270 | - $instance_id = (int) $request['instance_id']; |
|
270 | + $instance_id = (int) $request[ 'instance_id' ]; |
|
271 | 271 | $methods = $zone->get_shipping_methods(); |
272 | 272 | $method = false; |
273 | 273 | |
@@ -304,16 +304,16 @@ discard block |
||
304 | 304 | global $wpdb; |
305 | 305 | |
306 | 306 | // Update settings if present. |
307 | - if ( isset( $request['settings'] ) ) { |
|
307 | + if ( isset( $request[ 'settings' ] ) ) { |
|
308 | 308 | $method->init_instance_settings(); |
309 | 309 | $instance_settings = $method->instance_settings; |
310 | 310 | $errors_found = false; |
311 | 311 | foreach ( $method->get_instance_form_fields() as $key => $field ) { |
312 | - if ( isset( $request['settings'][ $key ] ) ) { |
|
313 | - if ( is_callable( array( $this, 'validate_setting_' . $field['type'] . '_field' ) ) ) { |
|
314 | - $value = $this->{'validate_setting_' . $field['type'] . '_field'}( $request['settings'][ $key ], $field ); |
|
312 | + if ( isset( $request[ 'settings' ][ $key ] ) ) { |
|
313 | + if ( is_callable( array( $this, 'validate_setting_' . $field[ 'type' ] . '_field' ) ) ) { |
|
314 | + $value = $this->{'validate_setting_' . $field[ 'type' ] . '_field'}( $request[ 'settings' ][ $key ], $field ); |
|
315 | 315 | } else { |
316 | - $value = $this->validate_setting_text_field( $request['settings'][ $key ], $field ); |
|
316 | + $value = $this->validate_setting_text_field( $request[ 'settings' ][ $key ], $field ); |
|
317 | 317 | } |
318 | 318 | if ( is_wp_error( $value ) ) { |
319 | 319 | $errors_found = true; |
@@ -331,16 +331,16 @@ discard block |
||
331 | 331 | } |
332 | 332 | |
333 | 333 | // Update order. |
334 | - if ( isset( $request['order'] ) ) { |
|
335 | - $wpdb->update( "{$wpdb->prefix}woocommerce_shipping_zone_methods", array( 'method_order' => absint( $request['order'] ) ), array( 'instance_id' => absint( $instance_id ) ) ); |
|
336 | - $method->method_order = absint( $request['order'] ); |
|
334 | + if ( isset( $request[ 'order' ] ) ) { |
|
335 | + $wpdb->update( "{$wpdb->prefix}woocommerce_shipping_zone_methods", array( 'method_order' => absint( $request[ 'order' ] ) ), array( 'instance_id' => absint( $instance_id ) ) ); |
|
336 | + $method->method_order = absint( $request[ 'order' ] ); |
|
337 | 337 | } |
338 | 338 | |
339 | 339 | // Update if this method is enabled or not. |
340 | - if ( isset( $request['enabled'] ) ) { |
|
341 | - if ( $wpdb->update( "{$wpdb->prefix}woocommerce_shipping_zone_methods", array( 'is_enabled' => $request['enabled'] ), array( 'instance_id' => absint( $instance_id ) ) ) ) { |
|
342 | - do_action( 'woocommerce_shipping_zone_method_status_toggled', $instance_id, $method->id, $request['zone_id'], $request['enabled'] ); |
|
343 | - $method->enabled = ( true === $request['enabled'] ? 'yes' : 'no' ); |
|
340 | + if ( isset( $request[ 'enabled' ] ) ) { |
|
341 | + if ( $wpdb->update( "{$wpdb->prefix}woocommerce_shipping_zone_methods", array( 'is_enabled' => $request[ 'enabled' ] ), array( 'instance_id' => absint( $instance_id ) ) ) ) { |
|
342 | + do_action( 'woocommerce_shipping_zone_method_status_toggled', $instance_id, $method->id, $request[ 'zone_id' ], $request[ 'enabled' ] ); |
|
343 | + $method->enabled = ( true === $request[ 'enabled' ] ? 'yes' : 'no' ); |
|
344 | 344 | } |
345 | 345 | } |
346 | 346 | |
@@ -358,7 +358,7 @@ discard block |
||
358 | 358 | $method = array( |
359 | 359 | 'id' => $item->instance_id, |
360 | 360 | 'instance_id' => $item->instance_id, |
361 | - 'title' => $item->instance_settings['title'], |
|
361 | + 'title' => $item->instance_settings[ 'title' ], |
|
362 | 362 | 'order' => $item->method_order, |
363 | 363 | 'enabled' => ( 'yes' === $item->enabled ), |
364 | 364 | 'method_id' => $item->id, |
@@ -367,14 +367,14 @@ discard block |
||
367 | 367 | 'settings' => $this->get_settings( $item ), |
368 | 368 | ); |
369 | 369 | |
370 | - $context = empty( $request['context'] ) ? 'view' : $request['context']; |
|
370 | + $context = empty( $request[ 'context' ] ) ? 'view' : $request[ 'context' ]; |
|
371 | 371 | $data = $this->add_additional_fields_to_object( $method, $request ); |
372 | 372 | $data = $this->filter_response_by_context( $data, $context ); |
373 | 373 | |
374 | 374 | // Wrap the data in a response object. |
375 | 375 | $response = rest_ensure_response( $data ); |
376 | 376 | |
377 | - $response->add_links( $this->prepare_links( $request['zone_id'], $item->instance_id ) ); |
|
377 | + $response->add_links( $this->prepare_links( $request[ 'zone_id' ], $item->instance_id ) ); |
|
378 | 378 | |
379 | 379 | $response = $this->prepare_response_for_collection( $response ); |
380 | 380 | |
@@ -394,16 +394,16 @@ discard block |
||
394 | 394 | foreach ( $item->get_instance_form_fields() as $id => $field ) { |
395 | 395 | $data = array( |
396 | 396 | 'id' => $id, |
397 | - 'label' => $field['title'], |
|
398 | - 'description' => empty( $field['description'] ) ? '' : $field['description'], |
|
399 | - 'type' => $field['type'], |
|
397 | + 'label' => $field[ 'title' ], |
|
398 | + 'description' => empty( $field[ 'description' ] ) ? '' : $field[ 'description' ], |
|
399 | + 'type' => $field[ 'type' ], |
|
400 | 400 | 'value' => $item->instance_settings[ $id ], |
401 | - 'default' => empty( $field['default'] ) ? '' : $field['default'], |
|
402 | - 'tip' => empty( $field['description'] ) ? '' : $field['description'], |
|
403 | - 'placeholder' => empty( $field['placeholder'] ) ? '' : $field['placeholder'], |
|
401 | + 'default' => empty( $field[ 'default' ] ) ? '' : $field[ 'default' ], |
|
402 | + 'tip' => empty( $field[ 'description' ] ) ? '' : $field[ 'description' ], |
|
403 | + 'placeholder' => empty( $field[ 'placeholder' ] ) ? '' : $field[ 'placeholder' ], |
|
404 | 404 | ); |
405 | - if ( ! empty( $field['options'] ) ) { |
|
406 | - $data['options'] = $field['options']; |
|
405 | + if ( ! empty( $field[ 'options' ] ) ) { |
|
406 | + $data[ 'options' ] = $field[ 'options' ]; |
|
407 | 407 | } |
408 | 408 | $settings[ $id ] = $data; |
409 | 409 | } |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | 'count' => (int) $item->count, |
151 | 151 | ); |
152 | 152 | |
153 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
153 | + $context = ! empty( $request[ 'context' ] ) ? $request[ 'context' ] : 'view'; |
|
154 | 154 | $data = $this->add_additional_fields_to_object( $data, $request ); |
155 | 155 | $data = $this->filter_response_by_context( $data, $context ); |
156 | 156 | |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | protected function update_term_meta_fields( $term, $request ) { |
181 | 181 | $id = (int) $term->term_id; |
182 | 182 | |
183 | - update_term_meta( $id, 'order_' . $this->taxonomy, $request['menu_order'] ); |
|
183 | + update_term_meta( $id, 'order_' . $this->taxonomy, $request[ 'menu_order' ] ); |
|
184 | 184 | |
185 | 185 | return true; |
186 | 186 | } |
@@ -203,21 +203,21 @@ discard block |
||
203 | 203 | global $wpdb; |
204 | 204 | |
205 | 205 | $prepared_args = array(); |
206 | - $prepared_args['order'] = $request['order']; |
|
207 | - $prepared_args['number'] = $request['per_page']; |
|
208 | - if ( ! empty( $request['offset'] ) ) { |
|
209 | - $prepared_args['offset'] = $request['offset']; |
|
206 | + $prepared_args[ 'order' ] = $request[ 'order' ]; |
|
207 | + $prepared_args[ 'number' ] = $request[ 'per_page' ]; |
|
208 | + if ( ! empty( $request[ 'offset' ] ) ) { |
|
209 | + $prepared_args[ 'offset' ] = $request[ 'offset' ]; |
|
210 | 210 | } else { |
211 | - $prepared_args['offset'] = ( $request['page'] - 1 ) * $prepared_args['number']; |
|
211 | + $prepared_args[ 'offset' ] = ( $request[ 'page' ] - 1 ) * $prepared_args[ 'number' ]; |
|
212 | 212 | } |
213 | 213 | $orderby_possibles = array( |
214 | 214 | 'id' => 'tax_rate_id', |
215 | 215 | 'order' => 'tax_rate_order', |
216 | 216 | ); |
217 | - $prepared_args['orderby'] = $orderby_possibles[ $request['orderby'] ]; |
|
218 | - $prepared_args['class'] = $request['class']; |
|
219 | - $prepared_args['code'] = $request['code']; |
|
220 | - $prepared_args['include'] = $request['include']; |
|
217 | + $prepared_args[ 'orderby' ] = $orderby_possibles[ $request[ 'orderby' ] ]; |
|
218 | + $prepared_args[ 'class' ] = $request[ 'class' ]; |
|
219 | + $prepared_args[ 'code' ] = $request[ 'code' ]; |
|
220 | + $prepared_args[ 'include' ] = $request[ 'include' ]; |
|
221 | 221 | |
222 | 222 | /** |
223 | 223 | * Filter arguments, before passing to $wpdb->get_results(), when querying taxes via the REST API. |
@@ -234,13 +234,13 @@ discard block |
||
234 | 234 | "; |
235 | 235 | |
236 | 236 | // Filter by tax class. |
237 | - if ( ! empty( $prepared_args['class'] ) ) { |
|
238 | - $class = 'standard' !== $prepared_args['class'] ? sanitize_title( $prepared_args['class'] ) : ''; |
|
237 | + if ( ! empty( $prepared_args[ 'class' ] ) ) { |
|
238 | + $class = 'standard' !== $prepared_args[ 'class' ] ? sanitize_title( $prepared_args[ 'class' ] ) : ''; |
|
239 | 239 | $query .= " AND tax_rate_class = '$class'"; |
240 | 240 | } |
241 | 241 | |
242 | 242 | // Filter by tax code. |
243 | - $tax_code_search = $prepared_args['code']; |
|
243 | + $tax_code_search = $prepared_args[ 'code' ]; |
|
244 | 244 | if ( $tax_code_search ) { |
245 | 245 | $tax_code_search = $wpdb->esc_like( $tax_code_search ); |
246 | 246 | $tax_code_search = ' \'%' . $tax_code_search . '%\''; |
@@ -248,17 +248,17 @@ discard block |
||
248 | 248 | } |
249 | 249 | |
250 | 250 | // Filter by included tax rate IDs. |
251 | - $included_taxes = $prepared_args['include']; |
|
251 | + $included_taxes = $prepared_args[ 'include' ]; |
|
252 | 252 | if ( ! empty( $included_taxes ) ) { |
253 | - $included_taxes = implode( ',', $prepared_args['include'] ); |
|
253 | + $included_taxes = implode( ',', $prepared_args[ 'include' ] ); |
|
254 | 254 | $query .= " AND tax_rate_id IN ({$included_taxes})"; |
255 | 255 | } |
256 | 256 | |
257 | 257 | // Order tax rates. |
258 | - $order_by = sprintf( ' ORDER BY %s', sanitize_key( $prepared_args['orderby'] ) ); |
|
258 | + $order_by = sprintf( ' ORDER BY %s', sanitize_key( $prepared_args[ 'orderby' ] ) ); |
|
259 | 259 | |
260 | 260 | // Pagination. |
261 | - $pagination = sprintf( ' LIMIT %d, %d', $prepared_args['offset'], $prepared_args['number'] ); |
|
261 | + $pagination = sprintf( ' LIMIT %d, %d', $prepared_args[ 'offset' ], $prepared_args[ 'number' ] ); |
|
262 | 262 | |
263 | 263 | // Query taxes. |
264 | 264 | $results = $wpdb->get_results( $query . $order_by . $pagination ); // @codingStandardsIgnoreLine. |
@@ -266,14 +266,14 @@ discard block |
||
266 | 266 | $taxes = array(); |
267 | 267 | foreach ( $results as $tax ) { |
268 | 268 | $data = $this->prepare_item_for_response( $tax, $request ); |
269 | - $taxes[] = $this->prepare_response_for_collection( $data ); |
|
269 | + $taxes[ ] = $this->prepare_response_for_collection( $data ); |
|
270 | 270 | } |
271 | 271 | |
272 | 272 | $response = rest_ensure_response( $taxes ); |
273 | 273 | |
274 | 274 | // Store pagination values for headers then unset for count query. |
275 | - $per_page = (int) $prepared_args['number']; |
|
276 | - $page = ceil( ( ( (int) $prepared_args['offset'] ) / $per_page ) + 1 ); |
|
275 | + $per_page = (int) $prepared_args[ 'number' ]; |
|
276 | + $page = ceil( ( ( (int) $prepared_args[ 'offset' ] ) / $per_page ) + 1 ); |
|
277 | 277 | |
278 | 278 | // Query only for ids. |
279 | 279 | $wpdb->get_results( str_replace( 'SELECT *', 'SELECT tax_rate_id', $query ) ); // @codingStandardsIgnoreLine. |
@@ -310,7 +310,7 @@ discard block |
||
310 | 310 | * @return object |
311 | 311 | */ |
312 | 312 | protected function create_or_update_tax( $request, $current = null ) { |
313 | - $id = absint( isset( $request['id'] ) ? $request['id'] : 0 ); |
|
313 | + $id = absint( isset( $request[ 'id' ] ) ? $request[ 'id' ] : 0 ); |
|
314 | 314 | $data = array(); |
315 | 315 | $fields = array( |
316 | 316 | 'tax_rate_country', |
@@ -347,7 +347,7 @@ discard block |
||
347 | 347 | $data[ $field ] = absint( $request[ $key ] ); |
348 | 348 | break; |
349 | 349 | case 'tax_rate_class': |
350 | - $data[ $field ] = 'standard' !== $request['tax_rate_class'] ? $request['tax_rate_class'] : ''; |
|
350 | + $data[ $field ] = 'standard' !== $request[ 'tax_rate_class' ] ? $request[ 'tax_rate_class' ] : ''; |
|
351 | 351 | break; |
352 | 352 | default: |
353 | 353 | $data[ $field ] = wc_clean( $request[ $key ] ); |
@@ -362,11 +362,11 @@ discard block |
||
362 | 362 | } |
363 | 363 | |
364 | 364 | // Add locales. |
365 | - if ( ! empty( $request['postcode'] ) ) { |
|
366 | - \WC_Tax::_update_tax_rate_postcodes( $id, wc_clean( $request['postcode'] ) ); |
|
365 | + if ( ! empty( $request[ 'postcode' ] ) ) { |
|
366 | + \WC_Tax::_update_tax_rate_postcodes( $id, wc_clean( $request[ 'postcode' ] ) ); |
|
367 | 367 | } |
368 | - if ( ! empty( $request['city'] ) ) { |
|
369 | - \WC_Tax::_update_tax_rate_cities( $id, wc_clean( $request['city'] ) ); |
|
368 | + if ( ! empty( $request[ 'city' ] ) ) { |
|
369 | + \WC_Tax::_update_tax_rate_cities( $id, wc_clean( $request[ 'city' ] ) ); |
|
370 | 370 | } |
371 | 371 | |
372 | 372 | return \WC_Tax::_get_tax_rate( $id, OBJECT ); |
@@ -379,7 +379,7 @@ discard block |
||
379 | 379 | * @return \WP_Error\WP_REST_Response |
380 | 380 | */ |
381 | 381 | public function create_item( $request ) { |
382 | - if ( ! empty( $request['id'] ) ) { |
|
382 | + if ( ! empty( $request[ 'id' ] ) ) { |
|
383 | 383 | return new \WP_Error( 'woocommerce_rest_tax_exists', __( 'Cannot create existing resource.', 'woocommerce' ), array( 'status' => 400 ) ); |
384 | 384 | } |
385 | 385 | |
@@ -412,7 +412,7 @@ discard block |
||
412 | 412 | * @return \WP_Error\WP_REST_Response |
413 | 413 | */ |
414 | 414 | public function get_item( $request ) { |
415 | - $id = (int) $request['id']; |
|
415 | + $id = (int) $request[ 'id' ]; |
|
416 | 416 | $tax_obj = \WC_Tax::_get_tax_rate( $id, OBJECT ); |
417 | 417 | |
418 | 418 | if ( empty( $id ) || empty( $tax_obj ) ) { |
@@ -432,7 +432,7 @@ discard block |
||
432 | 432 | * @return \WP_Error\WP_REST_Response |
433 | 433 | */ |
434 | 434 | public function update_item( $request ) { |
435 | - $id = (int) $request['id']; |
|
435 | + $id = (int) $request[ 'id' ]; |
|
436 | 436 | $tax_obj = \WC_Tax::_get_tax_rate( $id, OBJECT ); |
437 | 437 | |
438 | 438 | if ( empty( $id ) || empty( $tax_obj ) ) { |
@@ -468,8 +468,8 @@ discard block |
||
468 | 468 | public function delete_item( $request ) { |
469 | 469 | global $wpdb; |
470 | 470 | |
471 | - $id = (int) $request['id']; |
|
472 | - $force = isset( $request['force'] ) ? (bool) $request['force'] : false; |
|
471 | + $id = (int) $request[ 'id' ]; |
|
472 | + $force = isset( $request[ 'force' ] ) ? (bool) $request[ 'force' ] : false; |
|
473 | 473 | |
474 | 474 | // We don't support trashing for this type, error out. |
475 | 475 | if ( ! $force ) { |
@@ -547,7 +547,7 @@ discard block |
||
547 | 547 | } |
548 | 548 | } |
549 | 549 | |
550 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
550 | + $context = ! empty( $request[ 'context' ] ) ? $request[ 'context' ] : 'view'; |
|
551 | 551 | $data = $this->add_additional_fields_to_object( $data, $request ); |
552 | 552 | $data = $this->filter_response_by_context( $data, $context ); |
553 | 553 | |
@@ -675,10 +675,10 @@ discard block |
||
675 | 675 | */ |
676 | 676 | public function get_collection_params() { |
677 | 677 | $params = array(); |
678 | - $params['context'] = $this->get_context_param(); |
|
679 | - $params['context']['default'] = 'view'; |
|
678 | + $params[ 'context' ] = $this->get_context_param(); |
|
679 | + $params[ 'context' ][ 'default' ] = 'view'; |
|
680 | 680 | |
681 | - $params['page'] = array( |
|
681 | + $params[ 'page' ] = array( |
|
682 | 682 | 'description' => __( 'Current page of the collection.', 'woocommerce' ), |
683 | 683 | 'type' => 'integer', |
684 | 684 | 'default' => 1, |
@@ -686,7 +686,7 @@ discard block |
||
686 | 686 | 'validate_callback' => 'rest_validate_request_arg', |
687 | 687 | 'minimum' => 1, |
688 | 688 | ); |
689 | - $params['per_page'] = array( |
|
689 | + $params[ 'per_page' ] = array( |
|
690 | 690 | 'description' => __( 'Maximum number of items to be returned in result set.', 'woocommerce' ), |
691 | 691 | 'type' => 'integer', |
692 | 692 | 'default' => 10, |
@@ -695,13 +695,13 @@ discard block |
||
695 | 695 | 'sanitize_callback' => 'absint', |
696 | 696 | 'validate_callback' => 'rest_validate_request_arg', |
697 | 697 | ); |
698 | - $params['offset'] = array( |
|
698 | + $params[ 'offset' ] = array( |
|
699 | 699 | 'description' => __( 'Offset the result set by a specific number of items.', 'woocommerce' ), |
700 | 700 | 'type' => 'integer', |
701 | 701 | 'sanitize_callback' => 'absint', |
702 | 702 | 'validate_callback' => 'rest_validate_request_arg', |
703 | 703 | ); |
704 | - $params['order'] = array( |
|
704 | + $params[ 'order' ] = array( |
|
705 | 705 | 'default' => 'asc', |
706 | 706 | 'description' => __( 'Order sort attribute ascending or descending.', 'woocommerce' ), |
707 | 707 | 'enum' => array( 'asc', 'desc' ), |
@@ -709,7 +709,7 @@ discard block |
||
709 | 709 | 'type' => 'string', |
710 | 710 | 'validate_callback' => 'rest_validate_request_arg', |
711 | 711 | ); |
712 | - $params['orderby'] = array( |
|
712 | + $params[ 'orderby' ] = array( |
|
713 | 713 | 'default' => 'order', |
714 | 714 | 'description' => __( 'Sort collection by object attribute.', 'woocommerce' ), |
715 | 715 | 'enum' => array( |
@@ -720,19 +720,19 @@ discard block |
||
720 | 720 | 'type' => 'string', |
721 | 721 | 'validate_callback' => 'rest_validate_request_arg', |
722 | 722 | ); |
723 | - $params['class'] = array( |
|
723 | + $params[ 'class' ] = array( |
|
724 | 724 | 'description' => __( 'Sort by tax class.', 'woocommerce' ), |
725 | 725 | 'enum' => array_merge( array( 'standard' ), \WC_Tax::get_tax_class_slugs() ), |
726 | 726 | 'sanitize_callback' => 'sanitize_title', |
727 | 727 | 'type' => 'string', |
728 | 728 | 'validate_callback' => 'rest_validate_request_arg', |
729 | 729 | ); |
730 | - $params['code'] = array( |
|
730 | + $params[ 'code' ] = array( |
|
731 | 731 | 'description' => __( 'Search by similar tax code.', 'woocommerce' ), |
732 | 732 | 'type' => 'string', |
733 | 733 | 'validate_callback' => 'rest_validate_request_arg', |
734 | 734 | ); |
735 | - $params['include'] = array( |
|
735 | + $params[ 'include' ] = array( |
|
736 | 736 | 'description' => __( 'Limit result set to items that have the specified rate ID(s) assigned.', 'woocommerce' ), |
737 | 737 | 'type' => 'array', |
738 | 738 | 'items' => array( |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | * @return \WP_Error\WP_REST_Response |
110 | 110 | */ |
111 | 111 | public function get_item( $request ) { |
112 | - $setting = $this->get_setting( $request['group_id'], $request['id'] ); |
|
112 | + $setting = $this->get_setting( $request[ 'group_id' ], $request[ 'id' ] ); |
|
113 | 113 | |
114 | 114 | if ( is_wp_error( $setting ) ) { |
115 | 115 | return $setting; |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | * @return \WP_Error\WP_REST_Response |
129 | 129 | */ |
130 | 130 | public function get_items( $request ) { |
131 | - $settings = $this->get_group_settings( $request['group_id'] ); |
|
131 | + $settings = $this->get_group_settings( $request[ 'group_id' ] ); |
|
132 | 132 | |
133 | 133 | if ( is_wp_error( $settings ) ) { |
134 | 134 | return $settings; |
@@ -139,8 +139,8 @@ discard block |
||
139 | 139 | foreach ( $settings as $setting_obj ) { |
140 | 140 | $setting = $this->prepare_item_for_response( $setting_obj, $request ); |
141 | 141 | $setting = $this->prepare_response_for_collection( $setting ); |
142 | - if ( $this->is_setting_type_valid( $setting['type'] ) ) { |
|
143 | - $data[] = $setting; |
|
142 | + if ( $this->is_setting_type_valid( $setting[ 'type' ] ) ) { |
|
143 | + $data[ ] = $setting; |
|
144 | 144 | } |
145 | 145 | } |
146 | 146 | |
@@ -166,26 +166,26 @@ discard block |
||
166 | 166 | |
167 | 167 | $filtered_settings = array(); |
168 | 168 | foreach ( $settings as $setting ) { |
169 | - $option_key = $setting['option_key']; |
|
169 | + $option_key = $setting[ 'option_key' ]; |
|
170 | 170 | $setting = $this->filter_setting( $setting ); |
171 | - $default = isset( $setting['default'] ) ? $setting['default'] : ''; |
|
171 | + $default = isset( $setting[ 'default' ] ) ? $setting[ 'default' ] : ''; |
|
172 | 172 | // Get the option value. |
173 | 173 | if ( is_array( $option_key ) ) { |
174 | - $option = get_option( $option_key[0] ); |
|
175 | - $setting['value'] = isset( $option[ $option_key[1] ] ) ? $option[ $option_key[1] ] : $default; |
|
174 | + $option = get_option( $option_key[ 0 ] ); |
|
175 | + $setting[ 'value' ] = isset( $option[ $option_key[ 1 ] ] ) ? $option[ $option_key[ 1 ] ] : $default; |
|
176 | 176 | } else { |
177 | 177 | $admin_setting_value = \WC_Admin_Settings::get_option( $option_key, $default ); |
178 | - $setting['value'] = $admin_setting_value; |
|
178 | + $setting[ 'value' ] = $admin_setting_value; |
|
179 | 179 | } |
180 | 180 | |
181 | - if ( 'multi_select_countries' === $setting['type'] ) { |
|
182 | - $setting['options'] = WC()->countries->get_countries(); |
|
183 | - $setting['type'] = 'multiselect'; |
|
184 | - } elseif ( 'single_select_country' === $setting['type'] ) { |
|
185 | - $setting['type'] = 'select'; |
|
186 | - $setting['options'] = $this->get_countries_and_states(); |
|
187 | - } elseif ( 'single_select_page' === $setting['type'] ) { |
|
188 | - $pages = get_pages( |
|
181 | + if ( 'multi_select_countries' === $setting[ 'type' ] ) { |
|
182 | + $setting[ 'options' ] = WC()->countries->get_countries(); |
|
183 | + $setting[ 'type' ] = 'multiselect'; |
|
184 | + } elseif ( 'single_select_country' === $setting[ 'type' ] ) { |
|
185 | + $setting[ 'type' ] = 'select'; |
|
186 | + $setting[ 'options' ] = $this->get_countries_and_states(); |
|
187 | + } elseif ( 'single_select_page' === $setting[ 'type' ] ) { |
|
188 | + $pages = get_pages( |
|
189 | 189 | array( |
190 | 190 | 'sort_column' => 'menu_order', |
191 | 191 | 'sort_order' => 'ASC', |
@@ -196,11 +196,11 @@ discard block |
||
196 | 196 | foreach ( $pages as $page ) { |
197 | 197 | $options[ $page->ID ] = ! empty( $page->post_title ) ? $page->post_title : '#' . $page->ID; |
198 | 198 | } |
199 | - $setting['type'] = 'select'; |
|
200 | - $setting['options'] = $options; |
|
199 | + $setting[ 'type' ] = 'select'; |
|
200 | + $setting[ 'options' ] = $options; |
|
201 | 201 | } |
202 | 202 | |
203 | - $filtered_settings[] = $setting; |
|
203 | + $filtered_settings[ ] = $setting; |
|
204 | 204 | } |
205 | 205 | |
206 | 206 | return $filtered_settings; |
@@ -257,9 +257,9 @@ discard block |
||
257 | 257 | return new \WP_Error( 'rest_setting_setting_invalid', __( 'Invalid setting.', 'woocommerce' ), array( 'status' => 404 ) ); |
258 | 258 | } |
259 | 259 | |
260 | - $setting = $settings[ $array_key[0] ]; |
|
260 | + $setting = $settings[ $array_key[ 0 ] ]; |
|
261 | 261 | |
262 | - if ( ! $this->is_setting_type_valid( $setting['type'] ) ) { |
|
262 | + if ( ! $this->is_setting_type_valid( $setting[ 'type' ] ) ) { |
|
263 | 263 | return new \WP_Error( 'rest_setting_setting_invalid', __( 'Invalid setting.', 'woocommerce' ), array( 'status' => 404 ) ); |
264 | 264 | } |
265 | 265 | |
@@ -267,7 +267,7 @@ discard block |
||
267 | 267 | return $setting; |
268 | 268 | } |
269 | 269 | |
270 | - $setting['group_id'] = $group_id; |
|
270 | + $setting[ 'group_id' ] = $group_id; |
|
271 | 271 | |
272 | 272 | return $setting; |
273 | 273 | } |
@@ -287,10 +287,10 @@ discard block |
||
287 | 287 | * Since our batch settings update is group-specific and matches based on the route, |
288 | 288 | * we inject the URL parameters (containing group) into the batch items |
289 | 289 | */ |
290 | - if ( ! empty( $items['update'] ) ) { |
|
290 | + if ( ! empty( $items[ 'update' ] ) ) { |
|
291 | 291 | $to_update = array(); |
292 | - foreach ( $items['update'] as $item ) { |
|
293 | - $to_update[] = array_merge( $request->get_url_params(), $item ); |
|
292 | + foreach ( $items[ 'update' ] as $item ) { |
|
293 | + $to_update[ ] = array_merge( $request->get_url_params(), $item ); |
|
294 | 294 | } |
295 | 295 | $request = new \WP_REST_Request( $request->get_method() ); |
296 | 296 | $request->set_body_params( array( 'update' => $to_update ) ); |
@@ -307,32 +307,32 @@ discard block |
||
307 | 307 | * @return \WP_Error\WP_REST_Response |
308 | 308 | */ |
309 | 309 | public function update_item( $request ) { |
310 | - $setting = $this->get_setting( $request['group_id'], $request['id'] ); |
|
310 | + $setting = $this->get_setting( $request[ 'group_id' ], $request[ 'id' ] ); |
|
311 | 311 | |
312 | 312 | if ( is_wp_error( $setting ) ) { |
313 | 313 | return $setting; |
314 | 314 | } |
315 | 315 | |
316 | - if ( is_callable( array( $this, 'validate_setting_' . $setting['type'] . '_field' ) ) ) { |
|
317 | - $value = $this->{'validate_setting_' . $setting['type'] . '_field'}( $request['value'], $setting ); |
|
316 | + if ( is_callable( array( $this, 'validate_setting_' . $setting[ 'type' ] . '_field' ) ) ) { |
|
317 | + $value = $this->{'validate_setting_' . $setting[ 'type' ] . '_field'}( $request[ 'value' ], $setting ); |
|
318 | 318 | } else { |
319 | - $value = $this->validate_setting_text_field( $request['value'], $setting ); |
|
319 | + $value = $this->validate_setting_text_field( $request[ 'value' ], $setting ); |
|
320 | 320 | } |
321 | 321 | |
322 | 322 | if ( is_wp_error( $value ) ) { |
323 | 323 | return $value; |
324 | 324 | } |
325 | 325 | |
326 | - if ( is_array( $setting['option_key'] ) ) { |
|
327 | - $setting['value'] = $value; |
|
328 | - $option_key = $setting['option_key']; |
|
329 | - $prev = get_option( $option_key[0] ); |
|
330 | - $prev[ $option_key[1] ] = $request['value']; |
|
331 | - update_option( $option_key[0], $prev ); |
|
326 | + if ( is_array( $setting[ 'option_key' ] ) ) { |
|
327 | + $setting[ 'value' ] = $value; |
|
328 | + $option_key = $setting[ 'option_key' ]; |
|
329 | + $prev = get_option( $option_key[ 0 ] ); |
|
330 | + $prev[ $option_key[ 1 ] ] = $request[ 'value' ]; |
|
331 | + update_option( $option_key[ 0 ], $prev ); |
|
332 | 332 | } else { |
333 | 333 | $update_data = array(); |
334 | - $update_data[ $setting['option_key'] ] = $value; |
|
335 | - $setting['value'] = $value; |
|
334 | + $update_data[ $setting[ 'option_key' ] ] = $value; |
|
335 | + $setting[ 'value' ] = $value; |
|
336 | 336 | \WC_Admin_Settings::save_fields( array( $setting ), $update_data ); |
337 | 337 | } |
338 | 338 | |
@@ -350,12 +350,12 @@ discard block |
||
350 | 350 | * @return \WP_REST_Response $response Response data. |
351 | 351 | */ |
352 | 352 | public function prepare_item_for_response( $item, $request ) { |
353 | - unset( $item['option_key'] ); |
|
353 | + unset( $item[ 'option_key' ] ); |
|
354 | 354 | $data = $this->filter_setting( $item ); |
355 | 355 | $data = $this->add_additional_fields_to_object( $data, $request ); |
356 | - $data = $this->filter_response_by_context( $data, empty( $request['context'] ) ? 'view' : $request['context'] ); |
|
356 | + $data = $this->filter_response_by_context( $data, empty( $request[ 'context' ] ) ? 'view' : $request[ 'context' ] ); |
|
357 | 357 | $response = rest_ensure_response( $data ); |
358 | - $response->add_links( $this->prepare_links( $data['id'], $request['group_id'] ) ); |
|
358 | + $response->add_links( $this->prepare_links( $data[ 'id' ], $request[ 'group_id' ] ) ); |
|
359 | 359 | return $response; |
360 | 360 | } |
361 | 361 | |
@@ -425,11 +425,11 @@ discard block |
||
425 | 425 | array_flip( array_filter( array_keys( $setting ), array( $this, 'allowed_setting_keys' ) ) ) |
426 | 426 | ); |
427 | 427 | |
428 | - if ( empty( $setting['options'] ) ) { |
|
429 | - unset( $setting['options'] ); |
|
428 | + if ( empty( $setting[ 'options' ] ) ) { |
|
429 | + unset( $setting[ 'options' ] ); |
|
430 | 430 | } |
431 | 431 | |
432 | - if ( 'image_width' === $setting['type'] ) { |
|
432 | + if ( 'image_width' === $setting[ 'type' ] ) { |
|
433 | 433 | $setting = $this->cast_image_width( $setting ); |
434 | 434 | } |
435 | 435 | |
@@ -448,9 +448,9 @@ discard block |
||
448 | 448 | public function cast_image_width( $setting ) { |
449 | 449 | foreach ( array( 'default', 'value' ) as $key ) { |
450 | 450 | if ( isset( $setting[ $key ] ) ) { |
451 | - $setting[ $key ]['width'] = intval( $setting[ $key ]['width'] ); |
|
452 | - $setting[ $key ]['height'] = intval( $setting[ $key ]['height'] ); |
|
453 | - $setting[ $key ]['crop'] = (bool) $setting[ $key ]['crop']; |
|
451 | + $setting[ $key ][ 'width' ] = intval( $setting[ $key ][ 'width' ] ); |
|
452 | + $setting[ $key ][ 'height' ] = intval( $setting[ $key ][ 'height' ] ); |
|
453 | + $setting[ $key ][ 'crop' ] = (bool) $setting[ $key ][ 'crop' ]; |
|
454 | 454 | } |
455 | 455 | } |
456 | 456 | return $setting; |
@@ -490,17 +490,17 @@ discard block |
||
490 | 490 | public function is_setting_type_valid( $type ) { |
491 | 491 | return in_array( |
492 | 492 | $type, array( |
493 | - 'text', // Validates with validate_setting_text_field. |
|
494 | - 'email', // Validates with validate_setting_text_field. |
|
495 | - 'number', // Validates with validate_setting_text_field. |
|
496 | - 'color', // Validates with validate_setting_text_field. |
|
497 | - 'password', // Validates with validate_setting_text_field. |
|
498 | - 'textarea', // Validates with validate_setting_textarea_field. |
|
499 | - 'select', // Validates with validate_setting_select_field. |
|
500 | - 'multiselect', // Validates with validate_setting_multiselect_field. |
|
501 | - 'radio', // Validates with validate_setting_radio_field (-> validate_setting_select_field). |
|
502 | - 'checkbox', // Validates with validate_setting_checkbox_field. |
|
503 | - 'image_width', // Validates with validate_setting_image_width_field. |
|
493 | + 'text', // Validates with validate_setting_text_field. |
|
494 | + 'email', // Validates with validate_setting_text_field. |
|
495 | + 'number', // Validates with validate_setting_text_field. |
|
496 | + 'color', // Validates with validate_setting_text_field. |
|
497 | + 'password', // Validates with validate_setting_text_field. |
|
498 | + 'textarea', // Validates with validate_setting_textarea_field. |
|
499 | + 'select', // Validates with validate_setting_select_field. |
|
500 | + 'multiselect', // Validates with validate_setting_multiselect_field. |
|
501 | + 'radio', // Validates with validate_setting_radio_field (-> validate_setting_select_field). |
|
502 | + 'checkbox', // Validates with validate_setting_checkbox_field. |
|
503 | + 'image_width', // Validates with validate_setting_image_width_field. |
|
504 | 504 | 'thumbnail_cropping', // Validates with validate_setting_text_field. |
505 | 505 | ) |
506 | 506 | ); |