@@ -8,7 +8,7 @@ |
||
8 | 8 | * @since 2.6.0 |
9 | 9 | */ |
10 | 10 | |
11 | -defined( 'ABSPATH' ) || exit; |
|
11 | +defined('ABSPATH') || exit; |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * REST API Product Shipping Classes controller class. |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * @since 3.0.0 |
9 | 9 | */ |
10 | 10 | |
11 | -defined( 'ABSPATH' ) || exit; |
|
11 | +defined('ABSPATH') || exit; |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * System status controller class. |
@@ -42,11 +42,11 @@ discard block |
||
42 | 42 | array( |
43 | 43 | array( |
44 | 44 | 'methods' => WP_REST_Server::READABLE, |
45 | - 'callback' => array( $this, 'get_items' ), |
|
46 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
45 | + 'callback' => array($this, 'get_items'), |
|
46 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
47 | 47 | 'args' => $this->get_collection_params(), |
48 | 48 | ), |
49 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
49 | + 'schema' => array($this, 'get_public_item_schema'), |
|
50 | 50 | ) |
51 | 51 | ); |
52 | 52 | } |
@@ -57,9 +57,9 @@ discard block |
||
57 | 57 | * @param WP_REST_Request $request Full details about the request. |
58 | 58 | * @return WP_Error|boolean |
59 | 59 | */ |
60 | - public function get_items_permissions_check( $request ) { |
|
61 | - if ( ! wc_rest_check_manager_permissions( 'system_status', 'read' ) ) { |
|
62 | - return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
60 | + public function get_items_permissions_check($request) { |
|
61 | + if ( ! wc_rest_check_manager_permissions('system_status', 'read')) { |
|
62 | + return new WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
63 | 63 | } |
64 | 64 | return true; |
65 | 65 | } |
@@ -70,24 +70,24 @@ discard block |
||
70 | 70 | * @param WP_REST_Request $request Full details about the request. |
71 | 71 | * @return WP_Error|WP_REST_Response |
72 | 72 | */ |
73 | - public function get_items( $request ) { |
|
73 | + public function get_items($request) { |
|
74 | 74 | $schema = $this->get_item_schema(); |
75 | 75 | $mappings = $this->get_item_mappings(); |
76 | 76 | $response = array(); |
77 | 77 | |
78 | - foreach ( $mappings as $section => $values ) { |
|
79 | - foreach ( $values as $key => $value ) { |
|
80 | - if ( isset( $schema['properties'][ $section ]['properties'][ $key ]['type'] ) ) { |
|
81 | - settype( $values[ $key ], $schema['properties'][ $section ]['properties'][ $key ]['type'] ); |
|
78 | + foreach ($mappings as $section => $values) { |
|
79 | + foreach ($values as $key => $value) { |
|
80 | + if (isset($schema['properties'][$section]['properties'][$key]['type'])) { |
|
81 | + settype($values[$key], $schema['properties'][$section]['properties'][$key]['type']); |
|
82 | 82 | } |
83 | 83 | } |
84 | - settype( $values, $schema['properties'][ $section ]['type'] ); |
|
85 | - $response[ $section ] = $values; |
|
84 | + settype($values, $schema['properties'][$section]['type']); |
|
85 | + $response[$section] = $values; |
|
86 | 86 | } |
87 | 87 | |
88 | - $response = $this->prepare_item_for_response( $response, $request ); |
|
88 | + $response = $this->prepare_item_for_response($response, $request); |
|
89 | 89 | |
90 | - return rest_ensure_response( $response ); |
|
90 | + return rest_ensure_response($response); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | /** |
@@ -102,229 +102,229 @@ discard block |
||
102 | 102 | 'type' => 'object', |
103 | 103 | 'properties' => array( |
104 | 104 | 'environment' => array( |
105 | - 'description' => __( 'Environment.', 'woocommerce' ), |
|
105 | + 'description' => __('Environment.', 'woocommerce'), |
|
106 | 106 | 'type' => 'object', |
107 | - 'context' => array( 'view' ), |
|
107 | + 'context' => array('view'), |
|
108 | 108 | 'readonly' => true, |
109 | 109 | 'properties' => array( |
110 | 110 | 'home_url' => array( |
111 | - 'description' => __( 'Home URL.', 'woocommerce' ), |
|
111 | + 'description' => __('Home URL.', 'woocommerce'), |
|
112 | 112 | 'type' => 'string', |
113 | 113 | 'format' => 'uri', |
114 | - 'context' => array( 'view' ), |
|
114 | + 'context' => array('view'), |
|
115 | 115 | 'readonly' => true, |
116 | 116 | ), |
117 | 117 | 'site_url' => array( |
118 | - 'description' => __( 'Site URL.', 'woocommerce' ), |
|
118 | + 'description' => __('Site URL.', 'woocommerce'), |
|
119 | 119 | 'type' => 'string', |
120 | 120 | 'format' => 'uri', |
121 | - 'context' => array( 'view' ), |
|
121 | + 'context' => array('view'), |
|
122 | 122 | 'readonly' => true, |
123 | 123 | ), |
124 | 124 | 'wc_version' => array( |
125 | - 'description' => __( 'WooCommerce version.', 'woocommerce' ), |
|
125 | + 'description' => __('WooCommerce version.', 'woocommerce'), |
|
126 | 126 | 'type' => 'string', |
127 | - 'context' => array( 'view' ), |
|
127 | + 'context' => array('view'), |
|
128 | 128 | 'readonly' => true, |
129 | 129 | ), |
130 | 130 | 'log_directory' => array( |
131 | - 'description' => __( 'Log directory.', 'woocommerce' ), |
|
131 | + 'description' => __('Log directory.', 'woocommerce'), |
|
132 | 132 | 'type' => 'string', |
133 | - 'context' => array( 'view' ), |
|
133 | + 'context' => array('view'), |
|
134 | 134 | 'readonly' => true, |
135 | 135 | ), |
136 | 136 | 'log_directory_writable' => array( |
137 | - 'description' => __( 'Is log directory writable?', 'woocommerce' ), |
|
137 | + 'description' => __('Is log directory writable?', 'woocommerce'), |
|
138 | 138 | 'type' => 'boolean', |
139 | - 'context' => array( 'view' ), |
|
139 | + 'context' => array('view'), |
|
140 | 140 | 'readonly' => true, |
141 | 141 | ), |
142 | 142 | 'wp_version' => array( |
143 | - 'description' => __( 'WordPress version.', 'woocommerce' ), |
|
143 | + 'description' => __('WordPress version.', 'woocommerce'), |
|
144 | 144 | 'type' => 'string', |
145 | - 'context' => array( 'view' ), |
|
145 | + 'context' => array('view'), |
|
146 | 146 | 'readonly' => true, |
147 | 147 | ), |
148 | 148 | 'wp_multisite' => array( |
149 | - 'description' => __( 'Is WordPress multisite?', 'woocommerce' ), |
|
149 | + 'description' => __('Is WordPress multisite?', 'woocommerce'), |
|
150 | 150 | 'type' => 'boolean', |
151 | - 'context' => array( 'view' ), |
|
151 | + 'context' => array('view'), |
|
152 | 152 | 'readonly' => true, |
153 | 153 | ), |
154 | 154 | 'wp_memory_limit' => array( |
155 | - 'description' => __( 'WordPress memory limit.', 'woocommerce' ), |
|
155 | + 'description' => __('WordPress memory limit.', 'woocommerce'), |
|
156 | 156 | 'type' => 'integer', |
157 | - 'context' => array( 'view' ), |
|
157 | + 'context' => array('view'), |
|
158 | 158 | 'readonly' => true, |
159 | 159 | ), |
160 | 160 | 'wp_debug_mode' => array( |
161 | - 'description' => __( 'Is WordPress debug mode active?', 'woocommerce' ), |
|
161 | + 'description' => __('Is WordPress debug mode active?', 'woocommerce'), |
|
162 | 162 | 'type' => 'boolean', |
163 | - 'context' => array( 'view' ), |
|
163 | + 'context' => array('view'), |
|
164 | 164 | 'readonly' => true, |
165 | 165 | ), |
166 | 166 | 'wp_cron' => array( |
167 | - 'description' => __( 'Are WordPress cron jobs enabled?', 'woocommerce' ), |
|
167 | + 'description' => __('Are WordPress cron jobs enabled?', 'woocommerce'), |
|
168 | 168 | 'type' => 'boolean', |
169 | - 'context' => array( 'view' ), |
|
169 | + 'context' => array('view'), |
|
170 | 170 | 'readonly' => true, |
171 | 171 | ), |
172 | 172 | 'language' => array( |
173 | - 'description' => __( 'WordPress language.', 'woocommerce' ), |
|
173 | + 'description' => __('WordPress language.', 'woocommerce'), |
|
174 | 174 | 'type' => 'string', |
175 | - 'context' => array( 'view' ), |
|
175 | + 'context' => array('view'), |
|
176 | 176 | 'readonly' => true, |
177 | 177 | ), |
178 | 178 | 'server_info' => array( |
179 | - 'description' => __( 'Server info.', 'woocommerce' ), |
|
179 | + 'description' => __('Server info.', 'woocommerce'), |
|
180 | 180 | 'type' => 'string', |
181 | - 'context' => array( 'view' ), |
|
181 | + 'context' => array('view'), |
|
182 | 182 | 'readonly' => true, |
183 | 183 | ), |
184 | 184 | 'php_version' => array( |
185 | - 'description' => __( 'PHP version.', 'woocommerce' ), |
|
185 | + 'description' => __('PHP version.', 'woocommerce'), |
|
186 | 186 | 'type' => 'string', |
187 | - 'context' => array( 'view' ), |
|
187 | + 'context' => array('view'), |
|
188 | 188 | 'readonly' => true, |
189 | 189 | ), |
190 | 190 | 'php_post_max_size' => array( |
191 | - 'description' => __( 'PHP post max size.', 'woocommerce' ), |
|
191 | + 'description' => __('PHP post max size.', 'woocommerce'), |
|
192 | 192 | 'type' => 'integer', |
193 | - 'context' => array( 'view' ), |
|
193 | + 'context' => array('view'), |
|
194 | 194 | 'readonly' => true, |
195 | 195 | ), |
196 | 196 | 'php_max_execution_time' => array( |
197 | - 'description' => __( 'PHP max execution time.', 'woocommerce' ), |
|
197 | + 'description' => __('PHP max execution time.', 'woocommerce'), |
|
198 | 198 | 'type' => 'integer', |
199 | - 'context' => array( 'view' ), |
|
199 | + 'context' => array('view'), |
|
200 | 200 | 'readonly' => true, |
201 | 201 | ), |
202 | 202 | 'php_max_input_vars' => array( |
203 | - 'description' => __( 'PHP max input vars.', 'woocommerce' ), |
|
203 | + 'description' => __('PHP max input vars.', 'woocommerce'), |
|
204 | 204 | 'type' => 'integer', |
205 | - 'context' => array( 'view' ), |
|
205 | + 'context' => array('view'), |
|
206 | 206 | 'readonly' => true, |
207 | 207 | ), |
208 | 208 | 'curl_version' => array( |
209 | - 'description' => __( 'cURL version.', 'woocommerce' ), |
|
209 | + 'description' => __('cURL version.', 'woocommerce'), |
|
210 | 210 | 'type' => 'string', |
211 | - 'context' => array( 'view' ), |
|
211 | + 'context' => array('view'), |
|
212 | 212 | 'readonly' => true, |
213 | 213 | ), |
214 | 214 | 'suhosin_installed' => array( |
215 | - 'description' => __( 'Is SUHOSIN installed?', 'woocommerce' ), |
|
215 | + 'description' => __('Is SUHOSIN installed?', 'woocommerce'), |
|
216 | 216 | 'type' => 'boolean', |
217 | - 'context' => array( 'view' ), |
|
217 | + 'context' => array('view'), |
|
218 | 218 | 'readonly' => true, |
219 | 219 | ), |
220 | 220 | 'max_upload_size' => array( |
221 | - 'description' => __( 'Max upload size.', 'woocommerce' ), |
|
221 | + 'description' => __('Max upload size.', 'woocommerce'), |
|
222 | 222 | 'type' => 'integer', |
223 | - 'context' => array( 'view' ), |
|
223 | + 'context' => array('view'), |
|
224 | 224 | 'readonly' => true, |
225 | 225 | ), |
226 | 226 | 'mysql_version' => array( |
227 | - 'description' => __( 'MySQL version.', 'woocommerce' ), |
|
227 | + 'description' => __('MySQL version.', 'woocommerce'), |
|
228 | 228 | 'type' => 'string', |
229 | - 'context' => array( 'view' ), |
|
229 | + 'context' => array('view'), |
|
230 | 230 | 'readonly' => true, |
231 | 231 | ), |
232 | 232 | 'mysql_version_string' => array( |
233 | - 'description' => __( 'MySQL version string.', 'woocommerce' ), |
|
233 | + 'description' => __('MySQL version string.', 'woocommerce'), |
|
234 | 234 | 'type' => 'string', |
235 | - 'context' => array( 'view' ), |
|
235 | + 'context' => array('view'), |
|
236 | 236 | 'readonly' => true, |
237 | 237 | ), |
238 | 238 | 'default_timezone' => array( |
239 | - 'description' => __( 'Default timezone.', 'woocommerce' ), |
|
239 | + 'description' => __('Default timezone.', 'woocommerce'), |
|
240 | 240 | 'type' => 'string', |
241 | - 'context' => array( 'view' ), |
|
241 | + 'context' => array('view'), |
|
242 | 242 | 'readonly' => true, |
243 | 243 | ), |
244 | 244 | 'fsockopen_or_curl_enabled' => array( |
245 | - 'description' => __( 'Is fsockopen/cURL enabled?', 'woocommerce' ), |
|
245 | + 'description' => __('Is fsockopen/cURL enabled?', 'woocommerce'), |
|
246 | 246 | 'type' => 'boolean', |
247 | - 'context' => array( 'view' ), |
|
247 | + 'context' => array('view'), |
|
248 | 248 | 'readonly' => true, |
249 | 249 | ), |
250 | 250 | 'soapclient_enabled' => array( |
251 | - 'description' => __( 'Is SoapClient class enabled?', 'woocommerce' ), |
|
251 | + 'description' => __('Is SoapClient class enabled?', 'woocommerce'), |
|
252 | 252 | 'type' => 'boolean', |
253 | - 'context' => array( 'view' ), |
|
253 | + 'context' => array('view'), |
|
254 | 254 | 'readonly' => true, |
255 | 255 | ), |
256 | 256 | 'domdocument_enabled' => array( |
257 | - 'description' => __( 'Is DomDocument class enabled?', 'woocommerce' ), |
|
257 | + 'description' => __('Is DomDocument class enabled?', 'woocommerce'), |
|
258 | 258 | 'type' => 'boolean', |
259 | - 'context' => array( 'view' ), |
|
259 | + 'context' => array('view'), |
|
260 | 260 | 'readonly' => true, |
261 | 261 | ), |
262 | 262 | 'gzip_enabled' => array( |
263 | - 'description' => __( 'Is GZip enabled?', 'woocommerce' ), |
|
263 | + 'description' => __('Is GZip enabled?', 'woocommerce'), |
|
264 | 264 | 'type' => 'boolean', |
265 | - 'context' => array( 'view' ), |
|
265 | + 'context' => array('view'), |
|
266 | 266 | 'readonly' => true, |
267 | 267 | ), |
268 | 268 | 'mbstring_enabled' => array( |
269 | - 'description' => __( 'Is mbstring enabled?', 'woocommerce' ), |
|
269 | + 'description' => __('Is mbstring enabled?', 'woocommerce'), |
|
270 | 270 | 'type' => 'boolean', |
271 | - 'context' => array( 'view' ), |
|
271 | + 'context' => array('view'), |
|
272 | 272 | 'readonly' => true, |
273 | 273 | ), |
274 | 274 | 'remote_post_successful' => array( |
275 | - 'description' => __( 'Remote POST successful?', 'woocommerce' ), |
|
275 | + 'description' => __('Remote POST successful?', 'woocommerce'), |
|
276 | 276 | 'type' => 'boolean', |
277 | - 'context' => array( 'view' ), |
|
277 | + 'context' => array('view'), |
|
278 | 278 | 'readonly' => true, |
279 | 279 | ), |
280 | 280 | 'remote_post_response' => array( |
281 | - 'description' => __( 'Remote POST response.', 'woocommerce' ), |
|
281 | + 'description' => __('Remote POST response.', 'woocommerce'), |
|
282 | 282 | 'type' => 'string', |
283 | - 'context' => array( 'view' ), |
|
283 | + 'context' => array('view'), |
|
284 | 284 | 'readonly' => true, |
285 | 285 | ), |
286 | 286 | 'remote_get_successful' => array( |
287 | - 'description' => __( 'Remote GET successful?', 'woocommerce' ), |
|
287 | + 'description' => __('Remote GET successful?', 'woocommerce'), |
|
288 | 288 | 'type' => 'boolean', |
289 | - 'context' => array( 'view' ), |
|
289 | + 'context' => array('view'), |
|
290 | 290 | 'readonly' => true, |
291 | 291 | ), |
292 | 292 | 'remote_get_response' => array( |
293 | - 'description' => __( 'Remote GET response.', 'woocommerce' ), |
|
293 | + 'description' => __('Remote GET response.', 'woocommerce'), |
|
294 | 294 | 'type' => 'string', |
295 | - 'context' => array( 'view' ), |
|
295 | + 'context' => array('view'), |
|
296 | 296 | 'readonly' => true, |
297 | 297 | ), |
298 | 298 | ), |
299 | 299 | ), |
300 | 300 | 'database' => array( |
301 | - 'description' => __( 'Database.', 'woocommerce' ), |
|
301 | + 'description' => __('Database.', 'woocommerce'), |
|
302 | 302 | 'type' => 'object', |
303 | - 'context' => array( 'view' ), |
|
303 | + 'context' => array('view'), |
|
304 | 304 | 'readonly' => true, |
305 | 305 | 'properties' => array( |
306 | 306 | 'wc_database_version' => array( |
307 | - 'description' => __( 'WC database version.', 'woocommerce' ), |
|
307 | + 'description' => __('WC database version.', 'woocommerce'), |
|
308 | 308 | 'type' => 'string', |
309 | - 'context' => array( 'view' ), |
|
309 | + 'context' => array('view'), |
|
310 | 310 | 'readonly' => true, |
311 | 311 | ), |
312 | 312 | 'database_prefix' => array( |
313 | - 'description' => __( 'Database prefix.', 'woocommerce' ), |
|
313 | + 'description' => __('Database prefix.', 'woocommerce'), |
|
314 | 314 | 'type' => 'string', |
315 | - 'context' => array( 'view' ), |
|
315 | + 'context' => array('view'), |
|
316 | 316 | 'readonly' => true, |
317 | 317 | ), |
318 | 318 | 'maxmind_geoip_database' => array( |
319 | - 'description' => __( 'MaxMind GeoIP database.', 'woocommerce' ), |
|
319 | + 'description' => __('MaxMind GeoIP database.', 'woocommerce'), |
|
320 | 320 | 'type' => 'string', |
321 | - 'context' => array( 'view' ), |
|
321 | + 'context' => array('view'), |
|
322 | 322 | 'readonly' => true, |
323 | 323 | ), |
324 | 324 | 'database_tables' => array( |
325 | - 'description' => __( 'Database tables.', 'woocommerce' ), |
|
325 | + 'description' => __('Database tables.', 'woocommerce'), |
|
326 | 326 | 'type' => 'array', |
327 | - 'context' => array( 'view' ), |
|
327 | + 'context' => array('view'), |
|
328 | 328 | 'readonly' => true, |
329 | 329 | 'items' => array( |
330 | 330 | 'type' => 'string', |
@@ -333,190 +333,190 @@ discard block |
||
333 | 333 | ), |
334 | 334 | ), |
335 | 335 | 'active_plugins' => array( |
336 | - 'description' => __( 'Active plugins.', 'woocommerce' ), |
|
336 | + 'description' => __('Active plugins.', 'woocommerce'), |
|
337 | 337 | 'type' => 'array', |
338 | - 'context' => array( 'view' ), |
|
338 | + 'context' => array('view'), |
|
339 | 339 | 'readonly' => true, |
340 | 340 | 'items' => array( |
341 | 341 | 'type' => 'string', |
342 | 342 | ), |
343 | 343 | ), |
344 | 344 | 'inactive_plugins' => array( |
345 | - 'description' => __( 'Inactive plugins.', 'woocommerce' ), |
|
345 | + 'description' => __('Inactive plugins.', 'woocommerce'), |
|
346 | 346 | 'type' => 'array', |
347 | - 'context' => array( 'view' ), |
|
347 | + 'context' => array('view'), |
|
348 | 348 | 'readonly' => true, |
349 | 349 | 'items' => array( |
350 | 350 | 'type' => 'string', |
351 | 351 | ), |
352 | 352 | ), |
353 | 353 | 'dropins_mu_plugins' => array( |
354 | - 'description' => __( 'Dropins & MU plugins.', 'woocommerce' ), |
|
354 | + 'description' => __('Dropins & MU plugins.', 'woocommerce'), |
|
355 | 355 | 'type' => 'array', |
356 | - 'context' => array( 'view' ), |
|
356 | + 'context' => array('view'), |
|
357 | 357 | 'readonly' => true, |
358 | 358 | 'items' => array( |
359 | 359 | 'type' => 'string', |
360 | 360 | ), |
361 | 361 | ), |
362 | 362 | 'theme' => array( |
363 | - 'description' => __( 'Theme.', 'woocommerce' ), |
|
363 | + 'description' => __('Theme.', 'woocommerce'), |
|
364 | 364 | 'type' => 'object', |
365 | - 'context' => array( 'view' ), |
|
365 | + 'context' => array('view'), |
|
366 | 366 | 'readonly' => true, |
367 | 367 | 'properties' => array( |
368 | 368 | 'name' => array( |
369 | - 'description' => __( 'Theme name.', 'woocommerce' ), |
|
369 | + 'description' => __('Theme name.', 'woocommerce'), |
|
370 | 370 | 'type' => 'string', |
371 | - 'context' => array( 'view' ), |
|
371 | + 'context' => array('view'), |
|
372 | 372 | 'readonly' => true, |
373 | 373 | ), |
374 | 374 | 'version' => array( |
375 | - 'description' => __( 'Theme version.', 'woocommerce' ), |
|
375 | + 'description' => __('Theme version.', 'woocommerce'), |
|
376 | 376 | 'type' => 'string', |
377 | - 'context' => array( 'view' ), |
|
377 | + 'context' => array('view'), |
|
378 | 378 | 'readonly' => true, |
379 | 379 | ), |
380 | 380 | 'version_latest' => array( |
381 | - 'description' => __( 'Latest version of theme.', 'woocommerce' ), |
|
381 | + 'description' => __('Latest version of theme.', 'woocommerce'), |
|
382 | 382 | 'type' => 'string', |
383 | - 'context' => array( 'view' ), |
|
383 | + 'context' => array('view'), |
|
384 | 384 | 'readonly' => true, |
385 | 385 | ), |
386 | 386 | 'author_url' => array( |
387 | - 'description' => __( 'Theme author URL.', 'woocommerce' ), |
|
387 | + 'description' => __('Theme author URL.', 'woocommerce'), |
|
388 | 388 | 'type' => 'string', |
389 | 389 | 'format' => 'uri', |
390 | - 'context' => array( 'view' ), |
|
390 | + 'context' => array('view'), |
|
391 | 391 | 'readonly' => true, |
392 | 392 | ), |
393 | 393 | 'is_child_theme' => array( |
394 | - 'description' => __( 'Is this theme a child theme?', 'woocommerce' ), |
|
394 | + 'description' => __('Is this theme a child theme?', 'woocommerce'), |
|
395 | 395 | 'type' => 'boolean', |
396 | - 'context' => array( 'view' ), |
|
396 | + 'context' => array('view'), |
|
397 | 397 | 'readonly' => true, |
398 | 398 | ), |
399 | 399 | 'has_woocommerce_support' => array( |
400 | - 'description' => __( 'Does the theme declare WooCommerce support?', 'woocommerce' ), |
|
400 | + 'description' => __('Does the theme declare WooCommerce support?', 'woocommerce'), |
|
401 | 401 | 'type' => 'boolean', |
402 | - 'context' => array( 'view' ), |
|
402 | + 'context' => array('view'), |
|
403 | 403 | 'readonly' => true, |
404 | 404 | ), |
405 | 405 | 'has_woocommerce_file' => array( |
406 | - 'description' => __( 'Does the theme have a woocommerce.php file?', 'woocommerce' ), |
|
406 | + 'description' => __('Does the theme have a woocommerce.php file?', 'woocommerce'), |
|
407 | 407 | 'type' => 'boolean', |
408 | - 'context' => array( 'view' ), |
|
408 | + 'context' => array('view'), |
|
409 | 409 | 'readonly' => true, |
410 | 410 | ), |
411 | 411 | 'has_outdated_templates' => array( |
412 | - 'description' => __( 'Does this theme have outdated templates?', 'woocommerce' ), |
|
412 | + 'description' => __('Does this theme have outdated templates?', 'woocommerce'), |
|
413 | 413 | 'type' => 'boolean', |
414 | - 'context' => array( 'view' ), |
|
414 | + 'context' => array('view'), |
|
415 | 415 | 'readonly' => true, |
416 | 416 | ), |
417 | 417 | 'overrides' => array( |
418 | - 'description' => __( 'Template overrides.', 'woocommerce' ), |
|
418 | + 'description' => __('Template overrides.', 'woocommerce'), |
|
419 | 419 | 'type' => 'array', |
420 | - 'context' => array( 'view' ), |
|
420 | + 'context' => array('view'), |
|
421 | 421 | 'readonly' => true, |
422 | 422 | 'items' => array( |
423 | 423 | 'type' => 'string', |
424 | 424 | ), |
425 | 425 | ), |
426 | 426 | 'parent_name' => array( |
427 | - 'description' => __( 'Parent theme name.', 'woocommerce' ), |
|
427 | + 'description' => __('Parent theme name.', 'woocommerce'), |
|
428 | 428 | 'type' => 'string', |
429 | - 'context' => array( 'view' ), |
|
429 | + 'context' => array('view'), |
|
430 | 430 | 'readonly' => true, |
431 | 431 | ), |
432 | 432 | 'parent_version' => array( |
433 | - 'description' => __( 'Parent theme version.', 'woocommerce' ), |
|
433 | + 'description' => __('Parent theme version.', 'woocommerce'), |
|
434 | 434 | 'type' => 'string', |
435 | - 'context' => array( 'view' ), |
|
435 | + 'context' => array('view'), |
|
436 | 436 | 'readonly' => true, |
437 | 437 | ), |
438 | 438 | 'parent_author_url' => array( |
439 | - 'description' => __( 'Parent theme author URL.', 'woocommerce' ), |
|
439 | + 'description' => __('Parent theme author URL.', 'woocommerce'), |
|
440 | 440 | 'type' => 'string', |
441 | 441 | 'format' => 'uri', |
442 | - 'context' => array( 'view' ), |
|
442 | + 'context' => array('view'), |
|
443 | 443 | 'readonly' => true, |
444 | 444 | ), |
445 | 445 | ), |
446 | 446 | ), |
447 | 447 | 'settings' => array( |
448 | - 'description' => __( 'Settings.', 'woocommerce' ), |
|
448 | + 'description' => __('Settings.', 'woocommerce'), |
|
449 | 449 | 'type' => 'object', |
450 | - 'context' => array( 'view' ), |
|
450 | + 'context' => array('view'), |
|
451 | 451 | 'readonly' => true, |
452 | 452 | 'properties' => array( |
453 | 453 | 'api_enabled' => array( |
454 | - 'description' => __( 'REST API enabled?', 'woocommerce' ), |
|
454 | + 'description' => __('REST API enabled?', 'woocommerce'), |
|
455 | 455 | 'type' => 'boolean', |
456 | - 'context' => array( 'view' ), |
|
456 | + 'context' => array('view'), |
|
457 | 457 | 'readonly' => true, |
458 | 458 | ), |
459 | 459 | 'force_ssl' => array( |
460 | - 'description' => __( 'SSL forced?', 'woocommerce' ), |
|
460 | + 'description' => __('SSL forced?', 'woocommerce'), |
|
461 | 461 | 'type' => 'boolean', |
462 | - 'context' => array( 'view' ), |
|
462 | + 'context' => array('view'), |
|
463 | 463 | 'readonly' => true, |
464 | 464 | ), |
465 | 465 | 'currency' => array( |
466 | - 'description' => __( 'Currency.', 'woocommerce' ), |
|
466 | + 'description' => __('Currency.', 'woocommerce'), |
|
467 | 467 | 'type' => 'string', |
468 | - 'context' => array( 'view' ), |
|
468 | + 'context' => array('view'), |
|
469 | 469 | 'readonly' => true, |
470 | 470 | ), |
471 | 471 | 'currency_symbol' => array( |
472 | - 'description' => __( 'Currency symbol.', 'woocommerce' ), |
|
472 | + 'description' => __('Currency symbol.', 'woocommerce'), |
|
473 | 473 | 'type' => 'string', |
474 | - 'context' => array( 'view' ), |
|
474 | + 'context' => array('view'), |
|
475 | 475 | 'readonly' => true, |
476 | 476 | ), |
477 | 477 | 'currency_position' => array( |
478 | - 'description' => __( 'Currency position.', 'woocommerce' ), |
|
478 | + 'description' => __('Currency position.', 'woocommerce'), |
|
479 | 479 | 'type' => 'string', |
480 | - 'context' => array( 'view' ), |
|
480 | + 'context' => array('view'), |
|
481 | 481 | 'readonly' => true, |
482 | 482 | ), |
483 | 483 | 'thousand_separator' => array( |
484 | - 'description' => __( 'Thousand separator.', 'woocommerce' ), |
|
484 | + 'description' => __('Thousand separator.', 'woocommerce'), |
|
485 | 485 | 'type' => 'string', |
486 | - 'context' => array( 'view' ), |
|
486 | + 'context' => array('view'), |
|
487 | 487 | 'readonly' => true, |
488 | 488 | ), |
489 | 489 | 'decimal_separator' => array( |
490 | - 'description' => __( 'Decimal separator.', 'woocommerce' ), |
|
490 | + 'description' => __('Decimal separator.', 'woocommerce'), |
|
491 | 491 | 'type' => 'string', |
492 | - 'context' => array( 'view' ), |
|
492 | + 'context' => array('view'), |
|
493 | 493 | 'readonly' => true, |
494 | 494 | ), |
495 | 495 | 'number_of_decimals' => array( |
496 | - 'description' => __( 'Number of decimals.', 'woocommerce' ), |
|
496 | + 'description' => __('Number of decimals.', 'woocommerce'), |
|
497 | 497 | 'type' => 'integer', |
498 | - 'context' => array( 'view' ), |
|
498 | + 'context' => array('view'), |
|
499 | 499 | 'readonly' => true, |
500 | 500 | ), |
501 | 501 | 'geolocation_enabled' => array( |
502 | - 'description' => __( 'Geolocation enabled?', 'woocommerce' ), |
|
502 | + 'description' => __('Geolocation enabled?', 'woocommerce'), |
|
503 | 503 | 'type' => 'boolean', |
504 | - 'context' => array( 'view' ), |
|
504 | + 'context' => array('view'), |
|
505 | 505 | 'readonly' => true, |
506 | 506 | ), |
507 | 507 | 'taxonomies' => array( |
508 | - 'description' => __( 'Taxonomy terms for product/order statuses.', 'woocommerce' ), |
|
508 | + 'description' => __('Taxonomy terms for product/order statuses.', 'woocommerce'), |
|
509 | 509 | 'type' => 'array', |
510 | - 'context' => array( 'view' ), |
|
510 | + 'context' => array('view'), |
|
511 | 511 | 'readonly' => true, |
512 | 512 | 'items' => array( |
513 | 513 | 'type' => 'string', |
514 | 514 | ), |
515 | 515 | ), |
516 | 516 | 'product_visibility_terms' => array( |
517 | - 'description' => __( 'Terms in the product visibility taxonomy.', 'woocommerce' ), |
|
517 | + 'description' => __('Terms in the product visibility taxonomy.', 'woocommerce'), |
|
518 | 518 | 'type' => 'array', |
519 | - 'context' => array( 'view' ), |
|
519 | + 'context' => array('view'), |
|
520 | 520 | 'readonly' => true, |
521 | 521 | 'items' => array( |
522 | 522 | 'type' => 'string', |
@@ -525,29 +525,29 @@ discard block |
||
525 | 525 | ), |
526 | 526 | ), |
527 | 527 | 'security' => array( |
528 | - 'description' => __( 'Security.', 'woocommerce' ), |
|
528 | + 'description' => __('Security.', 'woocommerce'), |
|
529 | 529 | 'type' => 'object', |
530 | - 'context' => array( 'view' ), |
|
530 | + 'context' => array('view'), |
|
531 | 531 | 'readonly' => true, |
532 | 532 | 'properties' => array( |
533 | 533 | 'secure_connection' => array( |
534 | - 'description' => __( 'Is the connection to your store secure?', 'woocommerce' ), |
|
534 | + 'description' => __('Is the connection to your store secure?', 'woocommerce'), |
|
535 | 535 | 'type' => 'boolean', |
536 | - 'context' => array( 'view' ), |
|
536 | + 'context' => array('view'), |
|
537 | 537 | 'readonly' => true, |
538 | 538 | ), |
539 | 539 | 'hide_errors' => array( |
540 | - 'description' => __( 'Hide errors from visitors?', 'woocommerce' ), |
|
540 | + 'description' => __('Hide errors from visitors?', 'woocommerce'), |
|
541 | 541 | 'type' => 'boolean', |
542 | - 'context' => array( 'view' ), |
|
542 | + 'context' => array('view'), |
|
543 | 543 | 'readonly' => true, |
544 | 544 | ), |
545 | 545 | ), |
546 | 546 | ), |
547 | 547 | 'pages' => array( |
548 | - 'description' => __( 'WooCommerce pages.', 'woocommerce' ), |
|
548 | + 'description' => __('WooCommerce pages.', 'woocommerce'), |
|
549 | 549 | 'type' => 'array', |
550 | - 'context' => array( 'view' ), |
|
550 | + 'context' => array('view'), |
|
551 | 551 | 'readonly' => true, |
552 | 552 | 'items' => array( |
553 | 553 | 'type' => 'string', |
@@ -556,7 +556,7 @@ discard block |
||
556 | 556 | ), |
557 | 557 | ); |
558 | 558 | |
559 | - return $this->add_additional_fields_schema( $schema ); |
|
559 | + return $this->add_additional_fields_schema($schema); |
|
560 | 560 | } |
561 | 561 | |
562 | 562 | /** |
@@ -589,23 +589,23 @@ discard block |
||
589 | 589 | |
590 | 590 | // Figure out cURL version, if installed. |
591 | 591 | $curl_version = ''; |
592 | - if ( function_exists( 'curl_version' ) ) { |
|
592 | + if (function_exists('curl_version')) { |
|
593 | 593 | $curl_version = curl_version(); |
594 | 594 | $curl_version = $curl_version['version'] . ', ' . $curl_version['ssl_version']; |
595 | - } elseif ( extension_loaded( 'curl' ) ) { |
|
596 | - $curl_version = __( 'cURL installed but unable to retrieve version.', 'woocommerce' ); |
|
595 | + } elseif (extension_loaded('curl')) { |
|
596 | + $curl_version = __('cURL installed but unable to retrieve version.', 'woocommerce'); |
|
597 | 597 | } |
598 | 598 | |
599 | 599 | // WP memory limit. |
600 | - $wp_memory_limit = wc_let_to_num( WP_MEMORY_LIMIT ); |
|
601 | - if ( function_exists( 'memory_get_usage' ) ) { |
|
602 | - $wp_memory_limit = max( $wp_memory_limit, wc_let_to_num( @ini_get( 'memory_limit' ) ) ); |
|
600 | + $wp_memory_limit = wc_let_to_num(WP_MEMORY_LIMIT); |
|
601 | + if (function_exists('memory_get_usage')) { |
|
602 | + $wp_memory_limit = max($wp_memory_limit, wc_let_to_num(@ini_get('memory_limit'))); |
|
603 | 603 | } |
604 | 604 | |
605 | 605 | // Test POST requests. |
606 | - $post_response_code = get_transient( 'woocommerce_test_remote_post' ); |
|
606 | + $post_response_code = get_transient('woocommerce_test_remote_post'); |
|
607 | 607 | |
608 | - if ( false === $post_response_code || is_wp_error( $post_response_code ) ) { |
|
608 | + if (false === $post_response_code || is_wp_error($post_response_code)) { |
|
609 | 609 | $response = wp_safe_remote_post( |
610 | 610 | 'https://www.paypal.com/cgi-bin/webscr', |
611 | 611 | array( |
@@ -617,63 +617,63 @@ discard block |
||
617 | 617 | ), |
618 | 618 | ) |
619 | 619 | ); |
620 | - if ( ! is_wp_error( $response ) ) { |
|
620 | + if ( ! is_wp_error($response)) { |
|
621 | 621 | $post_response_code = $response['response']['code']; |
622 | 622 | } |
623 | - set_transient( 'woocommerce_test_remote_post', $post_response_code, HOUR_IN_SECONDS ); |
|
623 | + set_transient('woocommerce_test_remote_post', $post_response_code, HOUR_IN_SECONDS); |
|
624 | 624 | } |
625 | 625 | |
626 | - $post_response_successful = ! is_wp_error( $post_response_code ) && $post_response_code >= 200 && $post_response_code < 300; |
|
626 | + $post_response_successful = ! is_wp_error($post_response_code) && $post_response_code >= 200 && $post_response_code < 300; |
|
627 | 627 | |
628 | 628 | // Test GET requests. |
629 | - $get_response_code = get_transient( 'woocommerce_test_remote_get' ); |
|
629 | + $get_response_code = get_transient('woocommerce_test_remote_get'); |
|
630 | 630 | |
631 | - if ( false === $get_response_code || is_wp_error( $get_response_code ) ) { |
|
632 | - $response = wp_safe_remote_get( 'https://woocommerce.com/wc-api/product-key-api?request=ping&network=' . ( is_multisite() ? '1' : '0' ) ); |
|
633 | - if ( ! is_wp_error( $response ) ) { |
|
631 | + if (false === $get_response_code || is_wp_error($get_response_code)) { |
|
632 | + $response = wp_safe_remote_get('https://woocommerce.com/wc-api/product-key-api?request=ping&network=' . (is_multisite() ? '1' : '0')); |
|
633 | + if ( ! is_wp_error($response)) { |
|
634 | 634 | $get_response_code = $response['response']['code']; |
635 | 635 | } |
636 | - set_transient( 'woocommerce_test_remote_get', $get_response_code, HOUR_IN_SECONDS ); |
|
636 | + set_transient('woocommerce_test_remote_get', $get_response_code, HOUR_IN_SECONDS); |
|
637 | 637 | } |
638 | 638 | |
639 | - $get_response_successful = ! is_wp_error( $get_response_code ) && $get_response_code >= 200 && $get_response_code < 300; |
|
639 | + $get_response_successful = ! is_wp_error($get_response_code) && $get_response_code >= 200 && $get_response_code < 300; |
|
640 | 640 | |
641 | 641 | $database_version = wc_get_server_database_version(); |
642 | 642 | |
643 | 643 | // Return all environment info. Described by JSON Schema. |
644 | 644 | return array( |
645 | - 'home_url' => get_option( 'home' ), |
|
646 | - 'site_url' => get_option( 'siteurl' ), |
|
645 | + 'home_url' => get_option('home'), |
|
646 | + 'site_url' => get_option('siteurl'), |
|
647 | 647 | 'version' => WC()->version, |
648 | 648 | 'log_directory' => WC_LOG_DIR, |
649 | - 'log_directory_writable' => (bool) @fopen( WC_LOG_DIR . 'test-log.log', 'a' ), |
|
650 | - 'wp_version' => get_bloginfo( 'version' ), |
|
649 | + 'log_directory_writable' => (bool) @fopen(WC_LOG_DIR . 'test-log.log', 'a'), |
|
650 | + 'wp_version' => get_bloginfo('version'), |
|
651 | 651 | 'wp_multisite' => is_multisite(), |
652 | 652 | 'wp_memory_limit' => $wp_memory_limit, |
653 | - 'wp_debug_mode' => ( defined( 'WP_DEBUG' ) && WP_DEBUG ), |
|
654 | - 'wp_cron' => ! ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ), |
|
653 | + 'wp_debug_mode' => (defined('WP_DEBUG') && WP_DEBUG), |
|
654 | + 'wp_cron' => ! (defined('DISABLE_WP_CRON') && DISABLE_WP_CRON), |
|
655 | 655 | 'language' => get_locale(), |
656 | 656 | 'external_object_cache' => wp_using_ext_object_cache(), |
657 | - 'server_info' => isset( $_SERVER['SERVER_SOFTWARE'] ) ? wc_clean( wp_unslash( $_SERVER['SERVER_SOFTWARE'] ) ) : '', |
|
657 | + 'server_info' => isset($_SERVER['SERVER_SOFTWARE']) ? wc_clean(wp_unslash($_SERVER['SERVER_SOFTWARE'])) : '', |
|
658 | 658 | 'php_version' => phpversion(), |
659 | - 'php_post_max_size' => wc_let_to_num( ini_get( 'post_max_size' ) ), |
|
660 | - 'php_max_execution_time' => ini_get( 'max_execution_time' ), |
|
661 | - 'php_max_input_vars' => ini_get( 'max_input_vars' ), |
|
659 | + 'php_post_max_size' => wc_let_to_num(ini_get('post_max_size')), |
|
660 | + 'php_max_execution_time' => ini_get('max_execution_time'), |
|
661 | + 'php_max_input_vars' => ini_get('max_input_vars'), |
|
662 | 662 | 'curl_version' => $curl_version, |
663 | - 'suhosin_installed' => extension_loaded( 'suhosin' ), |
|
663 | + 'suhosin_installed' => extension_loaded('suhosin'), |
|
664 | 664 | 'max_upload_size' => wp_max_upload_size(), |
665 | 665 | 'mysql_version' => $database_version['number'], |
666 | 666 | 'mysql_version_string' => $database_version['string'], |
667 | 667 | 'default_timezone' => date_default_timezone_get(), |
668 | - 'fsockopen_or_curl_enabled' => ( function_exists( 'fsockopen' ) || function_exists( 'curl_init' ) ), |
|
669 | - 'soapclient_enabled' => class_exists( 'SoapClient' ), |
|
670 | - 'domdocument_enabled' => class_exists( 'DOMDocument' ), |
|
671 | - 'gzip_enabled' => is_callable( 'gzopen' ), |
|
672 | - 'mbstring_enabled' => extension_loaded( 'mbstring' ), |
|
668 | + 'fsockopen_or_curl_enabled' => (function_exists('fsockopen') || function_exists('curl_init')), |
|
669 | + 'soapclient_enabled' => class_exists('SoapClient'), |
|
670 | + 'domdocument_enabled' => class_exists('DOMDocument'), |
|
671 | + 'gzip_enabled' => is_callable('gzopen'), |
|
672 | + 'mbstring_enabled' => extension_loaded('mbstring'), |
|
673 | 673 | 'remote_post_successful' => $post_response_successful, |
674 | - 'remote_post_response' => is_wp_error( $post_response_code ) ? $post_response_code->get_error_message() : $post_response_code, |
|
674 | + 'remote_post_response' => is_wp_error($post_response_code) ? $post_response_code->get_error_message() : $post_response_code, |
|
675 | 675 | 'remote_get_successful' => $get_response_successful, |
676 | - 'remote_get_response' => is_wp_error( $get_response_code ) ? $get_response_code->get_error_message() : $get_response_code, |
|
676 | + 'remote_get_response' => is_wp_error($get_response_code) ? $get_response_code->get_error_message() : $get_response_code, |
|
677 | 677 | ); |
678 | 678 | } |
679 | 679 | |
@@ -683,7 +683,7 @@ discard block |
||
683 | 683 | * @param string $table Table name. |
684 | 684 | * @return stromg |
685 | 685 | */ |
686 | - protected function add_db_table_prefix( $table ) { |
|
686 | + protected function add_db_table_prefix($table) { |
|
687 | 687 | global $wpdb; |
688 | 688 | return $wpdb->prefix . $table; |
689 | 689 | } |
@@ -736,7 +736,7 @@ discard block |
||
736 | 736 | * |
737 | 737 | * If we changed the tables above to include the prefix, then any filters against that table could break. |
738 | 738 | */ |
739 | - $core_tables = array_map( array( $this, 'add_db_table_prefix' ), $core_tables ); |
|
739 | + $core_tables = array_map(array($this, 'add_db_table_prefix'), $core_tables); |
|
740 | 740 | |
741 | 741 | /** |
742 | 742 | * Organize WooCommerce and non-WooCommerce tables separately for display purposes later. |
@@ -744,7 +744,7 @@ discard block |
||
744 | 744 | * To ensure we include all WC tables, even if they do not exist, pre-populate the WC array with all the tables. |
745 | 745 | */ |
746 | 746 | $tables = array( |
747 | - 'woocommerce' => array_fill_keys( $core_tables, false ), |
|
747 | + 'woocommerce' => array_fill_keys($core_tables, false), |
|
748 | 748 | 'other' => array(), |
749 | 749 | ); |
750 | 750 | |
@@ -753,16 +753,16 @@ discard block |
||
753 | 753 | 'index' => 0, |
754 | 754 | ); |
755 | 755 | |
756 | - $site_tables_prefix = $wpdb->get_blog_prefix( get_current_blog_id() ); |
|
757 | - $global_tables = $wpdb->tables( 'global', true ); |
|
758 | - foreach ( $database_table_information as $table ) { |
|
756 | + $site_tables_prefix = $wpdb->get_blog_prefix(get_current_blog_id()); |
|
757 | + $global_tables = $wpdb->tables('global', true); |
|
758 | + foreach ($database_table_information as $table) { |
|
759 | 759 | // Only include tables matching the prefix of the current site, this is to prevent displaying all tables on a MS install not relating to the current. |
760 | - if ( is_multisite() && 0 !== strpos( $table->name, $site_tables_prefix ) && ! in_array( $table->name, $global_tables, true ) ) { |
|
760 | + if (is_multisite() && 0 !== strpos($table->name, $site_tables_prefix) && ! in_array($table->name, $global_tables, true)) { |
|
761 | 761 | continue; |
762 | 762 | } |
763 | - $table_type = in_array( $table->name, $core_tables ) ? 'woocommerce' : 'other'; |
|
763 | + $table_type = in_array($table->name, $core_tables) ? 'woocommerce' : 'other'; |
|
764 | 764 | |
765 | - $tables[ $table_type ][ $table->name ] = array( |
|
765 | + $tables[$table_type][$table->name] = array( |
|
766 | 766 | 'data' => $table->data, |
767 | 767 | 'index' => $table->index, |
768 | 768 | 'engine' => $table->engine, |
@@ -774,7 +774,7 @@ discard block |
||
774 | 774 | |
775 | 775 | // Return all database info. Described by JSON Schema. |
776 | 776 | return array( |
777 | - 'wc_database_version' => get_option( 'woocommerce_db_version' ), |
|
777 | + 'wc_database_version' => get_option('woocommerce_db_version'), |
|
778 | 778 | 'database_prefix' => $wpdb->prefix, |
779 | 779 | 'maxmind_geoip_database' => WC_Geolocation::get_local_database_path(), |
780 | 780 | 'database_tables' => $tables, |
@@ -790,9 +790,9 @@ discard block |
||
790 | 790 | public function get_post_type_counts() { |
791 | 791 | global $wpdb; |
792 | 792 | |
793 | - $post_type_counts = $wpdb->get_results( "SELECT post_type AS 'type', count(1) AS 'count' FROM {$wpdb->posts} GROUP BY post_type;" ); |
|
793 | + $post_type_counts = $wpdb->get_results("SELECT post_type AS 'type', count(1) AS 'count' FROM {$wpdb->posts} GROUP BY post_type;"); |
|
794 | 794 | |
795 | - return is_array( $post_type_counts ) ? $post_type_counts : array(); |
|
795 | + return is_array($post_type_counts) ? $post_type_counts : array(); |
|
796 | 796 | } |
797 | 797 | |
798 | 798 | /** |
@@ -803,21 +803,21 @@ discard block |
||
803 | 803 | public function get_active_plugins() { |
804 | 804 | require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
805 | 805 | |
806 | - if ( ! function_exists( 'get_plugin_data' ) ) { |
|
806 | + if ( ! function_exists('get_plugin_data')) { |
|
807 | 807 | return array(); |
808 | 808 | } |
809 | 809 | |
810 | - $active_plugins = (array) get_option( 'active_plugins', array() ); |
|
811 | - if ( is_multisite() ) { |
|
812 | - $network_activated_plugins = array_keys( get_site_option( 'active_sitewide_plugins', array() ) ); |
|
813 | - $active_plugins = array_merge( $active_plugins, $network_activated_plugins ); |
|
810 | + $active_plugins = (array) get_option('active_plugins', array()); |
|
811 | + if (is_multisite()) { |
|
812 | + $network_activated_plugins = array_keys(get_site_option('active_sitewide_plugins', array())); |
|
813 | + $active_plugins = array_merge($active_plugins, $network_activated_plugins); |
|
814 | 814 | } |
815 | 815 | |
816 | 816 | $active_plugins_data = array(); |
817 | 817 | |
818 | - foreach ( $active_plugins as $plugin ) { |
|
819 | - $data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin ); |
|
820 | - $active_plugins_data[] = $this->format_plugin_data( $plugin, $data ); |
|
818 | + foreach ($active_plugins as $plugin) { |
|
819 | + $data = get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin); |
|
820 | + $active_plugins_data[] = $this->format_plugin_data($plugin, $data); |
|
821 | 821 | } |
822 | 822 | |
823 | 823 | return $active_plugins_data; |
@@ -831,25 +831,25 @@ discard block |
||
831 | 831 | public function get_inactive_plugins() { |
832 | 832 | require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
833 | 833 | |
834 | - if ( ! function_exists( 'get_plugins' ) ) { |
|
834 | + if ( ! function_exists('get_plugins')) { |
|
835 | 835 | return array(); |
836 | 836 | } |
837 | 837 | |
838 | 838 | $plugins = get_plugins(); |
839 | - $active_plugins = (array) get_option( 'active_plugins', array() ); |
|
839 | + $active_plugins = (array) get_option('active_plugins', array()); |
|
840 | 840 | |
841 | - if ( is_multisite() ) { |
|
842 | - $network_activated_plugins = array_keys( get_site_option( 'active_sitewide_plugins', array() ) ); |
|
843 | - $active_plugins = array_merge( $active_plugins, $network_activated_plugins ); |
|
841 | + if (is_multisite()) { |
|
842 | + $network_activated_plugins = array_keys(get_site_option('active_sitewide_plugins', array())); |
|
843 | + $active_plugins = array_merge($active_plugins, $network_activated_plugins); |
|
844 | 844 | } |
845 | 845 | |
846 | 846 | $plugins_data = array(); |
847 | 847 | |
848 | - foreach ( $plugins as $plugin => $data ) { |
|
849 | - if ( in_array( $plugin, $active_plugins, true ) ) { |
|
848 | + foreach ($plugins as $plugin => $data) { |
|
849 | + if (in_array($plugin, $active_plugins, true)) { |
|
850 | 850 | continue; |
851 | 851 | } |
852 | - $plugins_data[] = $this->format_plugin_data( $plugin, $data ); |
|
852 | + $plugins_data[] = $this->format_plugin_data($plugin, $data); |
|
853 | 853 | } |
854 | 854 | |
855 | 855 | return $plugins_data; |
@@ -863,23 +863,23 @@ discard block |
||
863 | 863 | * @param array $data Plugin data from WP. |
864 | 864 | * @return array Formatted data. |
865 | 865 | */ |
866 | - protected function format_plugin_data( $plugin, $data ) { |
|
866 | + protected function format_plugin_data($plugin, $data) { |
|
867 | 867 | require_once ABSPATH . 'wp-admin/includes/update.php'; |
868 | 868 | |
869 | - if ( ! function_exists( 'get_plugin_updates' ) ) { |
|
869 | + if ( ! function_exists('get_plugin_updates')) { |
|
870 | 870 | return array(); |
871 | 871 | } |
872 | 872 | |
873 | 873 | // Use WP API to lookup latest updates for plugins. WC_Helper injects updates for premium plugins. |
874 | - if ( empty( $this->available_updates ) ) { |
|
874 | + if (empty($this->available_updates)) { |
|
875 | 875 | $this->available_updates = get_plugin_updates(); |
876 | 876 | } |
877 | 877 | |
878 | 878 | $version_latest = $data['Version']; |
879 | 879 | |
880 | 880 | // Find latest version. |
881 | - if ( isset( $this->available_updates[ $plugin ]->update->new_version ) ) { |
|
882 | - $version_latest = $this->available_updates[ $plugin ]->update->new_version; |
|
881 | + if (isset($this->available_updates[$plugin]->update->new_version)) { |
|
882 | + $version_latest = $this->available_updates[$plugin]->update->new_version; |
|
883 | 883 | } |
884 | 884 | |
885 | 885 | return array( |
@@ -889,7 +889,7 @@ discard block |
||
889 | 889 | 'version_latest' => $version_latest, |
890 | 890 | 'url' => $data['PluginURI'], |
891 | 891 | 'author_name' => $data['AuthorName'], |
892 | - 'author_url' => esc_url_raw( $data['AuthorURI'] ), |
|
892 | + 'author_url' => esc_url_raw($data['AuthorURI']), |
|
893 | 893 | 'network_activated' => $data['Network'], |
894 | 894 | ); |
895 | 895 | } |
@@ -906,7 +906,7 @@ discard block |
||
906 | 906 | 'dropins' => array(), |
907 | 907 | 'mu_plugins' => array(), |
908 | 908 | ); |
909 | - foreach ( $dropins as $key => $dropin ) { |
|
909 | + foreach ($dropins as $key => $dropin) { |
|
910 | 910 | $plugins['dropins'][] = array( |
911 | 911 | 'plugin' => $key, |
912 | 912 | 'name' => $dropin['Name'], |
@@ -914,14 +914,14 @@ discard block |
||
914 | 914 | } |
915 | 915 | |
916 | 916 | $mu_plugins = get_mu_plugins(); |
917 | - foreach ( $mu_plugins as $plugin => $mu_plugin ) { |
|
917 | + foreach ($mu_plugins as $plugin => $mu_plugin) { |
|
918 | 918 | $plugins['mu_plugins'][] = array( |
919 | 919 | 'plugin' => $plugin, |
920 | 920 | 'name' => $mu_plugin['Name'], |
921 | 921 | 'version' => $mu_plugin['Version'], |
922 | 922 | 'url' => $mu_plugin['PluginURI'], |
923 | 923 | 'author_name' => $mu_plugin['AuthorName'], |
924 | - 'author_url' => esc_url_raw( $mu_plugin['AuthorURI'] ), |
|
924 | + 'author_url' => esc_url_raw($mu_plugin['AuthorURI']), |
|
925 | 925 | ); |
926 | 926 | } |
927 | 927 | return $plugins; |
@@ -938,12 +938,12 @@ discard block |
||
938 | 938 | |
939 | 939 | // Get parent theme info if this theme is a child theme, otherwise |
940 | 940 | // pass empty info in the response. |
941 | - if ( is_child_theme() ) { |
|
942 | - $parent_theme = wp_get_theme( $active_theme->template ); |
|
941 | + if (is_child_theme()) { |
|
942 | + $parent_theme = wp_get_theme($active_theme->template); |
|
943 | 943 | $parent_theme_info = array( |
944 | 944 | 'parent_name' => $parent_theme->name, |
945 | 945 | 'parent_version' => $parent_theme->version, |
946 | - 'parent_version_latest' => WC_Admin_Status::get_latest_theme_version( $parent_theme ), |
|
946 | + 'parent_version_latest' => WC_Admin_Status::get_latest_theme_version($parent_theme), |
|
947 | 947 | 'parent_author_url' => $parent_theme->{'Author URI'}, |
948 | 948 | ); |
949 | 949 | } else { |
@@ -961,34 +961,34 @@ discard block |
||
961 | 961 | */ |
962 | 962 | $override_files = array(); |
963 | 963 | $outdated_templates = false; |
964 | - $scan_files = WC_Admin_Status::scan_template_files( WC()->plugin_path() . '/templates/' ); |
|
965 | - foreach ( $scan_files as $file ) { |
|
966 | - $located = apply_filters( 'wc_get_template', $file, $file, array(), WC()->template_path(), WC()->plugin_path() . '/templates/' ); |
|
964 | + $scan_files = WC_Admin_Status::scan_template_files(WC()->plugin_path() . '/templates/'); |
|
965 | + foreach ($scan_files as $file) { |
|
966 | + $located = apply_filters('wc_get_template', $file, $file, array(), WC()->template_path(), WC()->plugin_path() . '/templates/'); |
|
967 | 967 | |
968 | - if ( file_exists( $located ) ) { |
|
968 | + if (file_exists($located)) { |
|
969 | 969 | $theme_file = $located; |
970 | - } elseif ( file_exists( get_stylesheet_directory() . '/' . $file ) ) { |
|
970 | + } elseif (file_exists(get_stylesheet_directory() . '/' . $file)) { |
|
971 | 971 | $theme_file = get_stylesheet_directory() . '/' . $file; |
972 | - } elseif ( file_exists( get_stylesheet_directory() . '/' . WC()->template_path() . $file ) ) { |
|
972 | + } elseif (file_exists(get_stylesheet_directory() . '/' . WC()->template_path() . $file)) { |
|
973 | 973 | $theme_file = get_stylesheet_directory() . '/' . WC()->template_path() . $file; |
974 | - } elseif ( file_exists( get_template_directory() . '/' . $file ) ) { |
|
974 | + } elseif (file_exists(get_template_directory() . '/' . $file)) { |
|
975 | 975 | $theme_file = get_template_directory() . '/' . $file; |
976 | - } elseif ( file_exists( get_template_directory() . '/' . WC()->template_path() . $file ) ) { |
|
976 | + } elseif (file_exists(get_template_directory() . '/' . WC()->template_path() . $file)) { |
|
977 | 977 | $theme_file = get_template_directory() . '/' . WC()->template_path() . $file; |
978 | 978 | } else { |
979 | 979 | $theme_file = false; |
980 | 980 | } |
981 | 981 | |
982 | - if ( ! empty( $theme_file ) ) { |
|
983 | - $core_version = WC_Admin_Status::get_file_version( WC()->plugin_path() . '/templates/' . $file ); |
|
984 | - $theme_version = WC_Admin_Status::get_file_version( $theme_file ); |
|
985 | - if ( $core_version && ( empty( $theme_version ) || version_compare( $theme_version, $core_version, '<' ) ) ) { |
|
986 | - if ( ! $outdated_templates ) { |
|
982 | + if ( ! empty($theme_file)) { |
|
983 | + $core_version = WC_Admin_Status::get_file_version(WC()->plugin_path() . '/templates/' . $file); |
|
984 | + $theme_version = WC_Admin_Status::get_file_version($theme_file); |
|
985 | + if ($core_version && (empty($theme_version) || version_compare($theme_version, $core_version, '<'))) { |
|
986 | + if ( ! $outdated_templates) { |
|
987 | 987 | $outdated_templates = true; |
988 | 988 | } |
989 | 989 | } |
990 | 990 | $override_files[] = array( |
991 | - 'file' => str_replace( WP_CONTENT_DIR . '/themes/', '', $theme_file ), |
|
991 | + 'file' => str_replace(WP_CONTENT_DIR . '/themes/', '', $theme_file), |
|
992 | 992 | 'version' => $theme_version, |
993 | 993 | 'core_version' => $core_version, |
994 | 994 | ); |
@@ -998,16 +998,16 @@ discard block |
||
998 | 998 | $active_theme_info = array( |
999 | 999 | 'name' => $active_theme->name, |
1000 | 1000 | 'version' => $active_theme->version, |
1001 | - 'version_latest' => WC_Admin_Status::get_latest_theme_version( $active_theme ), |
|
1002 | - 'author_url' => esc_url_raw( $active_theme->{'Author URI'} ), |
|
1001 | + 'version_latest' => WC_Admin_Status::get_latest_theme_version($active_theme), |
|
1002 | + 'author_url' => esc_url_raw($active_theme->{'Author URI'} ), |
|
1003 | 1003 | 'is_child_theme' => is_child_theme(), |
1004 | - 'has_woocommerce_support' => current_theme_supports( 'woocommerce' ), |
|
1005 | - 'has_woocommerce_file' => ( file_exists( get_stylesheet_directory() . '/woocommerce.php' ) || file_exists( get_template_directory() . '/woocommerce.php' ) ), |
|
1004 | + 'has_woocommerce_support' => current_theme_supports('woocommerce'), |
|
1005 | + 'has_woocommerce_file' => (file_exists(get_stylesheet_directory() . '/woocommerce.php') || file_exists(get_template_directory() . '/woocommerce.php')), |
|
1006 | 1006 | 'has_outdated_templates' => $outdated_templates, |
1007 | 1007 | 'overrides' => $override_files, |
1008 | 1008 | ); |
1009 | 1009 | |
1010 | - return array_merge( $active_theme_info, $parent_theme_info ); |
|
1010 | + return array_merge($active_theme_info, $parent_theme_info); |
|
1011 | 1011 | } |
1012 | 1012 | |
1013 | 1013 | /** |
@@ -1019,36 +1019,36 @@ discard block |
||
1019 | 1019 | public function get_settings() { |
1020 | 1020 | // Get a list of terms used for product/order taxonomies. |
1021 | 1021 | $term_response = array(); |
1022 | - $terms = get_terms( 'product_type', array( 'hide_empty' => 0 ) ); |
|
1023 | - foreach ( $terms as $term ) { |
|
1024 | - $term_response[ $term->slug ] = strtolower( $term->name ); |
|
1022 | + $terms = get_terms('product_type', array('hide_empty' => 0)); |
|
1023 | + foreach ($terms as $term) { |
|
1024 | + $term_response[$term->slug] = strtolower($term->name); |
|
1025 | 1025 | } |
1026 | 1026 | |
1027 | 1027 | // Get a list of terms used for product visibility. |
1028 | 1028 | $product_visibility_terms = array(); |
1029 | - $terms = get_terms( 'product_visibility', array( 'hide_empty' => 0 ) ); |
|
1030 | - foreach ( $terms as $term ) { |
|
1031 | - $product_visibility_terms[ $term->slug ] = strtolower( $term->name ); |
|
1029 | + $terms = get_terms('product_visibility', array('hide_empty' => 0)); |
|
1030 | + foreach ($terms as $term) { |
|
1031 | + $product_visibility_terms[$term->slug] = strtolower($term->name); |
|
1032 | 1032 | } |
1033 | 1033 | |
1034 | 1034 | // Check if WooCommerce.com account is connected. |
1035 | 1035 | $woo_com_connected = 'no'; |
1036 | - $helper_options = get_option( 'woocommerce_helper_data', array() ); |
|
1037 | - if ( array_key_exists( 'auth', $helper_options ) && ! empty( $helper_options['auth'] ) ) { |
|
1036 | + $helper_options = get_option('woocommerce_helper_data', array()); |
|
1037 | + if (array_key_exists('auth', $helper_options) && ! empty($helper_options['auth'])) { |
|
1038 | 1038 | $woo_com_connected = 'yes'; |
1039 | 1039 | } |
1040 | 1040 | |
1041 | 1041 | // Return array of useful settings for debugging. |
1042 | 1042 | return array( |
1043 | - 'api_enabled' => 'yes' === get_option( 'woocommerce_api_enabled' ), |
|
1044 | - 'force_ssl' => 'yes' === get_option( 'woocommerce_force_ssl_checkout' ), |
|
1043 | + 'api_enabled' => 'yes' === get_option('woocommerce_api_enabled'), |
|
1044 | + 'force_ssl' => 'yes' === get_option('woocommerce_force_ssl_checkout'), |
|
1045 | 1045 | 'currency' => get_woocommerce_currency(), |
1046 | 1046 | 'currency_symbol' => get_woocommerce_currency_symbol(), |
1047 | - 'currency_position' => get_option( 'woocommerce_currency_pos' ), |
|
1047 | + 'currency_position' => get_option('woocommerce_currency_pos'), |
|
1048 | 1048 | 'thousand_separator' => wc_get_price_thousand_separator(), |
1049 | 1049 | 'decimal_separator' => wc_get_price_decimal_separator(), |
1050 | 1050 | 'number_of_decimals' => wc_get_price_decimals(), |
1051 | - 'geolocation_enabled' => in_array( get_option( 'woocommerce_default_customer_address' ), array( 'geolocation_ajax', 'geolocation' ) ), |
|
1051 | + 'geolocation_enabled' => in_array(get_option('woocommerce_default_customer_address'), array('geolocation_ajax', 'geolocation')), |
|
1052 | 1052 | 'taxonomies' => $term_response, |
1053 | 1053 | 'product_visibility_terms' => $product_visibility_terms, |
1054 | 1054 | 'woocommerce_com_connected' => $woo_com_connected, |
@@ -1061,10 +1061,10 @@ discard block |
||
1061 | 1061 | * @return array |
1062 | 1062 | */ |
1063 | 1063 | public function get_security_info() { |
1064 | - $check_page = wc_get_page_permalink( 'shop' ); |
|
1064 | + $check_page = wc_get_page_permalink('shop'); |
|
1065 | 1065 | return array( |
1066 | - 'secure_connection' => 'https' === substr( $check_page, 0, 5 ), |
|
1067 | - 'hide_errors' => ! ( defined( 'WP_DEBUG' ) && defined( 'WP_DEBUG_DISPLAY' ) && WP_DEBUG && WP_DEBUG_DISPLAY ) || 0 === intval( ini_get( 'display_errors' ) ), |
|
1066 | + 'secure_connection' => 'https' === substr($check_page, 0, 5), |
|
1067 | + 'hide_errors' => ! (defined('WP_DEBUG') && defined('WP_DEBUG_DISPLAY') && WP_DEBUG && WP_DEBUG_DISPLAY) || 0 === intval(ini_get('display_errors')), |
|
1068 | 1068 | ); |
1069 | 1069 | } |
1070 | 1070 | |
@@ -1077,31 +1077,31 @@ discard block |
||
1077 | 1077 | public function get_pages() { |
1078 | 1078 | // WC pages to check against. |
1079 | 1079 | $check_pages = array( |
1080 | - _x( 'Shop base', 'Page setting', 'woocommerce' ) => array( |
|
1080 | + _x('Shop base', 'Page setting', 'woocommerce') => array( |
|
1081 | 1081 | 'option' => 'woocommerce_shop_page_id', |
1082 | 1082 | 'shortcode' => '', |
1083 | 1083 | ), |
1084 | - _x( 'Cart', 'Page setting', 'woocommerce' ) => array( |
|
1084 | + _x('Cart', 'Page setting', 'woocommerce') => array( |
|
1085 | 1085 | 'option' => 'woocommerce_cart_page_id', |
1086 | - 'shortcode' => '[' . apply_filters( 'woocommerce_cart_shortcode_tag', 'woocommerce_cart' ) . ']', |
|
1086 | + 'shortcode' => '[' . apply_filters('woocommerce_cart_shortcode_tag', 'woocommerce_cart') . ']', |
|
1087 | 1087 | ), |
1088 | - _x( 'Checkout', 'Page setting', 'woocommerce' ) => array( |
|
1088 | + _x('Checkout', 'Page setting', 'woocommerce') => array( |
|
1089 | 1089 | 'option' => 'woocommerce_checkout_page_id', |
1090 | - 'shortcode' => '[' . apply_filters( 'woocommerce_checkout_shortcode_tag', 'woocommerce_checkout' ) . ']', |
|
1090 | + 'shortcode' => '[' . apply_filters('woocommerce_checkout_shortcode_tag', 'woocommerce_checkout') . ']', |
|
1091 | 1091 | ), |
1092 | - _x( 'My account', 'Page setting', 'woocommerce' ) => array( |
|
1092 | + _x('My account', 'Page setting', 'woocommerce') => array( |
|
1093 | 1093 | 'option' => 'woocommerce_myaccount_page_id', |
1094 | - 'shortcode' => '[' . apply_filters( 'woocommerce_my_account_shortcode_tag', 'woocommerce_my_account' ) . ']', |
|
1094 | + 'shortcode' => '[' . apply_filters('woocommerce_my_account_shortcode_tag', 'woocommerce_my_account') . ']', |
|
1095 | 1095 | ), |
1096 | - _x( 'Terms and conditions', 'Page setting', 'woocommerce' ) => array( |
|
1096 | + _x('Terms and conditions', 'Page setting', 'woocommerce') => array( |
|
1097 | 1097 | 'option' => 'woocommerce_terms_page_id', |
1098 | 1098 | 'shortcode' => '', |
1099 | 1099 | ), |
1100 | 1100 | ); |
1101 | 1101 | |
1102 | 1102 | $pages_output = array(); |
1103 | - foreach ( $check_pages as $page_name => $values ) { |
|
1104 | - $page_id = get_option( $values['option'] ); |
|
1103 | + foreach ($check_pages as $page_name => $values) { |
|
1104 | + $page_id = get_option($values['option']); |
|
1105 | 1105 | $page_set = false; |
1106 | 1106 | $page_exists = false; |
1107 | 1107 | $page_visible = false; |
@@ -1109,21 +1109,21 @@ discard block |
||
1109 | 1109 | $shortcode_required = false; |
1110 | 1110 | |
1111 | 1111 | // Page checks. |
1112 | - if ( $page_id ) { |
|
1112 | + if ($page_id) { |
|
1113 | 1113 | $page_set = true; |
1114 | 1114 | } |
1115 | - if ( get_post( $page_id ) ) { |
|
1115 | + if (get_post($page_id)) { |
|
1116 | 1116 | $page_exists = true; |
1117 | 1117 | } |
1118 | - if ( 'publish' === get_post_status( $page_id ) ) { |
|
1118 | + if ('publish' === get_post_status($page_id)) { |
|
1119 | 1119 | $page_visible = true; |
1120 | 1120 | } |
1121 | 1121 | |
1122 | 1122 | // Shortcode checks. |
1123 | - if ( $values['shortcode'] && get_post( $page_id ) ) { |
|
1123 | + if ($values['shortcode'] && get_post($page_id)) { |
|
1124 | 1124 | $shortcode_required = true; |
1125 | - $page = get_post( $page_id ); |
|
1126 | - if ( strstr( $page->post_content, $values['shortcode'] ) ) { |
|
1125 | + $page = get_post($page_id); |
|
1126 | + if (strstr($page->post_content, $values['shortcode'])) { |
|
1127 | 1127 | $shortcode_present = true; |
1128 | 1128 | } |
1129 | 1129 | } |
@@ -1151,7 +1151,7 @@ discard block |
||
1151 | 1151 | */ |
1152 | 1152 | public function get_collection_params() { |
1153 | 1153 | return array( |
1154 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
1154 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
1155 | 1155 | ); |
1156 | 1156 | } |
1157 | 1157 | |
@@ -1162,11 +1162,11 @@ discard block |
||
1162 | 1162 | * @param WP_REST_Request $request Request object. |
1163 | 1163 | * @return WP_REST_Response |
1164 | 1164 | */ |
1165 | - public function prepare_item_for_response( $system_status, $request ) { |
|
1166 | - $data = $this->add_additional_fields_to_object( $system_status, $request ); |
|
1167 | - $data = $this->filter_response_by_context( $data, 'view' ); |
|
1165 | + public function prepare_item_for_response($system_status, $request) { |
|
1166 | + $data = $this->add_additional_fields_to_object($system_status, $request); |
|
1167 | + $data = $this->filter_response_by_context($data, 'view'); |
|
1168 | 1168 | |
1169 | - $response = rest_ensure_response( $data ); |
|
1169 | + $response = rest_ensure_response($data); |
|
1170 | 1170 | |
1171 | 1171 | /** |
1172 | 1172 | * Filter the system status returned from the REST API. |
@@ -1175,6 +1175,6 @@ discard block |
||
1175 | 1175 | * @param mixed $system_status System status |
1176 | 1176 | * @param WP_REST_Request $request Request object. |
1177 | 1177 | */ |
1178 | - return apply_filters( 'woocommerce_rest_prepare_system_status', $response, $system_status, $request ); |
|
1178 | + return apply_filters('woocommerce_rest_prepare_system_status', $response, $system_status, $request); |
|
1179 | 1179 | } |
1180 | 1180 | } |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * @since 2.6.0 |
9 | 9 | */ |
10 | 10 | |
11 | -defined( 'ABSPATH' ) || exit; |
|
11 | +defined('ABSPATH') || exit; |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * REST API Product Categories controller class. |
@@ -32,12 +32,12 @@ discard block |
||
32 | 32 | * @param WP_REST_Request $request Request instance. |
33 | 33 | * @return WP_REST_Response |
34 | 34 | */ |
35 | - public function prepare_item_for_response( $item, $request ) { |
|
35 | + public function prepare_item_for_response($item, $request) { |
|
36 | 36 | // Get category display type. |
37 | - $display_type = get_term_meta( $item->term_id, 'display_type', true ); |
|
37 | + $display_type = get_term_meta($item->term_id, 'display_type', true); |
|
38 | 38 | |
39 | 39 | // Get category order. |
40 | - $menu_order = get_term_meta( $item->term_id, 'order', true ); |
|
40 | + $menu_order = get_term_meta($item->term_id, 'order', true); |
|
41 | 41 | |
42 | 42 | $data = array( |
43 | 43 | 'id' => (int) $item->term_id, |
@@ -52,29 +52,29 @@ discard block |
||
52 | 52 | ); |
53 | 53 | |
54 | 54 | // Get category image. |
55 | - $image_id = get_term_meta( $item->term_id, 'thumbnail_id', true ); |
|
56 | - if ( $image_id ) { |
|
57 | - $attachment = get_post( $image_id ); |
|
55 | + $image_id = get_term_meta($item->term_id, 'thumbnail_id', true); |
|
56 | + if ($image_id) { |
|
57 | + $attachment = get_post($image_id); |
|
58 | 58 | |
59 | 59 | $data['image'] = array( |
60 | 60 | 'id' => (int) $image_id, |
61 | - 'date_created' => wc_rest_prepare_date_response( $attachment->post_date ), |
|
62 | - 'date_created_gmt' => wc_rest_prepare_date_response( $attachment->post_date_gmt ), |
|
63 | - 'date_modified' => wc_rest_prepare_date_response( $attachment->post_modified ), |
|
64 | - 'date_modified_gmt' => wc_rest_prepare_date_response( $attachment->post_modified_gmt ), |
|
65 | - 'src' => wp_get_attachment_url( $image_id ), |
|
66 | - 'title' => get_the_title( $attachment ), |
|
67 | - 'alt' => get_post_meta( $image_id, '_wp_attachment_image_alt', true ), |
|
61 | + 'date_created' => wc_rest_prepare_date_response($attachment->post_date), |
|
62 | + 'date_created_gmt' => wc_rest_prepare_date_response($attachment->post_date_gmt), |
|
63 | + 'date_modified' => wc_rest_prepare_date_response($attachment->post_modified), |
|
64 | + 'date_modified_gmt' => wc_rest_prepare_date_response($attachment->post_modified_gmt), |
|
65 | + 'src' => wp_get_attachment_url($image_id), |
|
66 | + 'title' => get_the_title($attachment), |
|
67 | + 'alt' => get_post_meta($image_id, '_wp_attachment_image_alt', true), |
|
68 | 68 | ); |
69 | 69 | } |
70 | 70 | |
71 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
72 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
73 | - $data = $this->filter_response_by_context( $data, $context ); |
|
71 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
72 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
73 | + $data = $this->filter_response_by_context($data, $context); |
|
74 | 74 | |
75 | - $response = rest_ensure_response( $data ); |
|
75 | + $response = rest_ensure_response($data); |
|
76 | 76 | |
77 | - $response->add_links( $this->prepare_links( $item, $request ) ); |
|
77 | + $response->add_links($this->prepare_links($item, $request)); |
|
78 | 78 | |
79 | 79 | /** |
80 | 80 | * Filter a term item returned from the API. |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | * @param object $item The original term object. |
86 | 86 | * @param WP_REST_Request $request Request used to generate the response. |
87 | 87 | */ |
88 | - return apply_filters( "woocommerce_rest_prepare_{$this->taxonomy}", $response, $item, $request ); |
|
88 | + return apply_filters("woocommerce_rest_prepare_{$this->taxonomy}", $response, $item, $request); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | /** |
@@ -100,113 +100,113 @@ discard block |
||
100 | 100 | 'type' => 'object', |
101 | 101 | 'properties' => array( |
102 | 102 | 'id' => array( |
103 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
103 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
104 | 104 | 'type' => 'integer', |
105 | - 'context' => array( 'view', 'edit' ), |
|
105 | + 'context' => array('view', 'edit'), |
|
106 | 106 | 'readonly' => true, |
107 | 107 | ), |
108 | 108 | 'name' => array( |
109 | - 'description' => __( 'Category name.', 'woocommerce' ), |
|
109 | + 'description' => __('Category name.', 'woocommerce'), |
|
110 | 110 | 'type' => 'string', |
111 | - 'context' => array( 'view', 'edit' ), |
|
111 | + 'context' => array('view', 'edit'), |
|
112 | 112 | 'arg_options' => array( |
113 | 113 | 'sanitize_callback' => 'sanitize_text_field', |
114 | 114 | ), |
115 | 115 | ), |
116 | 116 | 'slug' => array( |
117 | - 'description' => __( 'An alphanumeric identifier for the resource unique to its type.', 'woocommerce' ), |
|
117 | + 'description' => __('An alphanumeric identifier for the resource unique to its type.', 'woocommerce'), |
|
118 | 118 | 'type' => 'string', |
119 | - 'context' => array( 'view', 'edit' ), |
|
119 | + 'context' => array('view', 'edit'), |
|
120 | 120 | 'arg_options' => array( |
121 | 121 | 'sanitize_callback' => 'sanitize_title', |
122 | 122 | ), |
123 | 123 | ), |
124 | 124 | 'parent' => array( |
125 | - 'description' => __( 'The ID for the parent of the resource.', 'woocommerce' ), |
|
125 | + 'description' => __('The ID for the parent of the resource.', 'woocommerce'), |
|
126 | 126 | 'type' => 'integer', |
127 | - 'context' => array( 'view', 'edit' ), |
|
127 | + 'context' => array('view', 'edit'), |
|
128 | 128 | ), |
129 | 129 | 'description' => array( |
130 | - 'description' => __( 'HTML description of the resource.', 'woocommerce' ), |
|
130 | + 'description' => __('HTML description of the resource.', 'woocommerce'), |
|
131 | 131 | 'type' => 'string', |
132 | - 'context' => array( 'view', 'edit' ), |
|
132 | + 'context' => array('view', 'edit'), |
|
133 | 133 | 'arg_options' => array( |
134 | 134 | 'sanitize_callback' => 'wp_filter_post_kses', |
135 | 135 | ), |
136 | 136 | ), |
137 | 137 | 'display' => array( |
138 | - 'description' => __( 'Category archive display type.', 'woocommerce' ), |
|
138 | + 'description' => __('Category archive display type.', 'woocommerce'), |
|
139 | 139 | 'type' => 'string', |
140 | 140 | 'default' => 'default', |
141 | - 'enum' => array( 'default', 'products', 'subcategories', 'both' ), |
|
142 | - 'context' => array( 'view', 'edit' ), |
|
141 | + 'enum' => array('default', 'products', 'subcategories', 'both'), |
|
142 | + 'context' => array('view', 'edit'), |
|
143 | 143 | ), |
144 | 144 | 'image' => array( |
145 | - 'description' => __( 'Image data.', 'woocommerce' ), |
|
145 | + 'description' => __('Image data.', 'woocommerce'), |
|
146 | 146 | 'type' => 'object', |
147 | - 'context' => array( 'view', 'edit' ), |
|
147 | + 'context' => array('view', 'edit'), |
|
148 | 148 | 'properties' => array( |
149 | 149 | 'id' => array( |
150 | - 'description' => __( 'Image ID.', 'woocommerce' ), |
|
150 | + 'description' => __('Image ID.', 'woocommerce'), |
|
151 | 151 | 'type' => 'integer', |
152 | - 'context' => array( 'view', 'edit' ), |
|
152 | + 'context' => array('view', 'edit'), |
|
153 | 153 | ), |
154 | 154 | 'date_created' => array( |
155 | - 'description' => __( "The date the image was created, in the site's timezone.", 'woocommerce' ), |
|
155 | + 'description' => __("The date the image was created, in the site's timezone.", 'woocommerce'), |
|
156 | 156 | 'type' => 'date-time', |
157 | - 'context' => array( 'view', 'edit' ), |
|
157 | + 'context' => array('view', 'edit'), |
|
158 | 158 | 'readonly' => true, |
159 | 159 | ), |
160 | 160 | 'date_created_gmt' => array( |
161 | - 'description' => __( 'The date the image was created, as GMT.', 'woocommerce' ), |
|
161 | + 'description' => __('The date the image was created, as GMT.', 'woocommerce'), |
|
162 | 162 | 'type' => 'date-time', |
163 | - 'context' => array( 'view', 'edit' ), |
|
163 | + 'context' => array('view', 'edit'), |
|
164 | 164 | 'readonly' => true, |
165 | 165 | ), |
166 | 166 | 'date_modified' => array( |
167 | - 'description' => __( "The date the image was last modified, in the site's timezone.", 'woocommerce' ), |
|
167 | + 'description' => __("The date the image was last modified, in the site's timezone.", 'woocommerce'), |
|
168 | 168 | 'type' => 'date-time', |
169 | - 'context' => array( 'view', 'edit' ), |
|
169 | + 'context' => array('view', 'edit'), |
|
170 | 170 | 'readonly' => true, |
171 | 171 | ), |
172 | 172 | 'date_modified_gmt' => array( |
173 | - 'description' => __( 'The date the image was last modified, as GMT.', 'woocommerce' ), |
|
173 | + 'description' => __('The date the image was last modified, as GMT.', 'woocommerce'), |
|
174 | 174 | 'type' => 'date-time', |
175 | - 'context' => array( 'view', 'edit' ), |
|
175 | + 'context' => array('view', 'edit'), |
|
176 | 176 | 'readonly' => true, |
177 | 177 | ), |
178 | 178 | 'src' => array( |
179 | - 'description' => __( 'Image URL.', 'woocommerce' ), |
|
179 | + 'description' => __('Image URL.', 'woocommerce'), |
|
180 | 180 | 'type' => 'string', |
181 | 181 | 'format' => 'uri', |
182 | - 'context' => array( 'view', 'edit' ), |
|
182 | + 'context' => array('view', 'edit'), |
|
183 | 183 | ), |
184 | 184 | 'title' => array( |
185 | - 'description' => __( 'Image name.', 'woocommerce' ), |
|
185 | + 'description' => __('Image name.', 'woocommerce'), |
|
186 | 186 | 'type' => 'string', |
187 | - 'context' => array( 'view', 'edit' ), |
|
187 | + 'context' => array('view', 'edit'), |
|
188 | 188 | ), |
189 | 189 | 'alt' => array( |
190 | - 'description' => __( 'Image alternative text.', 'woocommerce' ), |
|
190 | + 'description' => __('Image alternative text.', 'woocommerce'), |
|
191 | 191 | 'type' => 'string', |
192 | - 'context' => array( 'view', 'edit' ), |
|
192 | + 'context' => array('view', 'edit'), |
|
193 | 193 | ), |
194 | 194 | ), |
195 | 195 | ), |
196 | 196 | 'menu_order' => array( |
197 | - 'description' => __( 'Menu order, used to custom sort the resource.', 'woocommerce' ), |
|
197 | + 'description' => __('Menu order, used to custom sort the resource.', 'woocommerce'), |
|
198 | 198 | 'type' => 'integer', |
199 | - 'context' => array( 'view', 'edit' ), |
|
199 | + 'context' => array('view', 'edit'), |
|
200 | 200 | ), |
201 | 201 | 'count' => array( |
202 | - 'description' => __( 'Number of published products for the resource.', 'woocommerce' ), |
|
202 | + 'description' => __('Number of published products for the resource.', 'woocommerce'), |
|
203 | 203 | 'type' => 'integer', |
204 | - 'context' => array( 'view', 'edit' ), |
|
204 | + 'context' => array('view', 'edit'), |
|
205 | 205 | 'readonly' => true, |
206 | 206 | ), |
207 | 207 | ), |
208 | 208 | ); |
209 | 209 | |
210 | - return $this->add_additional_fields_schema( $schema ); |
|
210 | + return $this->add_additional_fields_schema($schema); |
|
211 | 211 | } |
212 | 212 | } |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * @since 3.0.0 |
9 | 9 | */ |
10 | 10 | |
11 | -defined( 'ABSPATH' ) || exit; |
|
11 | +defined('ABSPATH') || exit; |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * REST API Shipping Zone Methods class. |
@@ -26,30 +26,30 @@ discard block |
||
26 | 26 | $this->namespace, '/' . $this->rest_base . '/(?P<zone_id>[\d]+)/methods', array( |
27 | 27 | 'args' => array( |
28 | 28 | 'zone_id' => array( |
29 | - 'description' => __( 'Unique ID for the zone.', 'woocommerce' ), |
|
29 | + 'description' => __('Unique ID for the zone.', 'woocommerce'), |
|
30 | 30 | 'type' => 'integer', |
31 | 31 | ), |
32 | 32 | ), |
33 | 33 | array( |
34 | 34 | 'methods' => WP_REST_Server::READABLE, |
35 | - 'callback' => array( $this, 'get_items' ), |
|
36 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
35 | + 'callback' => array($this, 'get_items'), |
|
36 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
37 | 37 | ), |
38 | 38 | array( |
39 | 39 | 'methods' => WP_REST_Server::CREATABLE, |
40 | - 'callback' => array( $this, 'create_item' ), |
|
41 | - 'permission_callback' => array( $this, 'create_item_permissions_check' ), |
|
40 | + 'callback' => array($this, 'create_item'), |
|
41 | + 'permission_callback' => array($this, 'create_item_permissions_check'), |
|
42 | 42 | 'args' => array_merge( |
43 | - $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), array( |
|
43 | + $this->get_endpoint_args_for_item_schema(WP_REST_Server::CREATABLE), array( |
|
44 | 44 | 'method_id' => array( |
45 | 45 | 'required' => true, |
46 | 46 | 'readonly' => false, |
47 | - 'description' => __( 'Shipping method ID.', 'woocommerce' ), |
|
47 | + 'description' => __('Shipping method ID.', 'woocommerce'), |
|
48 | 48 | ), |
49 | 49 | ) |
50 | 50 | ), |
51 | 51 | ), |
52 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
52 | + 'schema' => array($this, 'get_public_item_schema'), |
|
53 | 53 | ) |
54 | 54 | ); |
55 | 55 | |
@@ -57,38 +57,38 @@ discard block |
||
57 | 57 | $this->namespace, '/' . $this->rest_base . '/(?P<zone_id>[\d]+)/methods/(?P<instance_id>[\d]+)', array( |
58 | 58 | 'args' => array( |
59 | 59 | 'zone_id' => array( |
60 | - 'description' => __( 'Unique ID for the zone.', 'woocommerce' ), |
|
60 | + 'description' => __('Unique ID for the zone.', 'woocommerce'), |
|
61 | 61 | 'type' => 'integer', |
62 | 62 | ), |
63 | 63 | 'instance_id' => array( |
64 | - 'description' => __( 'Unique ID for the instance.', 'woocommerce' ), |
|
64 | + 'description' => __('Unique ID for the instance.', 'woocommerce'), |
|
65 | 65 | 'type' => 'integer', |
66 | 66 | ), |
67 | 67 | ), |
68 | 68 | array( |
69 | 69 | 'methods' => WP_REST_Server::READABLE, |
70 | - 'callback' => array( $this, 'get_item' ), |
|
71 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
70 | + 'callback' => array($this, 'get_item'), |
|
71 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
72 | 72 | ), |
73 | 73 | array( |
74 | 74 | 'methods' => WP_REST_Server::EDITABLE, |
75 | - 'callback' => array( $this, 'update_item' ), |
|
76 | - 'permission_callback' => array( $this, 'update_items_permissions_check' ), |
|
77 | - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), |
|
75 | + 'callback' => array($this, 'update_item'), |
|
76 | + 'permission_callback' => array($this, 'update_items_permissions_check'), |
|
77 | + 'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE), |
|
78 | 78 | ), |
79 | 79 | array( |
80 | 80 | 'methods' => WP_REST_Server::DELETABLE, |
81 | - 'callback' => array( $this, 'delete_item' ), |
|
82 | - 'permission_callback' => array( $this, 'delete_items_permissions_check' ), |
|
81 | + 'callback' => array($this, 'delete_item'), |
|
82 | + 'permission_callback' => array($this, 'delete_items_permissions_check'), |
|
83 | 83 | 'args' => array( |
84 | 84 | 'force' => array( |
85 | 85 | 'default' => false, |
86 | 86 | 'type' => 'boolean', |
87 | - 'description' => __( 'Whether to bypass trash and force deletion.', 'woocommerce' ), |
|
87 | + 'description' => __('Whether to bypass trash and force deletion.', 'woocommerce'), |
|
88 | 88 | ), |
89 | 89 | ), |
90 | 90 | ), |
91 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
91 | + 'schema' => array($this, 'get_public_item_schema'), |
|
92 | 92 | ) |
93 | 93 | ); |
94 | 94 | } |
@@ -99,10 +99,10 @@ discard block |
||
99 | 99 | * @param WP_REST_Request $request Request data. |
100 | 100 | * @return WP_REST_Response|WP_Error |
101 | 101 | */ |
102 | - public function get_item( $request ) { |
|
103 | - $zone = $this->get_zone( $request['zone_id'] ); |
|
102 | + public function get_item($request) { |
|
103 | + $zone = $this->get_zone($request['zone_id']); |
|
104 | 104 | |
105 | - if ( is_wp_error( $zone ) ) { |
|
105 | + if (is_wp_error($zone)) { |
|
106 | 106 | return $zone; |
107 | 107 | } |
108 | 108 | |
@@ -110,20 +110,20 @@ discard block |
||
110 | 110 | $methods = $zone->get_shipping_methods(); |
111 | 111 | $method = false; |
112 | 112 | |
113 | - foreach ( $methods as $method_obj ) { |
|
114 | - if ( $instance_id === $method_obj->instance_id ) { |
|
113 | + foreach ($methods as $method_obj) { |
|
114 | + if ($instance_id === $method_obj->instance_id) { |
|
115 | 115 | $method = $method_obj; |
116 | 116 | break; |
117 | 117 | } |
118 | 118 | } |
119 | 119 | |
120 | - if ( false === $method ) { |
|
121 | - return new WP_Error( 'woocommerce_rest_shipping_zone_method_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
120 | + if (false === $method) { |
|
121 | + return new WP_Error('woocommerce_rest_shipping_zone_method_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404)); |
|
122 | 122 | } |
123 | 123 | |
124 | - $data = $this->prepare_item_for_response( $method, $request ); |
|
124 | + $data = $this->prepare_item_for_response($method, $request); |
|
125 | 125 | |
126 | - return rest_ensure_response( $data ); |
|
126 | + return rest_ensure_response($data); |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | /** |
@@ -132,22 +132,22 @@ discard block |
||
132 | 132 | * @param WP_REST_Request $request Request data. |
133 | 133 | * @return WP_REST_Response|WP_Error |
134 | 134 | */ |
135 | - public function get_items( $request ) { |
|
136 | - $zone = $this->get_zone( $request['zone_id'] ); |
|
135 | + public function get_items($request) { |
|
136 | + $zone = $this->get_zone($request['zone_id']); |
|
137 | 137 | |
138 | - if ( is_wp_error( $zone ) ) { |
|
138 | + if (is_wp_error($zone)) { |
|
139 | 139 | return $zone; |
140 | 140 | } |
141 | 141 | |
142 | 142 | $methods = $zone->get_shipping_methods(); |
143 | 143 | $data = array(); |
144 | 144 | |
145 | - foreach ( $methods as $method_obj ) { |
|
146 | - $method = $this->prepare_item_for_response( $method_obj, $request ); |
|
145 | + foreach ($methods as $method_obj) { |
|
146 | + $method = $this->prepare_item_for_response($method_obj, $request); |
|
147 | 147 | $data[] = $method; |
148 | 148 | } |
149 | 149 | |
150 | - return rest_ensure_response( $data ); |
|
150 | + return rest_ensure_response($data); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | /** |
@@ -156,34 +156,34 @@ discard block |
||
156 | 156 | * @param WP_REST_Request $request Full details about the request. |
157 | 157 | * @return WP_REST_Request|WP_Error |
158 | 158 | */ |
159 | - public function create_item( $request ) { |
|
159 | + public function create_item($request) { |
|
160 | 160 | $method_id = $request['method_id']; |
161 | - $zone = $this->get_zone( $request['zone_id'] ); |
|
162 | - if ( is_wp_error( $zone ) ) { |
|
161 | + $zone = $this->get_zone($request['zone_id']); |
|
162 | + if (is_wp_error($zone)) { |
|
163 | 163 | return $zone; |
164 | 164 | } |
165 | 165 | |
166 | - $instance_id = $zone->add_shipping_method( $method_id ); |
|
166 | + $instance_id = $zone->add_shipping_method($method_id); |
|
167 | 167 | $methods = $zone->get_shipping_methods(); |
168 | 168 | $method = false; |
169 | - foreach ( $methods as $method_obj ) { |
|
170 | - if ( $instance_id === $method_obj->instance_id ) { |
|
169 | + foreach ($methods as $method_obj) { |
|
170 | + if ($instance_id === $method_obj->instance_id) { |
|
171 | 171 | $method = $method_obj; |
172 | 172 | break; |
173 | 173 | } |
174 | 174 | } |
175 | 175 | |
176 | - if ( false === $method ) { |
|
177 | - return new WP_Error( 'woocommerce_rest_shipping_zone_not_created', __( 'Resource cannot be created.', 'woocommerce' ), array( 'status' => 500 ) ); |
|
176 | + if (false === $method) { |
|
177 | + return new WP_Error('woocommerce_rest_shipping_zone_not_created', __('Resource cannot be created.', 'woocommerce'), array('status' => 500)); |
|
178 | 178 | } |
179 | 179 | |
180 | - $method = $this->update_fields( $instance_id, $method, $request ); |
|
181 | - if ( is_wp_error( $method ) ) { |
|
180 | + $method = $this->update_fields($instance_id, $method, $request); |
|
181 | + if (is_wp_error($method)) { |
|
182 | 182 | return $method; |
183 | 183 | } |
184 | 184 | |
185 | - $data = $this->prepare_item_for_response( $method, $request ); |
|
186 | - return rest_ensure_response( $data ); |
|
185 | + $data = $this->prepare_item_for_response($method, $request); |
|
186 | + return rest_ensure_response($data); |
|
187 | 187 | } |
188 | 188 | |
189 | 189 | /** |
@@ -192,9 +192,9 @@ discard block |
||
192 | 192 | * @param WP_REST_Request $request Full details about the request. |
193 | 193 | * @return WP_Error|boolean |
194 | 194 | */ |
195 | - public function delete_item( $request ) { |
|
196 | - $zone = $this->get_zone( $request['zone_id'] ); |
|
197 | - if ( is_wp_error( $zone ) ) { |
|
195 | + public function delete_item($request) { |
|
196 | + $zone = $this->get_zone($request['zone_id']); |
|
197 | + if (is_wp_error($zone)) { |
|
198 | 198 | return $zone; |
199 | 199 | } |
200 | 200 | |
@@ -204,30 +204,30 @@ discard block |
||
204 | 204 | $methods = $zone->get_shipping_methods(); |
205 | 205 | $method = false; |
206 | 206 | |
207 | - foreach ( $methods as $method_obj ) { |
|
208 | - if ( $instance_id === $method_obj->instance_id ) { |
|
207 | + foreach ($methods as $method_obj) { |
|
208 | + if ($instance_id === $method_obj->instance_id) { |
|
209 | 209 | $method = $method_obj; |
210 | 210 | break; |
211 | 211 | } |
212 | 212 | } |
213 | 213 | |
214 | - if ( false === $method ) { |
|
215 | - return new WP_Error( 'woocommerce_rest_shipping_zone_method_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
214 | + if (false === $method) { |
|
215 | + return new WP_Error('woocommerce_rest_shipping_zone_method_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404)); |
|
216 | 216 | } |
217 | 217 | |
218 | - $method = $this->update_fields( $instance_id, $method, $request ); |
|
219 | - if ( is_wp_error( $method ) ) { |
|
218 | + $method = $this->update_fields($instance_id, $method, $request); |
|
219 | + if (is_wp_error($method)) { |
|
220 | 220 | return $method; |
221 | 221 | } |
222 | 222 | |
223 | - $request->set_param( 'context', 'view' ); |
|
224 | - $response = $this->prepare_item_for_response( $method, $request ); |
|
223 | + $request->set_param('context', 'view'); |
|
224 | + $response = $this->prepare_item_for_response($method, $request); |
|
225 | 225 | |
226 | 226 | // Actually delete. |
227 | - if ( $force ) { |
|
228 | - $zone->delete_shipping_method( $instance_id ); |
|
227 | + if ($force) { |
|
228 | + $zone->delete_shipping_method($instance_id); |
|
229 | 229 | } else { |
230 | - return new WP_Error( 'rest_trash_not_supported', __( 'Shipping methods do not support trashing.', 'woocommerce' ), array( 'status' => 501 ) ); |
|
230 | + return new WP_Error('rest_trash_not_supported', __('Shipping methods do not support trashing.', 'woocommerce'), array('status' => 501)); |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | /** |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | * @param WP_REST_Response $response The response data. |
238 | 238 | * @param WP_REST_Request $request The request sent to the API. |
239 | 239 | */ |
240 | - do_action( 'rest_delete_product_review', $method, $response, $request ); |
|
240 | + do_action('rest_delete_product_review', $method, $response, $request); |
|
241 | 241 | |
242 | 242 | return $response; |
243 | 243 | } |
@@ -248,9 +248,9 @@ discard block |
||
248 | 248 | * @param WP_REST_Request $request Request data. |
249 | 249 | * @return WP_REST_Response|WP_Error |
250 | 250 | */ |
251 | - public function update_item( $request ) { |
|
252 | - $zone = $this->get_zone( $request['zone_id'] ); |
|
253 | - if ( is_wp_error( $zone ) ) { |
|
251 | + public function update_item($request) { |
|
252 | + $zone = $this->get_zone($request['zone_id']); |
|
253 | + if (is_wp_error($zone)) { |
|
254 | 254 | return $zone; |
255 | 255 | } |
256 | 256 | |
@@ -258,24 +258,24 @@ discard block |
||
258 | 258 | $methods = $zone->get_shipping_methods(); |
259 | 259 | $method = false; |
260 | 260 | |
261 | - foreach ( $methods as $method_obj ) { |
|
262 | - if ( $instance_id === $method_obj->instance_id ) { |
|
261 | + foreach ($methods as $method_obj) { |
|
262 | + if ($instance_id === $method_obj->instance_id) { |
|
263 | 263 | $method = $method_obj; |
264 | 264 | break; |
265 | 265 | } |
266 | 266 | } |
267 | 267 | |
268 | - if ( false === $method ) { |
|
269 | - return new WP_Error( 'woocommerce_rest_shipping_zone_method_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
268 | + if (false === $method) { |
|
269 | + return new WP_Error('woocommerce_rest_shipping_zone_method_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404)); |
|
270 | 270 | } |
271 | 271 | |
272 | - $method = $this->update_fields( $instance_id, $method, $request ); |
|
273 | - if ( is_wp_error( $method ) ) { |
|
272 | + $method = $this->update_fields($instance_id, $method, $request); |
|
273 | + if (is_wp_error($method)) { |
|
274 | 274 | return $method; |
275 | 275 | } |
276 | 276 | |
277 | - $data = $this->prepare_item_for_response( $method, $request ); |
|
278 | - return rest_ensure_response( $data ); |
|
277 | + $data = $this->prepare_item_for_response($method, $request); |
|
278 | + return rest_ensure_response($data); |
|
279 | 279 | } |
280 | 280 | |
281 | 281 | /** |
@@ -287,47 +287,47 @@ discard block |
||
287 | 287 | * |
288 | 288 | * @return WC_Shipping_Method |
289 | 289 | */ |
290 | - public function update_fields( $instance_id, $method, $request ) { |
|
290 | + public function update_fields($instance_id, $method, $request) { |
|
291 | 291 | global $wpdb; |
292 | 292 | |
293 | 293 | // Update settings if present. |
294 | - if ( isset( $request['settings'] ) ) { |
|
294 | + if (isset($request['settings'])) { |
|
295 | 295 | $method->init_instance_settings(); |
296 | 296 | $instance_settings = $method->instance_settings; |
297 | 297 | $errors_found = false; |
298 | - foreach ( $method->get_instance_form_fields() as $key => $field ) { |
|
299 | - if ( isset( $request['settings'][ $key ] ) ) { |
|
300 | - if ( is_callable( array( $this, 'validate_setting_' . $field['type'] . '_field' ) ) ) { |
|
301 | - $value = $this->{'validate_setting_' . $field['type'] . '_field'}( $request['settings'][ $key ], $field ); |
|
298 | + foreach ($method->get_instance_form_fields() as $key => $field) { |
|
299 | + if (isset($request['settings'][$key])) { |
|
300 | + if (is_callable(array($this, 'validate_setting_' . $field['type'] . '_field'))) { |
|
301 | + $value = $this->{'validate_setting_' . $field['type'] . '_field'}($request['settings'][$key], $field); |
|
302 | 302 | } else { |
303 | - $value = $this->validate_setting_text_field( $request['settings'][ $key ], $field ); |
|
303 | + $value = $this->validate_setting_text_field($request['settings'][$key], $field); |
|
304 | 304 | } |
305 | - if ( is_wp_error( $value ) ) { |
|
305 | + if (is_wp_error($value)) { |
|
306 | 306 | $errors_found = true; |
307 | 307 | break; |
308 | 308 | } |
309 | - $instance_settings[ $key ] = $value; |
|
309 | + $instance_settings[$key] = $value; |
|
310 | 310 | } |
311 | 311 | } |
312 | 312 | |
313 | - if ( $errors_found ) { |
|
314 | - return new WP_Error( 'rest_setting_value_invalid', __( 'An invalid setting value was passed.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
313 | + if ($errors_found) { |
|
314 | + return new WP_Error('rest_setting_value_invalid', __('An invalid setting value was passed.', 'woocommerce'), array('status' => 400)); |
|
315 | 315 | } |
316 | 316 | |
317 | - update_option( $method->get_instance_option_key(), apply_filters( 'woocommerce_shipping_' . $method->id . '_instance_settings_values', $instance_settings, $method ) ); |
|
317 | + update_option($method->get_instance_option_key(), apply_filters('woocommerce_shipping_' . $method->id . '_instance_settings_values', $instance_settings, $method)); |
|
318 | 318 | } |
319 | 319 | |
320 | 320 | // Update order. |
321 | - if ( isset( $request['order'] ) ) { |
|
322 | - $wpdb->update( "{$wpdb->prefix}woocommerce_shipping_zone_methods", array( 'method_order' => absint( $request['order'] ) ), array( 'instance_id' => absint( $instance_id ) ) ); |
|
323 | - $method->method_order = absint( $request['order'] ); |
|
321 | + if (isset($request['order'])) { |
|
322 | + $wpdb->update("{$wpdb->prefix}woocommerce_shipping_zone_methods", array('method_order' => absint($request['order'])), array('instance_id' => absint($instance_id))); |
|
323 | + $method->method_order = absint($request['order']); |
|
324 | 324 | } |
325 | 325 | |
326 | 326 | // Update if this method is enabled or not. |
327 | - if ( isset( $request['enabled'] ) ) { |
|
328 | - if ( $wpdb->update( "{$wpdb->prefix}woocommerce_shipping_zone_methods", array( 'is_enabled' => $request['enabled'] ), array( 'instance_id' => absint( $instance_id ) ) ) ) { |
|
329 | - do_action( 'woocommerce_shipping_zone_method_status_toggled', $instance_id, $method->id, $request['zone_id'], $request['enabled'] ); |
|
330 | - $method->enabled = ( true === $request['enabled'] ? 'yes' : 'no' ); |
|
327 | + if (isset($request['enabled'])) { |
|
328 | + if ($wpdb->update("{$wpdb->prefix}woocommerce_shipping_zone_methods", array('is_enabled' => $request['enabled']), array('instance_id' => absint($instance_id)))) { |
|
329 | + do_action('woocommerce_shipping_zone_method_status_toggled', $instance_id, $method->id, $request['zone_id'], $request['enabled']); |
|
330 | + $method->enabled = (true === $request['enabled'] ? 'yes' : 'no'); |
|
331 | 331 | } |
332 | 332 | } |
333 | 333 | |
@@ -341,29 +341,29 @@ discard block |
||
341 | 341 | * @param WP_REST_Request $request Request object. |
342 | 342 | * @return WP_REST_Response $response |
343 | 343 | */ |
344 | - public function prepare_item_for_response( $item, $request ) { |
|
344 | + public function prepare_item_for_response($item, $request) { |
|
345 | 345 | $method = array( |
346 | 346 | 'id' => $item->instance_id, |
347 | 347 | 'instance_id' => $item->instance_id, |
348 | 348 | 'title' => $item->instance_settings['title'], |
349 | 349 | 'order' => $item->method_order, |
350 | - 'enabled' => ( 'yes' === $item->enabled ), |
|
350 | + 'enabled' => ('yes' === $item->enabled), |
|
351 | 351 | 'method_id' => $item->id, |
352 | 352 | 'method_title' => $item->method_title, |
353 | 353 | 'method_description' => $item->method_description, |
354 | - 'settings' => $this->get_settings( $item ), |
|
354 | + 'settings' => $this->get_settings($item), |
|
355 | 355 | ); |
356 | 356 | |
357 | - $context = empty( $request['context'] ) ? 'view' : $request['context']; |
|
358 | - $data = $this->add_additional_fields_to_object( $method, $request ); |
|
359 | - $data = $this->filter_response_by_context( $data, $context ); |
|
357 | + $context = empty($request['context']) ? 'view' : $request['context']; |
|
358 | + $data = $this->add_additional_fields_to_object($method, $request); |
|
359 | + $data = $this->filter_response_by_context($data, $context); |
|
360 | 360 | |
361 | 361 | // Wrap the data in a response object. |
362 | - $response = rest_ensure_response( $data ); |
|
362 | + $response = rest_ensure_response($data); |
|
363 | 363 | |
364 | - $response->add_links( $this->prepare_links( $request['zone_id'], $item->instance_id ) ); |
|
364 | + $response->add_links($this->prepare_links($request['zone_id'], $item->instance_id)); |
|
365 | 365 | |
366 | - $response = $this->prepare_response_for_collection( $response ); |
|
366 | + $response = $this->prepare_response_for_collection($response); |
|
367 | 367 | |
368 | 368 | return $response; |
369 | 369 | } |
@@ -375,24 +375,24 @@ discard block |
||
375 | 375 | * |
376 | 376 | * @return array |
377 | 377 | */ |
378 | - public function get_settings( $item ) { |
|
378 | + public function get_settings($item) { |
|
379 | 379 | $item->init_instance_settings(); |
380 | 380 | $settings = array(); |
381 | - foreach ( $item->get_instance_form_fields() as $id => $field ) { |
|
381 | + foreach ($item->get_instance_form_fields() as $id => $field) { |
|
382 | 382 | $data = array( |
383 | 383 | 'id' => $id, |
384 | 384 | 'label' => $field['title'], |
385 | - 'description' => empty( $field['description'] ) ? '' : $field['description'], |
|
385 | + 'description' => empty($field['description']) ? '' : $field['description'], |
|
386 | 386 | 'type' => $field['type'], |
387 | - 'value' => $item->instance_settings[ $id ], |
|
388 | - 'default' => empty( $field['default'] ) ? '' : $field['default'], |
|
389 | - 'tip' => empty( $field['description'] ) ? '' : $field['description'], |
|
390 | - 'placeholder' => empty( $field['placeholder'] ) ? '' : $field['placeholder'], |
|
387 | + 'value' => $item->instance_settings[$id], |
|
388 | + 'default' => empty($field['default']) ? '' : $field['default'], |
|
389 | + 'tip' => empty($field['description']) ? '' : $field['description'], |
|
390 | + 'placeholder' => empty($field['placeholder']) ? '' : $field['placeholder'], |
|
391 | 391 | ); |
392 | - if ( ! empty( $field['options'] ) ) { |
|
392 | + if ( ! empty($field['options'])) { |
|
393 | 393 | $data['options'] = $field['options']; |
394 | 394 | } |
395 | - $settings[ $id ] = $data; |
|
395 | + $settings[$id] = $data; |
|
396 | 396 | } |
397 | 397 | return $settings; |
398 | 398 | } |
@@ -404,17 +404,17 @@ discard block |
||
404 | 404 | * @param int $instance_id Given Shipping Zone Method Instance ID. |
405 | 405 | * @return array Links for the given Shipping Zone Method. |
406 | 406 | */ |
407 | - protected function prepare_links( $zone_id, $instance_id ) { |
|
407 | + protected function prepare_links($zone_id, $instance_id) { |
|
408 | 408 | $base = '/' . $this->namespace . '/' . $this->rest_base . '/' . $zone_id; |
409 | 409 | $links = array( |
410 | 410 | 'self' => array( |
411 | - 'href' => rest_url( $base . '/methods/' . $instance_id ), |
|
411 | + 'href' => rest_url($base . '/methods/' . $instance_id), |
|
412 | 412 | ), |
413 | 413 | 'collection' => array( |
414 | - 'href' => rest_url( $base . '/methods' ), |
|
414 | + 'href' => rest_url($base . '/methods'), |
|
415 | 415 | ), |
416 | 416 | 'describes' => array( |
417 | - 'href' => rest_url( $base ), |
|
417 | + 'href' => rest_url($base), |
|
418 | 418 | ), |
419 | 419 | ); |
420 | 420 | |
@@ -433,102 +433,102 @@ discard block |
||
433 | 433 | 'type' => 'object', |
434 | 434 | 'properties' => array( |
435 | 435 | 'id' => array( |
436 | - 'description' => __( 'Shipping method instance ID.', 'woocommerce' ), |
|
436 | + 'description' => __('Shipping method instance ID.', 'woocommerce'), |
|
437 | 437 | 'type' => 'integer', |
438 | - 'context' => array( 'view', 'edit' ), |
|
438 | + 'context' => array('view', 'edit'), |
|
439 | 439 | 'readonly' => true, |
440 | 440 | ), |
441 | 441 | 'instance_id' => array( |
442 | - 'description' => __( 'Shipping method instance ID.', 'woocommerce' ), |
|
442 | + 'description' => __('Shipping method instance ID.', 'woocommerce'), |
|
443 | 443 | 'type' => 'integer', |
444 | - 'context' => array( 'view', 'edit' ), |
|
444 | + 'context' => array('view', 'edit'), |
|
445 | 445 | 'readonly' => true, |
446 | 446 | ), |
447 | 447 | 'title' => array( |
448 | - 'description' => __( 'Shipping method customer facing title.', 'woocommerce' ), |
|
448 | + 'description' => __('Shipping method customer facing title.', 'woocommerce'), |
|
449 | 449 | 'type' => 'string', |
450 | - 'context' => array( 'view', 'edit' ), |
|
450 | + 'context' => array('view', 'edit'), |
|
451 | 451 | 'readonly' => true, |
452 | 452 | ), |
453 | 453 | 'order' => array( |
454 | - 'description' => __( 'Shipping method sort order.', 'woocommerce' ), |
|
454 | + 'description' => __('Shipping method sort order.', 'woocommerce'), |
|
455 | 455 | 'type' => 'integer', |
456 | - 'context' => array( 'view', 'edit' ), |
|
456 | + 'context' => array('view', 'edit'), |
|
457 | 457 | ), |
458 | 458 | 'enabled' => array( |
459 | - 'description' => __( 'Shipping method enabled status.', 'woocommerce' ), |
|
459 | + 'description' => __('Shipping method enabled status.', 'woocommerce'), |
|
460 | 460 | 'type' => 'boolean', |
461 | - 'context' => array( 'view', 'edit' ), |
|
461 | + 'context' => array('view', 'edit'), |
|
462 | 462 | ), |
463 | 463 | 'method_id' => array( |
464 | - 'description' => __( 'Shipping method ID.', 'woocommerce' ), |
|
464 | + 'description' => __('Shipping method ID.', 'woocommerce'), |
|
465 | 465 | 'type' => 'string', |
466 | - 'context' => array( 'view', 'edit' ), |
|
466 | + 'context' => array('view', 'edit'), |
|
467 | 467 | 'readonly' => true, |
468 | 468 | ), |
469 | 469 | 'method_title' => array( |
470 | - 'description' => __( 'Shipping method title.', 'woocommerce' ), |
|
470 | + 'description' => __('Shipping method title.', 'woocommerce'), |
|
471 | 471 | 'type' => 'string', |
472 | - 'context' => array( 'view', 'edit' ), |
|
472 | + 'context' => array('view', 'edit'), |
|
473 | 473 | 'readonly' => true, |
474 | 474 | ), |
475 | 475 | 'method_description' => array( |
476 | - 'description' => __( 'Shipping method description.', 'woocommerce' ), |
|
476 | + 'description' => __('Shipping method description.', 'woocommerce'), |
|
477 | 477 | 'type' => 'string', |
478 | - 'context' => array( 'view', 'edit' ), |
|
478 | + 'context' => array('view', 'edit'), |
|
479 | 479 | 'readonly' => true, |
480 | 480 | ), |
481 | 481 | 'settings' => array( |
482 | - 'description' => __( 'Shipping method settings.', 'woocommerce' ), |
|
482 | + 'description' => __('Shipping method settings.', 'woocommerce'), |
|
483 | 483 | 'type' => 'object', |
484 | - 'context' => array( 'view', 'edit' ), |
|
484 | + 'context' => array('view', 'edit'), |
|
485 | 485 | 'properties' => array( |
486 | 486 | 'id' => array( |
487 | - 'description' => __( 'A unique identifier for the setting.', 'woocommerce' ), |
|
487 | + 'description' => __('A unique identifier for the setting.', 'woocommerce'), |
|
488 | 488 | 'type' => 'string', |
489 | - 'context' => array( 'view', 'edit' ), |
|
489 | + 'context' => array('view', 'edit'), |
|
490 | 490 | 'readonly' => true, |
491 | 491 | ), |
492 | 492 | 'label' => array( |
493 | - 'description' => __( 'A human readable label for the setting used in interfaces.', 'woocommerce' ), |
|
493 | + 'description' => __('A human readable label for the setting used in interfaces.', 'woocommerce'), |
|
494 | 494 | 'type' => 'string', |
495 | - 'context' => array( 'view', 'edit' ), |
|
495 | + 'context' => array('view', 'edit'), |
|
496 | 496 | 'readonly' => true, |
497 | 497 | ), |
498 | 498 | 'description' => array( |
499 | - 'description' => __( 'A human readable description for the setting used in interfaces.', 'woocommerce' ), |
|
499 | + 'description' => __('A human readable description for the setting used in interfaces.', 'woocommerce'), |
|
500 | 500 | 'type' => 'string', |
501 | - 'context' => array( 'view', 'edit' ), |
|
501 | + 'context' => array('view', 'edit'), |
|
502 | 502 | 'readonly' => true, |
503 | 503 | ), |
504 | 504 | 'type' => array( |
505 | - 'description' => __( 'Type of setting.', 'woocommerce' ), |
|
505 | + 'description' => __('Type of setting.', 'woocommerce'), |
|
506 | 506 | 'type' => 'string', |
507 | - 'context' => array( 'view', 'edit' ), |
|
508 | - 'enum' => array( 'text', 'email', 'number', 'color', 'password', 'textarea', 'select', 'multiselect', 'radio', 'image_width', 'checkbox' ), |
|
507 | + 'context' => array('view', 'edit'), |
|
508 | + 'enum' => array('text', 'email', 'number', 'color', 'password', 'textarea', 'select', 'multiselect', 'radio', 'image_width', 'checkbox'), |
|
509 | 509 | 'readonly' => true, |
510 | 510 | ), |
511 | 511 | 'value' => array( |
512 | - 'description' => __( 'Setting value.', 'woocommerce' ), |
|
512 | + 'description' => __('Setting value.', 'woocommerce'), |
|
513 | 513 | 'type' => 'string', |
514 | - 'context' => array( 'view', 'edit' ), |
|
514 | + 'context' => array('view', 'edit'), |
|
515 | 515 | ), |
516 | 516 | 'default' => array( |
517 | - 'description' => __( 'Default value for the setting.', 'woocommerce' ), |
|
517 | + 'description' => __('Default value for the setting.', 'woocommerce'), |
|
518 | 518 | 'type' => 'string', |
519 | - 'context' => array( 'view', 'edit' ), |
|
519 | + 'context' => array('view', 'edit'), |
|
520 | 520 | 'readonly' => true, |
521 | 521 | ), |
522 | 522 | 'tip' => array( |
523 | - 'description' => __( 'Additional help text shown to the user about the setting.', 'woocommerce' ), |
|
523 | + 'description' => __('Additional help text shown to the user about the setting.', 'woocommerce'), |
|
524 | 524 | 'type' => 'string', |
525 | - 'context' => array( 'view', 'edit' ), |
|
525 | + 'context' => array('view', 'edit'), |
|
526 | 526 | 'readonly' => true, |
527 | 527 | ), |
528 | 528 | 'placeholder' => array( |
529 | - 'description' => __( 'Placeholder text to be displayed in text inputs.', 'woocommerce' ), |
|
529 | + 'description' => __('Placeholder text to be displayed in text inputs.', 'woocommerce'), |
|
530 | 530 | 'type' => 'string', |
531 | - 'context' => array( 'view', 'edit' ), |
|
531 | + 'context' => array('view', 'edit'), |
|
532 | 532 | 'readonly' => true, |
533 | 533 | ), |
534 | 534 | ), |
@@ -536,6 +536,6 @@ discard block |
||
536 | 536 | ), |
537 | 537 | ); |
538 | 538 | |
539 | - return $this->add_additional_fields_schema( $schema ); |
|
539 | + return $this->add_additional_fields_schema($schema); |
|
540 | 540 | } |
541 | 541 | } |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * @since 3.0.0 |
9 | 9 | */ |
10 | 10 | |
11 | -defined( 'ABSPATH' ) || exit; |
|
11 | +defined('ABSPATH') || exit; |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * REST API variations controller class. |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | * Initialize product actions (parent). |
44 | 44 | */ |
45 | 45 | public function __construct() { |
46 | - add_filter( "woocommerce_rest_{$this->post_type}_query", array( $this, 'add_product_id' ), 9, 2 ); |
|
46 | + add_filter("woocommerce_rest_{$this->post_type}_query", array($this, 'add_product_id'), 9, 2); |
|
47 | 47 | parent::__construct(); |
48 | 48 | } |
49 | 49 | |
@@ -55,41 +55,41 @@ discard block |
||
55 | 55 | $this->namespace, '/' . $this->rest_base, array( |
56 | 56 | 'args' => array( |
57 | 57 | 'product_id' => array( |
58 | - 'description' => __( 'Unique identifier for the variable product.', 'woocommerce' ), |
|
58 | + 'description' => __('Unique identifier for the variable product.', 'woocommerce'), |
|
59 | 59 | 'type' => 'integer', |
60 | 60 | ), |
61 | 61 | ), |
62 | 62 | array( |
63 | 63 | 'methods' => WP_REST_Server::READABLE, |
64 | - 'callback' => array( $this, 'get_items' ), |
|
65 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
64 | + 'callback' => array($this, 'get_items'), |
|
65 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
66 | 66 | 'args' => $this->get_collection_params(), |
67 | 67 | ), |
68 | 68 | array( |
69 | 69 | 'methods' => WP_REST_Server::CREATABLE, |
70 | - 'callback' => array( $this, 'create_item' ), |
|
71 | - 'permission_callback' => array( $this, 'create_item_permissions_check' ), |
|
72 | - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), |
|
70 | + 'callback' => array($this, 'create_item'), |
|
71 | + 'permission_callback' => array($this, 'create_item_permissions_check'), |
|
72 | + 'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::CREATABLE), |
|
73 | 73 | ), |
74 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
74 | + 'schema' => array($this, 'get_public_item_schema'), |
|
75 | 75 | ) |
76 | 76 | ); |
77 | 77 | register_rest_route( |
78 | 78 | $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array( |
79 | 79 | 'args' => array( |
80 | 80 | 'product_id' => array( |
81 | - 'description' => __( 'Unique identifier for the variable product.', 'woocommerce' ), |
|
81 | + 'description' => __('Unique identifier for the variable product.', 'woocommerce'), |
|
82 | 82 | 'type' => 'integer', |
83 | 83 | ), |
84 | 84 | 'id' => array( |
85 | - 'description' => __( 'Unique identifier for the variation.', 'woocommerce' ), |
|
85 | + 'description' => __('Unique identifier for the variation.', 'woocommerce'), |
|
86 | 86 | 'type' => 'integer', |
87 | 87 | ), |
88 | 88 | ), |
89 | 89 | array( |
90 | 90 | 'methods' => WP_REST_Server::READABLE, |
91 | - 'callback' => array( $this, 'get_item' ), |
|
92 | - 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
|
91 | + 'callback' => array($this, 'get_item'), |
|
92 | + 'permission_callback' => array($this, 'get_item_permissions_check'), |
|
93 | 93 | 'args' => array( |
94 | 94 | 'context' => $this->get_context_param( |
95 | 95 | array( |
@@ -100,40 +100,40 @@ discard block |
||
100 | 100 | ), |
101 | 101 | array( |
102 | 102 | 'methods' => WP_REST_Server::EDITABLE, |
103 | - 'callback' => array( $this, 'update_item' ), |
|
104 | - 'permission_callback' => array( $this, 'update_item_permissions_check' ), |
|
105 | - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), |
|
103 | + 'callback' => array($this, 'update_item'), |
|
104 | + 'permission_callback' => array($this, 'update_item_permissions_check'), |
|
105 | + 'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE), |
|
106 | 106 | ), |
107 | 107 | array( |
108 | 108 | 'methods' => WP_REST_Server::DELETABLE, |
109 | - 'callback' => array( $this, 'delete_item' ), |
|
110 | - 'permission_callback' => array( $this, 'delete_item_permissions_check' ), |
|
109 | + 'callback' => array($this, 'delete_item'), |
|
110 | + 'permission_callback' => array($this, 'delete_item_permissions_check'), |
|
111 | 111 | 'args' => array( |
112 | 112 | 'force' => array( |
113 | 113 | 'default' => false, |
114 | 114 | 'type' => 'boolean', |
115 | - 'description' => __( 'Whether to bypass trash and force deletion.', 'woocommerce' ), |
|
115 | + 'description' => __('Whether to bypass trash and force deletion.', 'woocommerce'), |
|
116 | 116 | ), |
117 | 117 | ), |
118 | 118 | ), |
119 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
119 | + 'schema' => array($this, 'get_public_item_schema'), |
|
120 | 120 | ) |
121 | 121 | ); |
122 | 122 | register_rest_route( |
123 | 123 | $this->namespace, '/' . $this->rest_base . '/batch', array( |
124 | 124 | 'args' => array( |
125 | 125 | 'product_id' => array( |
126 | - 'description' => __( 'Unique identifier for the variable product.', 'woocommerce' ), |
|
126 | + 'description' => __('Unique identifier for the variable product.', 'woocommerce'), |
|
127 | 127 | 'type' => 'integer', |
128 | 128 | ), |
129 | 129 | ), |
130 | 130 | array( |
131 | 131 | 'methods' => WP_REST_Server::EDITABLE, |
132 | - 'callback' => array( $this, 'batch_items' ), |
|
133 | - 'permission_callback' => array( $this, 'batch_items_permissions_check' ), |
|
134 | - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), |
|
132 | + 'callback' => array($this, 'batch_items'), |
|
133 | + 'permission_callback' => array($this, 'batch_items_permissions_check'), |
|
134 | + 'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE), |
|
135 | 135 | ), |
136 | - 'schema' => array( $this, 'get_public_batch_schema' ), |
|
136 | + 'schema' => array($this, 'get_public_batch_schema'), |
|
137 | 137 | ) |
138 | 138 | ); |
139 | 139 | } |
@@ -145,8 +145,8 @@ discard block |
||
145 | 145 | * @param int $id Object ID. |
146 | 146 | * @return WC_Data |
147 | 147 | */ |
148 | - protected function get_object( $id ) { |
|
149 | - return wc_get_product( $id ); |
|
148 | + protected function get_object($id) { |
|
149 | + return wc_get_product($id); |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | /** |
@@ -155,16 +155,16 @@ discard block |
||
155 | 155 | * @param WP_REST_Request $request Full details about the request. |
156 | 156 | * @return WP_Error|boolean |
157 | 157 | */ |
158 | - public function update_item_permissions_check( $request ) { |
|
159 | - $object = $this->get_object( (int) $request['id'] ); |
|
158 | + public function update_item_permissions_check($request) { |
|
159 | + $object = $this->get_object((int) $request['id']); |
|
160 | 160 | |
161 | - if ( $object && 0 !== $object->get_id() && ! wc_rest_check_post_permissions( $this->post_type, 'edit', $object->get_id() ) ) { |
|
162 | - return new WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you are not allowed to edit this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
161 | + if ($object && 0 !== $object->get_id() && ! wc_rest_check_post_permissions($this->post_type, 'edit', $object->get_id())) { |
|
162 | + return new WP_Error('woocommerce_rest_cannot_edit', __('Sorry, you are not allowed to edit this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | // Check if variation belongs to the correct parent product. |
166 | - if ( $object && 0 !== $object->get_parent_id() && absint( $request['product_id'] ) !== $object->get_parent_id() ) { |
|
167 | - return new WP_Error( 'woocommerce_rest_cannot_edit', __( 'Parent product does not match current variation.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
166 | + if ($object && 0 !== $object->get_parent_id() && absint($request['product_id']) !== $object->get_parent_id()) { |
|
167 | + return new WP_Error('woocommerce_rest_cannot_edit', __('Parent product does not match current variation.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
168 | 168 | } |
169 | 169 | |
170 | 170 | return true; |
@@ -178,29 +178,29 @@ discard block |
||
178 | 178 | * @param WP_REST_Request $request Request object. |
179 | 179 | * @return WP_REST_Response |
180 | 180 | */ |
181 | - public function prepare_object_for_response( $object, $request ) { |
|
181 | + public function prepare_object_for_response($object, $request) { |
|
182 | 182 | $data = array( |
183 | 183 | 'id' => $object->get_id(), |
184 | - 'date_created' => wc_rest_prepare_date_response( $object->get_date_created(), false ), |
|
185 | - 'date_created_gmt' => wc_rest_prepare_date_response( $object->get_date_created() ), |
|
186 | - 'date_modified' => wc_rest_prepare_date_response( $object->get_date_modified(), false ), |
|
187 | - 'date_modified_gmt' => wc_rest_prepare_date_response( $object->get_date_modified() ), |
|
188 | - 'description' => wc_format_content( $object->get_description() ), |
|
184 | + 'date_created' => wc_rest_prepare_date_response($object->get_date_created(), false), |
|
185 | + 'date_created_gmt' => wc_rest_prepare_date_response($object->get_date_created()), |
|
186 | + 'date_modified' => wc_rest_prepare_date_response($object->get_date_modified(), false), |
|
187 | + 'date_modified_gmt' => wc_rest_prepare_date_response($object->get_date_modified()), |
|
188 | + 'description' => wc_format_content($object->get_description()), |
|
189 | 189 | 'permalink' => $object->get_permalink(), |
190 | 190 | 'sku' => $object->get_sku(), |
191 | 191 | 'price' => $object->get_price(), |
192 | 192 | 'regular_price' => $object->get_regular_price(), |
193 | 193 | 'sale_price' => $object->get_sale_price(), |
194 | - 'date_on_sale_from' => wc_rest_prepare_date_response( $object->get_date_on_sale_from(), false ), |
|
195 | - 'date_on_sale_from_gmt' => wc_rest_prepare_date_response( $object->get_date_on_sale_from() ), |
|
196 | - 'date_on_sale_to' => wc_rest_prepare_date_response( $object->get_date_on_sale_to(), false ), |
|
197 | - 'date_on_sale_to_gmt' => wc_rest_prepare_date_response( $object->get_date_on_sale_to() ), |
|
194 | + 'date_on_sale_from' => wc_rest_prepare_date_response($object->get_date_on_sale_from(), false), |
|
195 | + 'date_on_sale_from_gmt' => wc_rest_prepare_date_response($object->get_date_on_sale_from()), |
|
196 | + 'date_on_sale_to' => wc_rest_prepare_date_response($object->get_date_on_sale_to(), false), |
|
197 | + 'date_on_sale_to_gmt' => wc_rest_prepare_date_response($object->get_date_on_sale_to()), |
|
198 | 198 | 'on_sale' => $object->is_on_sale(), |
199 | 199 | 'visible' => $object->is_visible(), |
200 | 200 | 'purchasable' => $object->is_purchasable(), |
201 | 201 | 'virtual' => $object->is_virtual(), |
202 | 202 | 'downloadable' => $object->is_downloadable(), |
203 | - 'downloads' => $this->get_downloads( $object ), |
|
203 | + 'downloads' => $this->get_downloads($object), |
|
204 | 204 | 'download_limit' => '' !== $object->get_download_limit() ? (int) $object->get_download_limit() : -1, |
205 | 205 | 'download_expiry' => '' !== $object->get_download_expiry() ? (int) $object->get_download_expiry() : -1, |
206 | 206 | 'tax_status' => $object->get_tax_status(), |
@@ -219,17 +219,17 @@ discard block |
||
219 | 219 | ), |
220 | 220 | 'shipping_class' => $object->get_shipping_class(), |
221 | 221 | 'shipping_class_id' => $object->get_shipping_class_id(), |
222 | - 'image' => current( $this->get_images( $object ) ), |
|
223 | - 'attributes' => $this->get_attributes( $object ), |
|
222 | + 'image' => current($this->get_images($object)), |
|
223 | + 'attributes' => $this->get_attributes($object), |
|
224 | 224 | 'menu_order' => $object->get_menu_order(), |
225 | 225 | 'meta_data' => $object->get_meta_data(), |
226 | 226 | ); |
227 | 227 | |
228 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
229 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
230 | - $data = $this->filter_response_by_context( $data, $context ); |
|
231 | - $response = rest_ensure_response( $data ); |
|
232 | - $response->add_links( $this->prepare_links( $object, $request ) ); |
|
228 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
229 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
230 | + $data = $this->filter_response_by_context($data, $context); |
|
231 | + $response = rest_ensure_response($data); |
|
232 | + $response->add_links($this->prepare_links($object, $request)); |
|
233 | 233 | |
234 | 234 | /** |
235 | 235 | * Filter the data for a response. |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | * @param WC_Data $object Object data. |
242 | 242 | * @param WP_REST_Request $request Request object. |
243 | 243 | */ |
244 | - return apply_filters( "woocommerce_rest_prepare_{$this->post_type}_object", $response, $object, $request ); |
|
244 | + return apply_filters("woocommerce_rest_prepare_{$this->post_type}_object", $response, $object, $request); |
|
245 | 245 | } |
246 | 246 | |
247 | 247 | /** |
@@ -251,8 +251,8 @@ discard block |
||
251 | 251 | * @param WP_REST_Request $request Full details about the request. |
252 | 252 | * @return array |
253 | 253 | */ |
254 | - protected function prepare_objects_query( $request ) { |
|
255 | - $args = parent::prepare_objects_query( $request ); |
|
254 | + protected function prepare_objects_query($request) { |
|
255 | + $args = parent::prepare_objects_query($request); |
|
256 | 256 | |
257 | 257 | $args['post_parent'] = $request['product_id']; |
258 | 258 | |
@@ -266,196 +266,196 @@ discard block |
||
266 | 266 | * @param bool $creating If is creating a new object. |
267 | 267 | * @return WP_Error|WC_Data |
268 | 268 | */ |
269 | - protected function prepare_object_for_database( $request, $creating = false ) { |
|
270 | - if ( isset( $request['id'] ) ) { |
|
271 | - $variation = wc_get_product( absint( $request['id'] ) ); |
|
269 | + protected function prepare_object_for_database($request, $creating = false) { |
|
270 | + if (isset($request['id'])) { |
|
271 | + $variation = wc_get_product(absint($request['id'])); |
|
272 | 272 | } else { |
273 | 273 | $variation = new WC_Product_Variation(); |
274 | 274 | } |
275 | 275 | |
276 | 276 | // Update parent ID just once. |
277 | - if ( 0 === $variation->get_parent_id() ) { |
|
278 | - $variation->set_parent_id( absint( $request['product_id'] ) ); |
|
277 | + if (0 === $variation->get_parent_id()) { |
|
278 | + $variation->set_parent_id(absint($request['product_id'])); |
|
279 | 279 | } |
280 | 280 | |
281 | 281 | // Status. |
282 | - if ( isset( $request['visible'] ) ) { |
|
283 | - $variation->set_status( false === $request['visible'] ? 'private' : 'publish' ); |
|
282 | + if (isset($request['visible'])) { |
|
283 | + $variation->set_status(false === $request['visible'] ? 'private' : 'publish'); |
|
284 | 284 | } |
285 | 285 | |
286 | 286 | // SKU. |
287 | - if ( isset( $request['sku'] ) ) { |
|
288 | - $variation->set_sku( wc_clean( $request['sku'] ) ); |
|
287 | + if (isset($request['sku'])) { |
|
288 | + $variation->set_sku(wc_clean($request['sku'])); |
|
289 | 289 | } |
290 | 290 | |
291 | 291 | // Thumbnail. |
292 | - if ( isset( $request['image'] ) ) { |
|
293 | - if ( is_array( $request['image'] ) && ! empty( $request['image'] ) ) { |
|
292 | + if (isset($request['image'])) { |
|
293 | + if (is_array($request['image']) && ! empty($request['image'])) { |
|
294 | 294 | $image = $request['image']; |
295 | - if ( is_array( $image ) ) { |
|
295 | + if (is_array($image)) { |
|
296 | 296 | $image['position'] = 0; |
297 | 297 | } |
298 | 298 | |
299 | - $variation = $this->set_product_images( $variation, array( $image ) ); |
|
299 | + $variation = $this->set_product_images($variation, array($image)); |
|
300 | 300 | } else { |
301 | - $variation->set_image_id( '' ); |
|
301 | + $variation->set_image_id(''); |
|
302 | 302 | } |
303 | 303 | } |
304 | 304 | |
305 | 305 | // Virtual variation. |
306 | - if ( isset( $request['virtual'] ) ) { |
|
307 | - $variation->set_virtual( $request['virtual'] ); |
|
306 | + if (isset($request['virtual'])) { |
|
307 | + $variation->set_virtual($request['virtual']); |
|
308 | 308 | } |
309 | 309 | |
310 | 310 | // Downloadable variation. |
311 | - if ( isset( $request['downloadable'] ) ) { |
|
312 | - $variation->set_downloadable( $request['downloadable'] ); |
|
311 | + if (isset($request['downloadable'])) { |
|
312 | + $variation->set_downloadable($request['downloadable']); |
|
313 | 313 | } |
314 | 314 | |
315 | 315 | // Downloads. |
316 | - if ( $variation->get_downloadable() ) { |
|
316 | + if ($variation->get_downloadable()) { |
|
317 | 317 | // Downloadable files. |
318 | - if ( isset( $request['downloads'] ) && is_array( $request['downloads'] ) ) { |
|
319 | - $variation = $this->save_downloadable_files( $variation, $request['downloads'] ); |
|
318 | + if (isset($request['downloads']) && is_array($request['downloads'])) { |
|
319 | + $variation = $this->save_downloadable_files($variation, $request['downloads']); |
|
320 | 320 | } |
321 | 321 | |
322 | 322 | // Download limit. |
323 | - if ( isset( $request['download_limit'] ) ) { |
|
324 | - $variation->set_download_limit( $request['download_limit'] ); |
|
323 | + if (isset($request['download_limit'])) { |
|
324 | + $variation->set_download_limit($request['download_limit']); |
|
325 | 325 | } |
326 | 326 | |
327 | 327 | // Download expiry. |
328 | - if ( isset( $request['download_expiry'] ) ) { |
|
329 | - $variation->set_download_expiry( $request['download_expiry'] ); |
|
328 | + if (isset($request['download_expiry'])) { |
|
329 | + $variation->set_download_expiry($request['download_expiry']); |
|
330 | 330 | } |
331 | 331 | } |
332 | 332 | |
333 | 333 | // Shipping data. |
334 | - $variation = $this->save_product_shipping_data( $variation, $request ); |
|
334 | + $variation = $this->save_product_shipping_data($variation, $request); |
|
335 | 335 | |
336 | 336 | // Stock handling. |
337 | - if ( isset( $request['manage_stock'] ) ) { |
|
338 | - if ( 'parent' === $request['manage_stock'] ) { |
|
339 | - $variation->set_manage_stock( false ); // This just indicates the variation does not manage stock, but the parent does. |
|
337 | + if (isset($request['manage_stock'])) { |
|
338 | + if ('parent' === $request['manage_stock']) { |
|
339 | + $variation->set_manage_stock(false); // This just indicates the variation does not manage stock, but the parent does. |
|
340 | 340 | } else { |
341 | - $variation->set_manage_stock( wc_string_to_bool( $request['manage_stock'] ) ); |
|
341 | + $variation->set_manage_stock(wc_string_to_bool($request['manage_stock'])); |
|
342 | 342 | } |
343 | 343 | } |
344 | 344 | |
345 | - if ( isset( $request['in_stock'] ) ) { |
|
346 | - $variation->set_stock_status( true === $request['in_stock'] ? 'instock' : 'outofstock' ); |
|
345 | + if (isset($request['in_stock'])) { |
|
346 | + $variation->set_stock_status(true === $request['in_stock'] ? 'instock' : 'outofstock'); |
|
347 | 347 | } |
348 | 348 | |
349 | - if ( isset( $request['backorders'] ) ) { |
|
350 | - $variation->set_backorders( $request['backorders'] ); |
|
349 | + if (isset($request['backorders'])) { |
|
350 | + $variation->set_backorders($request['backorders']); |
|
351 | 351 | } |
352 | 352 | |
353 | - if ( $variation->get_manage_stock() ) { |
|
354 | - if ( isset( $request['stock_quantity'] ) ) { |
|
355 | - $variation->set_stock_quantity( $request['stock_quantity'] ); |
|
356 | - } elseif ( isset( $request['inventory_delta'] ) ) { |
|
357 | - $stock_quantity = wc_stock_amount( $variation->get_stock_quantity() ); |
|
358 | - $stock_quantity += wc_stock_amount( $request['inventory_delta'] ); |
|
359 | - $variation->set_stock_quantity( $stock_quantity ); |
|
353 | + if ($variation->get_manage_stock()) { |
|
354 | + if (isset($request['stock_quantity'])) { |
|
355 | + $variation->set_stock_quantity($request['stock_quantity']); |
|
356 | + } elseif (isset($request['inventory_delta'])) { |
|
357 | + $stock_quantity = wc_stock_amount($variation->get_stock_quantity()); |
|
358 | + $stock_quantity += wc_stock_amount($request['inventory_delta']); |
|
359 | + $variation->set_stock_quantity($stock_quantity); |
|
360 | 360 | } |
361 | 361 | } else { |
362 | - $variation->set_backorders( 'no' ); |
|
363 | - $variation->set_stock_quantity( '' ); |
|
362 | + $variation->set_backorders('no'); |
|
363 | + $variation->set_stock_quantity(''); |
|
364 | 364 | } |
365 | 365 | |
366 | 366 | // Regular Price. |
367 | - if ( isset( $request['regular_price'] ) ) { |
|
368 | - $variation->set_regular_price( $request['regular_price'] ); |
|
367 | + if (isset($request['regular_price'])) { |
|
368 | + $variation->set_regular_price($request['regular_price']); |
|
369 | 369 | } |
370 | 370 | |
371 | 371 | // Sale Price. |
372 | - if ( isset( $request['sale_price'] ) ) { |
|
373 | - $variation->set_sale_price( $request['sale_price'] ); |
|
372 | + if (isset($request['sale_price'])) { |
|
373 | + $variation->set_sale_price($request['sale_price']); |
|
374 | 374 | } |
375 | 375 | |
376 | - if ( isset( $request['date_on_sale_from'] ) ) { |
|
377 | - $variation->set_date_on_sale_from( $request['date_on_sale_from'] ); |
|
376 | + if (isset($request['date_on_sale_from'])) { |
|
377 | + $variation->set_date_on_sale_from($request['date_on_sale_from']); |
|
378 | 378 | } |
379 | 379 | |
380 | - if ( isset( $request['date_on_sale_from_gmt'] ) ) { |
|
381 | - $variation->set_date_on_sale_from( $request['date_on_sale_from_gmt'] ? strtotime( $request['date_on_sale_from_gmt'] ) : null ); |
|
380 | + if (isset($request['date_on_sale_from_gmt'])) { |
|
381 | + $variation->set_date_on_sale_from($request['date_on_sale_from_gmt'] ? strtotime($request['date_on_sale_from_gmt']) : null); |
|
382 | 382 | } |
383 | 383 | |
384 | - if ( isset( $request['date_on_sale_to'] ) ) { |
|
385 | - $variation->set_date_on_sale_to( $request['date_on_sale_to'] ); |
|
384 | + if (isset($request['date_on_sale_to'])) { |
|
385 | + $variation->set_date_on_sale_to($request['date_on_sale_to']); |
|
386 | 386 | } |
387 | 387 | |
388 | - if ( isset( $request['date_on_sale_to_gmt'] ) ) { |
|
389 | - $variation->set_date_on_sale_to( $request['date_on_sale_to_gmt'] ? strtotime( $request['date_on_sale_to_gmt'] ) : null ); |
|
388 | + if (isset($request['date_on_sale_to_gmt'])) { |
|
389 | + $variation->set_date_on_sale_to($request['date_on_sale_to_gmt'] ? strtotime($request['date_on_sale_to_gmt']) : null); |
|
390 | 390 | } |
391 | 391 | |
392 | 392 | // Tax class. |
393 | - if ( isset( $request['tax_class'] ) ) { |
|
394 | - $variation->set_tax_class( $request['tax_class'] ); |
|
393 | + if (isset($request['tax_class'])) { |
|
394 | + $variation->set_tax_class($request['tax_class']); |
|
395 | 395 | } |
396 | 396 | |
397 | 397 | // Description. |
398 | - if ( isset( $request['description'] ) ) { |
|
399 | - $variation->set_description( wp_kses_post( $request['description'] ) ); |
|
398 | + if (isset($request['description'])) { |
|
399 | + $variation->set_description(wp_kses_post($request['description'])); |
|
400 | 400 | } |
401 | 401 | |
402 | 402 | // Update taxonomies. |
403 | - if ( isset( $request['attributes'] ) ) { |
|
403 | + if (isset($request['attributes'])) { |
|
404 | 404 | $attributes = array(); |
405 | - $parent = wc_get_product( $variation->get_parent_id() ); |
|
405 | + $parent = wc_get_product($variation->get_parent_id()); |
|
406 | 406 | $parent_attributes = $parent->get_attributes(); |
407 | 407 | |
408 | - foreach ( $request['attributes'] as $attribute ) { |
|
408 | + foreach ($request['attributes'] as $attribute) { |
|
409 | 409 | $attribute_id = 0; |
410 | 410 | $attribute_name = ''; |
411 | 411 | |
412 | 412 | // Check ID for global attributes or name for product attributes. |
413 | - if ( ! empty( $attribute['id'] ) ) { |
|
414 | - $attribute_id = absint( $attribute['id'] ); |
|
415 | - $raw_attribute_name = wc_attribute_taxonomy_name_by_id( $attribute_id ); |
|
416 | - } elseif ( ! empty( $attribute['name'] ) ) { |
|
417 | - $raw_attribute_name = sanitize_title( $attribute['name'] ); |
|
413 | + if ( ! empty($attribute['id'])) { |
|
414 | + $attribute_id = absint($attribute['id']); |
|
415 | + $raw_attribute_name = wc_attribute_taxonomy_name_by_id($attribute_id); |
|
416 | + } elseif ( ! empty($attribute['name'])) { |
|
417 | + $raw_attribute_name = sanitize_title($attribute['name']); |
|
418 | 418 | } |
419 | 419 | |
420 | - if ( ! $attribute_id && ! $raw_attribute_name ) { |
|
420 | + if ( ! $attribute_id && ! $raw_attribute_name) { |
|
421 | 421 | continue; |
422 | 422 | } |
423 | 423 | |
424 | - $attribute_name = sanitize_title( $raw_attribute_name ); |
|
424 | + $attribute_name = sanitize_title($raw_attribute_name); |
|
425 | 425 | |
426 | - if ( ! isset( $parent_attributes[ $attribute_name ] ) || ! $parent_attributes[ $attribute_name ]->get_variation() ) { |
|
426 | + if ( ! isset($parent_attributes[$attribute_name]) || ! $parent_attributes[$attribute_name]->get_variation()) { |
|
427 | 427 | continue; |
428 | 428 | } |
429 | 429 | |
430 | - $attribute_key = sanitize_title( $parent_attributes[ $attribute_name ]->get_name() ); |
|
431 | - $attribute_value = isset( $attribute['option'] ) ? wc_clean( stripslashes( $attribute['option'] ) ) : ''; |
|
430 | + $attribute_key = sanitize_title($parent_attributes[$attribute_name]->get_name()); |
|
431 | + $attribute_value = isset($attribute['option']) ? wc_clean(stripslashes($attribute['option'])) : ''; |
|
432 | 432 | |
433 | - if ( $parent_attributes[ $attribute_name ]->is_taxonomy() ) { |
|
433 | + if ($parent_attributes[$attribute_name]->is_taxonomy()) { |
|
434 | 434 | // If dealing with a taxonomy, we need to get the slug from the name posted to the API. |
435 | - $term = get_term_by( 'name', $attribute_value, $raw_attribute_name ); // @codingStandardsIgnoreLine |
|
435 | + $term = get_term_by('name', $attribute_value, $raw_attribute_name); // @codingStandardsIgnoreLine |
|
436 | 436 | |
437 | - if ( $term && ! is_wp_error( $term ) ) { |
|
437 | + if ($term && ! is_wp_error($term)) { |
|
438 | 438 | $attribute_value = $term->slug; |
439 | 439 | } else { |
440 | - $attribute_value = sanitize_title( $attribute_value ); |
|
440 | + $attribute_value = sanitize_title($attribute_value); |
|
441 | 441 | } |
442 | 442 | } |
443 | 443 | |
444 | - $attributes[ $attribute_key ] = $attribute_value; |
|
444 | + $attributes[$attribute_key] = $attribute_value; |
|
445 | 445 | } |
446 | 446 | |
447 | - $variation->set_attributes( $attributes ); |
|
447 | + $variation->set_attributes($attributes); |
|
448 | 448 | } |
449 | 449 | |
450 | 450 | // Menu order. |
451 | - if ( $request['menu_order'] ) { |
|
452 | - $variation->set_menu_order( $request['menu_order'] ); |
|
451 | + if ($request['menu_order']) { |
|
452 | + $variation->set_menu_order($request['menu_order']); |
|
453 | 453 | } |
454 | 454 | |
455 | 455 | // Meta data. |
456 | - if ( is_array( $request['meta_data'] ) ) { |
|
457 | - foreach ( $request['meta_data'] as $meta ) { |
|
458 | - $variation->update_meta_data( $meta['key'], $meta['value'], isset( $meta['id'] ) ? $meta['id'] : '' ); |
|
456 | + if (is_array($request['meta_data'])) { |
|
457 | + foreach ($request['meta_data'] as $meta) { |
|
458 | + $variation->update_meta_data($meta['key'], $meta['value'], isset($meta['id']) ? $meta['id'] : ''); |
|
459 | 459 | } |
460 | 460 | } |
461 | 461 | |
@@ -469,7 +469,7 @@ discard block |
||
469 | 469 | * @param WP_REST_Request $request Request object. |
470 | 470 | * @param bool $creating If is creating a new object. |
471 | 471 | */ |
472 | - return apply_filters( "woocommerce_rest_pre_insert_{$this->post_type}_object", $variation, $request, $creating ); |
|
472 | + return apply_filters("woocommerce_rest_pre_insert_{$this->post_type}_object", $variation, $request, $creating); |
|
473 | 473 | } |
474 | 474 | |
475 | 475 | /** |
@@ -477,9 +477,9 @@ discard block |
||
477 | 477 | * |
478 | 478 | * @param WC_Data $object Object data. |
479 | 479 | */ |
480 | - public function clear_transients( $object ) { |
|
481 | - wc_delete_product_transients( $object->get_parent_id() ); |
|
482 | - wp_cache_delete( 'product-' . $object->get_parent_id(), 'products' ); |
|
480 | + public function clear_transients($object) { |
|
481 | + wc_delete_product_transients($object->get_parent_id()); |
|
482 | + wp_cache_delete('product-' . $object->get_parent_id(), 'products'); |
|
483 | 483 | } |
484 | 484 | |
485 | 485 | /** |
@@ -489,20 +489,20 @@ discard block |
||
489 | 489 | * |
490 | 490 | * @return bool|WP_Error|WP_REST_Response |
491 | 491 | */ |
492 | - public function delete_item( $request ) { |
|
492 | + public function delete_item($request) { |
|
493 | 493 | $force = (bool) $request['force']; |
494 | - $object = $this->get_object( (int) $request['id'] ); |
|
494 | + $object = $this->get_object((int) $request['id']); |
|
495 | 495 | $result = false; |
496 | 496 | |
497 | - if ( ! $object || 0 === $object->get_id() ) { |
|
497 | + if ( ! $object || 0 === $object->get_id()) { |
|
498 | 498 | return new WP_Error( |
499 | - "woocommerce_rest_{$this->post_type}_invalid_id", __( 'Invalid ID.', 'woocommerce' ), array( |
|
499 | + "woocommerce_rest_{$this->post_type}_invalid_id", __('Invalid ID.', 'woocommerce'), array( |
|
500 | 500 | 'status' => 404, |
501 | 501 | ) |
502 | 502 | ); |
503 | 503 | } |
504 | 504 | |
505 | - $supports_trash = EMPTY_TRASH_DAYS > 0 && is_callable( array( $object, 'get_status' ) ); |
|
505 | + $supports_trash = EMPTY_TRASH_DAYS > 0 && is_callable(array($object, 'get_status')); |
|
506 | 506 | |
507 | 507 | /** |
508 | 508 | * Filter whether an object is trashable. |
@@ -512,41 +512,41 @@ discard block |
||
512 | 512 | * @param boolean $supports_trash Whether the object type support trashing. |
513 | 513 | * @param WC_Data $object The object being considered for trashing support. |
514 | 514 | */ |
515 | - $supports_trash = apply_filters( "woocommerce_rest_{$this->post_type}_object_trashable", $supports_trash, $object ); |
|
515 | + $supports_trash = apply_filters("woocommerce_rest_{$this->post_type}_object_trashable", $supports_trash, $object); |
|
516 | 516 | |
517 | - if ( ! wc_rest_check_post_permissions( $this->post_type, 'delete', $object->get_id() ) ) { |
|
517 | + if ( ! wc_rest_check_post_permissions($this->post_type, 'delete', $object->get_id())) { |
|
518 | 518 | return new WP_Error( |
519 | 519 | /* translators: %s: post type */ |
520 | - "woocommerce_rest_user_cannot_delete_{$this->post_type}", sprintf( __( 'Sorry, you are not allowed to delete %s.', 'woocommerce' ), $this->post_type ), array( |
|
520 | + "woocommerce_rest_user_cannot_delete_{$this->post_type}", sprintf(__('Sorry, you are not allowed to delete %s.', 'woocommerce'), $this->post_type), array( |
|
521 | 521 | 'status' => rest_authorization_required_code(), |
522 | 522 | ) |
523 | 523 | ); |
524 | 524 | } |
525 | 525 | |
526 | - $request->set_param( 'context', 'edit' ); |
|
527 | - $response = $this->prepare_object_for_response( $object, $request ); |
|
526 | + $request->set_param('context', 'edit'); |
|
527 | + $response = $this->prepare_object_for_response($object, $request); |
|
528 | 528 | |
529 | 529 | // If we're forcing, then delete permanently. |
530 | - if ( $force ) { |
|
531 | - $object->delete( true ); |
|
530 | + if ($force) { |
|
531 | + $object->delete(true); |
|
532 | 532 | $result = 0 === $object->get_id(); |
533 | 533 | } else { |
534 | 534 | // If we don't support trashing for this type, error out. |
535 | - if ( ! $supports_trash ) { |
|
535 | + if ( ! $supports_trash) { |
|
536 | 536 | return new WP_Error( |
537 | 537 | /* translators: %s: post type */ |
538 | - 'woocommerce_rest_trash_not_supported', sprintf( __( 'The %s does not support trashing.', 'woocommerce' ), $this->post_type ), array( |
|
538 | + 'woocommerce_rest_trash_not_supported', sprintf(__('The %s does not support trashing.', 'woocommerce'), $this->post_type), array( |
|
539 | 539 | 'status' => 501, |
540 | 540 | ) |
541 | 541 | ); |
542 | 542 | } |
543 | 543 | |
544 | 544 | // Otherwise, only trash if we haven't already. |
545 | - if ( is_callable( array( $object, 'get_status' ) ) ) { |
|
546 | - if ( 'trash' === $object->get_status() ) { |
|
545 | + if (is_callable(array($object, 'get_status'))) { |
|
546 | + if ('trash' === $object->get_status()) { |
|
547 | 547 | return new WP_Error( |
548 | 548 | /* translators: %s: post type */ |
549 | - 'woocommerce_rest_already_trashed', sprintf( __( 'The %s has already been deleted.', 'woocommerce' ), $this->post_type ), array( |
|
549 | + 'woocommerce_rest_already_trashed', sprintf(__('The %s has already been deleted.', 'woocommerce'), $this->post_type), array( |
|
550 | 550 | 'status' => 410, |
551 | 551 | ) |
552 | 552 | ); |
@@ -557,18 +557,18 @@ discard block |
||
557 | 557 | } |
558 | 558 | } |
559 | 559 | |
560 | - if ( ! $result ) { |
|
560 | + if ( ! $result) { |
|
561 | 561 | return new WP_Error( |
562 | 562 | /* translators: %s: post type */ |
563 | - 'woocommerce_rest_cannot_delete', sprintf( __( 'The %s cannot be deleted.', 'woocommerce' ), $this->post_type ), array( |
|
563 | + 'woocommerce_rest_cannot_delete', sprintf(__('The %s cannot be deleted.', 'woocommerce'), $this->post_type), array( |
|
564 | 564 | 'status' => 500, |
565 | 565 | ) |
566 | 566 | ); |
567 | 567 | } |
568 | 568 | |
569 | 569 | // Delete parent product transients. |
570 | - if ( 0 !== $object->get_parent_id() ) { |
|
571 | - wc_delete_product_transients( $object->get_parent_id() ); |
|
570 | + if (0 !== $object->get_parent_id()) { |
|
571 | + wc_delete_product_transients($object->get_parent_id()); |
|
572 | 572 | } |
573 | 573 | |
574 | 574 | /** |
@@ -578,7 +578,7 @@ discard block |
||
578 | 578 | * @param WP_REST_Response $response The response data. |
579 | 579 | * @param WP_REST_Request $request The request sent to the API. |
580 | 580 | */ |
581 | - do_action( "woocommerce_rest_delete_{$this->post_type}_object", $object, $response, $request ); |
|
581 | + do_action("woocommerce_rest_delete_{$this->post_type}_object", $object, $response, $request); |
|
582 | 582 | |
583 | 583 | return $response; |
584 | 584 | } |
@@ -590,30 +590,30 @@ discard block |
||
590 | 590 | * @param WP_REST_Request $request Full details about the request. |
591 | 591 | * @return array Of WP_Error or WP_REST_Response. |
592 | 592 | */ |
593 | - public function batch_items( $request ) { |
|
594 | - $items = array_filter( $request->get_params() ); |
|
593 | + public function batch_items($request) { |
|
594 | + $items = array_filter($request->get_params()); |
|
595 | 595 | $params = $request->get_url_params(); |
596 | 596 | $product_id = $params['product_id']; |
597 | 597 | $body_params = array(); |
598 | 598 | |
599 | - foreach ( array( 'update', 'create', 'delete' ) as $batch_type ) { |
|
600 | - if ( ! empty( $items[ $batch_type ] ) ) { |
|
599 | + foreach (array('update', 'create', 'delete') as $batch_type) { |
|
600 | + if ( ! empty($items[$batch_type])) { |
|
601 | 601 | $injected_items = array(); |
602 | - foreach ( $items[ $batch_type ] as $item ) { |
|
603 | - $injected_items[] = is_array( $item ) ? array_merge( |
|
602 | + foreach ($items[$batch_type] as $item) { |
|
603 | + $injected_items[] = is_array($item) ? array_merge( |
|
604 | 604 | array( |
605 | 605 | 'product_id' => $product_id, |
606 | 606 | ), $item |
607 | 607 | ) : $item; |
608 | 608 | } |
609 | - $body_params[ $batch_type ] = $injected_items; |
|
609 | + $body_params[$batch_type] = $injected_items; |
|
610 | 610 | } |
611 | 611 | } |
612 | 612 | |
613 | - $request = new WP_REST_Request( $request->get_method() ); |
|
614 | - $request->set_body_params( $body_params ); |
|
613 | + $request = new WP_REST_Request($request->get_method()); |
|
614 | + $request->set_body_params($body_params); |
|
615 | 615 | |
616 | - return parent::batch_items( $request ); |
|
616 | + return parent::batch_items($request); |
|
617 | 617 | } |
618 | 618 | |
619 | 619 | /** |
@@ -623,18 +623,18 @@ discard block |
||
623 | 623 | * @param WP_REST_Request $request Request object. |
624 | 624 | * @return array Links for the given post. |
625 | 625 | */ |
626 | - protected function prepare_links( $object, $request ) { |
|
626 | + protected function prepare_links($object, $request) { |
|
627 | 627 | $product_id = (int) $request['product_id']; |
628 | - $base = str_replace( '(?P<product_id>[\d]+)', $product_id, $this->rest_base ); |
|
628 | + $base = str_replace('(?P<product_id>[\d]+)', $product_id, $this->rest_base); |
|
629 | 629 | $links = array( |
630 | 630 | 'self' => array( |
631 | - 'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $base, $object->get_id() ) ), |
|
631 | + 'href' => rest_url(sprintf('/%s/%s/%d', $this->namespace, $base, $object->get_id())), |
|
632 | 632 | ), |
633 | 633 | 'collection' => array( |
634 | - 'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $base ) ), |
|
634 | + 'href' => rest_url(sprintf('/%s/%s', $this->namespace, $base)), |
|
635 | 635 | ), |
636 | 636 | 'up' => array( |
637 | - 'href' => rest_url( sprintf( '/%s/products/%d', $this->namespace, $product_id ) ), |
|
637 | + 'href' => rest_url(sprintf('/%s/products/%d', $this->namespace, $product_id)), |
|
638 | 638 | ), |
639 | 639 | ); |
640 | 640 | return $links; |
@@ -646,350 +646,350 @@ discard block |
||
646 | 646 | * @return array |
647 | 647 | */ |
648 | 648 | public function get_item_schema() { |
649 | - $weight_unit = get_option( 'woocommerce_weight_unit' ); |
|
650 | - $dimension_unit = get_option( 'woocommerce_dimension_unit' ); |
|
649 | + $weight_unit = get_option('woocommerce_weight_unit'); |
|
650 | + $dimension_unit = get_option('woocommerce_dimension_unit'); |
|
651 | 651 | $schema = array( |
652 | 652 | '$schema' => 'http://json-schema.org/draft-04/schema#', |
653 | 653 | 'title' => $this->post_type, |
654 | 654 | 'type' => 'object', |
655 | 655 | 'properties' => array( |
656 | 656 | 'id' => array( |
657 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
657 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
658 | 658 | 'type' => 'integer', |
659 | - 'context' => array( 'view', 'edit' ), |
|
659 | + 'context' => array('view', 'edit'), |
|
660 | 660 | 'readonly' => true, |
661 | 661 | ), |
662 | 662 | 'date_created' => array( |
663 | - 'description' => __( "The date the variation was created, in the site's timezone.", 'woocommerce' ), |
|
663 | + 'description' => __("The date the variation was created, in the site's timezone.", 'woocommerce'), |
|
664 | 664 | 'type' => 'date-time', |
665 | - 'context' => array( 'view', 'edit' ), |
|
665 | + 'context' => array('view', 'edit'), |
|
666 | 666 | 'readonly' => true, |
667 | 667 | ), |
668 | 668 | 'date_modified' => array( |
669 | - 'description' => __( "The date the variation was last modified, in the site's timezone.", 'woocommerce' ), |
|
669 | + 'description' => __("The date the variation was last modified, in the site's timezone.", 'woocommerce'), |
|
670 | 670 | 'type' => 'date-time', |
671 | - 'context' => array( 'view', 'edit' ), |
|
671 | + 'context' => array('view', 'edit'), |
|
672 | 672 | 'readonly' => true, |
673 | 673 | ), |
674 | 674 | 'description' => array( |
675 | - 'description' => __( 'Variation description.', 'woocommerce' ), |
|
675 | + 'description' => __('Variation description.', 'woocommerce'), |
|
676 | 676 | 'type' => 'string', |
677 | - 'context' => array( 'view', 'edit' ), |
|
677 | + 'context' => array('view', 'edit'), |
|
678 | 678 | ), |
679 | 679 | 'permalink' => array( |
680 | - 'description' => __( 'Variation URL.', 'woocommerce' ), |
|
680 | + 'description' => __('Variation URL.', 'woocommerce'), |
|
681 | 681 | 'type' => 'string', |
682 | 682 | 'format' => 'uri', |
683 | - 'context' => array( 'view', 'edit' ), |
|
683 | + 'context' => array('view', 'edit'), |
|
684 | 684 | 'readonly' => true, |
685 | 685 | ), |
686 | 686 | 'sku' => array( |
687 | - 'description' => __( 'Unique identifier.', 'woocommerce' ), |
|
687 | + 'description' => __('Unique identifier.', 'woocommerce'), |
|
688 | 688 | 'type' => 'string', |
689 | - 'context' => array( 'view', 'edit' ), |
|
689 | + 'context' => array('view', 'edit'), |
|
690 | 690 | ), |
691 | 691 | 'price' => array( |
692 | - 'description' => __( 'Current variation price.', 'woocommerce' ), |
|
692 | + 'description' => __('Current variation price.', 'woocommerce'), |
|
693 | 693 | 'type' => 'string', |
694 | - 'context' => array( 'view', 'edit' ), |
|
694 | + 'context' => array('view', 'edit'), |
|
695 | 695 | 'readonly' => true, |
696 | 696 | ), |
697 | 697 | 'regular_price' => array( |
698 | - 'description' => __( 'Variation regular price.', 'woocommerce' ), |
|
698 | + 'description' => __('Variation regular price.', 'woocommerce'), |
|
699 | 699 | 'type' => 'string', |
700 | - 'context' => array( 'view', 'edit' ), |
|
700 | + 'context' => array('view', 'edit'), |
|
701 | 701 | ), |
702 | 702 | 'sale_price' => array( |
703 | - 'description' => __( 'Variation sale price.', 'woocommerce' ), |
|
703 | + 'description' => __('Variation sale price.', 'woocommerce'), |
|
704 | 704 | 'type' => 'string', |
705 | - 'context' => array( 'view', 'edit' ), |
|
705 | + 'context' => array('view', 'edit'), |
|
706 | 706 | ), |
707 | 707 | 'date_on_sale_from' => array( |
708 | - 'description' => __( "Start date of sale price, in the site's timezone.", 'woocommerce' ), |
|
708 | + 'description' => __("Start date of sale price, in the site's timezone.", 'woocommerce'), |
|
709 | 709 | 'type' => 'date-time', |
710 | - 'context' => array( 'view', 'edit' ), |
|
710 | + 'context' => array('view', 'edit'), |
|
711 | 711 | ), |
712 | 712 | 'date_on_sale_from_gmt' => array( |
713 | - 'description' => __( 'Start date of sale price, as GMT.', 'woocommerce' ), |
|
713 | + 'description' => __('Start date of sale price, as GMT.', 'woocommerce'), |
|
714 | 714 | 'type' => 'date-time', |
715 | - 'context' => array( 'view', 'edit' ), |
|
715 | + 'context' => array('view', 'edit'), |
|
716 | 716 | ), |
717 | 717 | 'date_on_sale_to' => array( |
718 | - 'description' => __( "End date of sale price, in the site's timezone.", 'woocommerce' ), |
|
718 | + 'description' => __("End date of sale price, in the site's timezone.", 'woocommerce'), |
|
719 | 719 | 'type' => 'date-time', |
720 | - 'context' => array( 'view', 'edit' ), |
|
720 | + 'context' => array('view', 'edit'), |
|
721 | 721 | ), |
722 | 722 | 'date_on_sale_to_gmt' => array( |
723 | - 'description' => __( 'End date of sale price, as GMT.', 'woocommerce' ), |
|
723 | + 'description' => __('End date of sale price, as GMT.', 'woocommerce'), |
|
724 | 724 | 'type' => 'date-time', |
725 | - 'context' => array( 'view', 'edit' ), |
|
725 | + 'context' => array('view', 'edit'), |
|
726 | 726 | ), |
727 | 727 | 'on_sale' => array( |
728 | - 'description' => __( 'Shows if the variation is on sale.', 'woocommerce' ), |
|
728 | + 'description' => __('Shows if the variation is on sale.', 'woocommerce'), |
|
729 | 729 | 'type' => 'boolean', |
730 | - 'context' => array( 'view', 'edit' ), |
|
730 | + 'context' => array('view', 'edit'), |
|
731 | 731 | 'readonly' => true, |
732 | 732 | ), |
733 | 733 | 'visible' => array( |
734 | - 'description' => __( "Define if the variation is visible on the product's page.", 'woocommerce' ), |
|
734 | + 'description' => __("Define if the variation is visible on the product's page.", 'woocommerce'), |
|
735 | 735 | 'type' => 'boolean', |
736 | 736 | 'default' => true, |
737 | - 'context' => array( 'view', 'edit' ), |
|
737 | + 'context' => array('view', 'edit'), |
|
738 | 738 | ), |
739 | 739 | 'purchasable' => array( |
740 | - 'description' => __( 'Shows if the variation can be bought.', 'woocommerce' ), |
|
740 | + 'description' => __('Shows if the variation can be bought.', 'woocommerce'), |
|
741 | 741 | 'type' => 'boolean', |
742 | - 'context' => array( 'view', 'edit' ), |
|
742 | + 'context' => array('view', 'edit'), |
|
743 | 743 | 'readonly' => true, |
744 | 744 | ), |
745 | 745 | 'virtual' => array( |
746 | - 'description' => __( 'If the variation is virtual.', 'woocommerce' ), |
|
746 | + 'description' => __('If the variation is virtual.', 'woocommerce'), |
|
747 | 747 | 'type' => 'boolean', |
748 | 748 | 'default' => false, |
749 | - 'context' => array( 'view', 'edit' ), |
|
749 | + 'context' => array('view', 'edit'), |
|
750 | 750 | ), |
751 | 751 | 'downloadable' => array( |
752 | - 'description' => __( 'If the variation is downloadable.', 'woocommerce' ), |
|
752 | + 'description' => __('If the variation is downloadable.', 'woocommerce'), |
|
753 | 753 | 'type' => 'boolean', |
754 | 754 | 'default' => false, |
755 | - 'context' => array( 'view', 'edit' ), |
|
755 | + 'context' => array('view', 'edit'), |
|
756 | 756 | ), |
757 | 757 | 'downloads' => array( |
758 | - 'description' => __( 'List of downloadable files.', 'woocommerce' ), |
|
758 | + 'description' => __('List of downloadable files.', 'woocommerce'), |
|
759 | 759 | 'type' => 'array', |
760 | - 'context' => array( 'view', 'edit' ), |
|
760 | + 'context' => array('view', 'edit'), |
|
761 | 761 | 'items' => array( |
762 | 762 | 'type' => 'object', |
763 | 763 | 'properties' => array( |
764 | 764 | 'id' => array( |
765 | - 'description' => __( 'File ID.', 'woocommerce' ), |
|
765 | + 'description' => __('File ID.', 'woocommerce'), |
|
766 | 766 | 'type' => 'string', |
767 | - 'context' => array( 'view', 'edit' ), |
|
767 | + 'context' => array('view', 'edit'), |
|
768 | 768 | ), |
769 | 769 | 'name' => array( |
770 | - 'description' => __( 'File name.', 'woocommerce' ), |
|
770 | + 'description' => __('File name.', 'woocommerce'), |
|
771 | 771 | 'type' => 'string', |
772 | - 'context' => array( 'view', 'edit' ), |
|
772 | + 'context' => array('view', 'edit'), |
|
773 | 773 | ), |
774 | 774 | 'file' => array( |
775 | - 'description' => __( 'File URL.', 'woocommerce' ), |
|
775 | + 'description' => __('File URL.', 'woocommerce'), |
|
776 | 776 | 'type' => 'string', |
777 | - 'context' => array( 'view', 'edit' ), |
|
777 | + 'context' => array('view', 'edit'), |
|
778 | 778 | ), |
779 | 779 | ), |
780 | 780 | ), |
781 | 781 | ), |
782 | 782 | 'download_limit' => array( |
783 | - 'description' => __( 'Number of times downloadable files can be downloaded after purchase.', 'woocommerce' ), |
|
783 | + 'description' => __('Number of times downloadable files can be downloaded after purchase.', 'woocommerce'), |
|
784 | 784 | 'type' => 'integer', |
785 | 785 | 'default' => -1, |
786 | - 'context' => array( 'view', 'edit' ), |
|
786 | + 'context' => array('view', 'edit'), |
|
787 | 787 | ), |
788 | 788 | 'download_expiry' => array( |
789 | - 'description' => __( 'Number of days until access to downloadable files expires.', 'woocommerce' ), |
|
789 | + 'description' => __('Number of days until access to downloadable files expires.', 'woocommerce'), |
|
790 | 790 | 'type' => 'integer', |
791 | 791 | 'default' => -1, |
792 | - 'context' => array( 'view', 'edit' ), |
|
792 | + 'context' => array('view', 'edit'), |
|
793 | 793 | ), |
794 | 794 | 'tax_status' => array( |
795 | - 'description' => __( 'Tax status.', 'woocommerce' ), |
|
795 | + 'description' => __('Tax status.', 'woocommerce'), |
|
796 | 796 | 'type' => 'string', |
797 | 797 | 'default' => 'taxable', |
798 | - 'enum' => array( 'taxable', 'shipping', 'none' ), |
|
799 | - 'context' => array( 'view', 'edit' ), |
|
798 | + 'enum' => array('taxable', 'shipping', 'none'), |
|
799 | + 'context' => array('view', 'edit'), |
|
800 | 800 | ), |
801 | 801 | 'tax_class' => array( |
802 | - 'description' => __( 'Tax class.', 'woocommerce' ), |
|
802 | + 'description' => __('Tax class.', 'woocommerce'), |
|
803 | 803 | 'type' => 'string', |
804 | - 'context' => array( 'view', 'edit' ), |
|
804 | + 'context' => array('view', 'edit'), |
|
805 | 805 | ), |
806 | 806 | 'manage_stock' => array( |
807 | - 'description' => __( 'Stock management at variation level.', 'woocommerce' ), |
|
807 | + 'description' => __('Stock management at variation level.', 'woocommerce'), |
|
808 | 808 | 'type' => 'mixed', |
809 | 809 | 'default' => false, |
810 | - 'context' => array( 'view', 'edit' ), |
|
810 | + 'context' => array('view', 'edit'), |
|
811 | 811 | ), |
812 | 812 | 'stock_quantity' => array( |
813 | - 'description' => __( 'Stock quantity.', 'woocommerce' ), |
|
813 | + 'description' => __('Stock quantity.', 'woocommerce'), |
|
814 | 814 | 'type' => 'integer', |
815 | - 'context' => array( 'view', 'edit' ), |
|
815 | + 'context' => array('view', 'edit'), |
|
816 | 816 | ), |
817 | 817 | 'in_stock' => array( |
818 | - 'description' => __( 'Controls whether or not the variation is listed as "in stock" or "out of stock" on the frontend.', 'woocommerce' ), |
|
818 | + 'description' => __('Controls whether or not the variation is listed as "in stock" or "out of stock" on the frontend.', 'woocommerce'), |
|
819 | 819 | 'type' => 'boolean', |
820 | 820 | 'default' => true, |
821 | - 'context' => array( 'view', 'edit' ), |
|
821 | + 'context' => array('view', 'edit'), |
|
822 | 822 | ), |
823 | 823 | 'backorders' => array( |
824 | - 'description' => __( 'If managing stock, this controls if backorders are allowed.', 'woocommerce' ), |
|
824 | + 'description' => __('If managing stock, this controls if backorders are allowed.', 'woocommerce'), |
|
825 | 825 | 'type' => 'string', |
826 | 826 | 'default' => 'no', |
827 | - 'enum' => array( 'no', 'notify', 'yes' ), |
|
828 | - 'context' => array( 'view', 'edit' ), |
|
827 | + 'enum' => array('no', 'notify', 'yes'), |
|
828 | + 'context' => array('view', 'edit'), |
|
829 | 829 | ), |
830 | 830 | 'backorders_allowed' => array( |
831 | - 'description' => __( 'Shows if backorders are allowed.', 'woocommerce' ), |
|
831 | + 'description' => __('Shows if backorders are allowed.', 'woocommerce'), |
|
832 | 832 | 'type' => 'boolean', |
833 | - 'context' => array( 'view', 'edit' ), |
|
833 | + 'context' => array('view', 'edit'), |
|
834 | 834 | 'readonly' => true, |
835 | 835 | ), |
836 | 836 | 'backordered' => array( |
837 | - 'description' => __( 'Shows if the variation is on backordered.', 'woocommerce' ), |
|
837 | + 'description' => __('Shows if the variation is on backordered.', 'woocommerce'), |
|
838 | 838 | 'type' => 'boolean', |
839 | - 'context' => array( 'view', 'edit' ), |
|
839 | + 'context' => array('view', 'edit'), |
|
840 | 840 | 'readonly' => true, |
841 | 841 | ), |
842 | 842 | 'weight' => array( |
843 | 843 | /* translators: %s: weight unit */ |
844 | - 'description' => sprintf( __( 'Variation weight (%s).', 'woocommerce' ), $weight_unit ), |
|
844 | + 'description' => sprintf(__('Variation weight (%s).', 'woocommerce'), $weight_unit), |
|
845 | 845 | 'type' => 'string', |
846 | - 'context' => array( 'view', 'edit' ), |
|
846 | + 'context' => array('view', 'edit'), |
|
847 | 847 | ), |
848 | 848 | 'dimensions' => array( |
849 | - 'description' => __( 'Variation dimensions.', 'woocommerce' ), |
|
849 | + 'description' => __('Variation dimensions.', 'woocommerce'), |
|
850 | 850 | 'type' => 'object', |
851 | - 'context' => array( 'view', 'edit' ), |
|
851 | + 'context' => array('view', 'edit'), |
|
852 | 852 | 'properties' => array( |
853 | 853 | 'length' => array( |
854 | 854 | /* translators: %s: dimension unit */ |
855 | - 'description' => sprintf( __( 'Variation length (%s).', 'woocommerce' ), $dimension_unit ), |
|
855 | + 'description' => sprintf(__('Variation length (%s).', 'woocommerce'), $dimension_unit), |
|
856 | 856 | 'type' => 'string', |
857 | - 'context' => array( 'view', 'edit' ), |
|
857 | + 'context' => array('view', 'edit'), |
|
858 | 858 | ), |
859 | 859 | 'width' => array( |
860 | 860 | /* translators: %s: dimension unit */ |
861 | - 'description' => sprintf( __( 'Variation width (%s).', 'woocommerce' ), $dimension_unit ), |
|
861 | + 'description' => sprintf(__('Variation width (%s).', 'woocommerce'), $dimension_unit), |
|
862 | 862 | 'type' => 'string', |
863 | - 'context' => array( 'view', 'edit' ), |
|
863 | + 'context' => array('view', 'edit'), |
|
864 | 864 | ), |
865 | 865 | 'height' => array( |
866 | 866 | /* translators: %s: dimension unit */ |
867 | - 'description' => sprintf( __( 'Variation height (%s).', 'woocommerce' ), $dimension_unit ), |
|
867 | + 'description' => sprintf(__('Variation height (%s).', 'woocommerce'), $dimension_unit), |
|
868 | 868 | 'type' => 'string', |
869 | - 'context' => array( 'view', 'edit' ), |
|
869 | + 'context' => array('view', 'edit'), |
|
870 | 870 | ), |
871 | 871 | ), |
872 | 872 | ), |
873 | 873 | 'shipping_class' => array( |
874 | - 'description' => __( 'Shipping class slug.', 'woocommerce' ), |
|
874 | + 'description' => __('Shipping class slug.', 'woocommerce'), |
|
875 | 875 | 'type' => 'string', |
876 | - 'context' => array( 'view', 'edit' ), |
|
876 | + 'context' => array('view', 'edit'), |
|
877 | 877 | ), |
878 | 878 | 'shipping_class_id' => array( |
879 | - 'description' => __( 'Shipping class ID.', 'woocommerce' ), |
|
879 | + 'description' => __('Shipping class ID.', 'woocommerce'), |
|
880 | 880 | 'type' => 'string', |
881 | - 'context' => array( 'view', 'edit' ), |
|
881 | + 'context' => array('view', 'edit'), |
|
882 | 882 | 'readonly' => true, |
883 | 883 | ), |
884 | 884 | 'image' => array( |
885 | - 'description' => __( 'Variation image data.', 'woocommerce' ), |
|
885 | + 'description' => __('Variation image data.', 'woocommerce'), |
|
886 | 886 | 'type' => 'object', |
887 | - 'context' => array( 'view', 'edit' ), |
|
887 | + 'context' => array('view', 'edit'), |
|
888 | 888 | 'properties' => array( |
889 | 889 | 'id' => array( |
890 | - 'description' => __( 'Image ID.', 'woocommerce' ), |
|
890 | + 'description' => __('Image ID.', 'woocommerce'), |
|
891 | 891 | 'type' => 'integer', |
892 | - 'context' => array( 'view', 'edit' ), |
|
892 | + 'context' => array('view', 'edit'), |
|
893 | 893 | ), |
894 | 894 | 'date_created' => array( |
895 | - 'description' => __( "The date the image was created, in the site's timezone.", 'woocommerce' ), |
|
895 | + 'description' => __("The date the image was created, in the site's timezone.", 'woocommerce'), |
|
896 | 896 | 'type' => 'date-time', |
897 | - 'context' => array( 'view', 'edit' ), |
|
897 | + 'context' => array('view', 'edit'), |
|
898 | 898 | 'readonly' => true, |
899 | 899 | ), |
900 | 900 | 'date_created_gmt' => array( |
901 | - 'description' => __( 'The date the image was created, as GMT.', 'woocommerce' ), |
|
901 | + 'description' => __('The date the image was created, as GMT.', 'woocommerce'), |
|
902 | 902 | 'type' => 'date-time', |
903 | - 'context' => array( 'view', 'edit' ), |
|
903 | + 'context' => array('view', 'edit'), |
|
904 | 904 | 'readonly' => true, |
905 | 905 | ), |
906 | 906 | 'date_modified' => array( |
907 | - 'description' => __( "The date the image was last modified, in the site's timezone.", 'woocommerce' ), |
|
907 | + 'description' => __("The date the image was last modified, in the site's timezone.", 'woocommerce'), |
|
908 | 908 | 'type' => 'date-time', |
909 | - 'context' => array( 'view', 'edit' ), |
|
909 | + 'context' => array('view', 'edit'), |
|
910 | 910 | 'readonly' => true, |
911 | 911 | ), |
912 | 912 | 'date_modified_gmt' => array( |
913 | - 'description' => __( 'The date the image was last modified, as GMT.', 'woocommerce' ), |
|
913 | + 'description' => __('The date the image was last modified, as GMT.', 'woocommerce'), |
|
914 | 914 | 'type' => 'date-time', |
915 | - 'context' => array( 'view', 'edit' ), |
|
915 | + 'context' => array('view', 'edit'), |
|
916 | 916 | 'readonly' => true, |
917 | 917 | ), |
918 | 918 | 'src' => array( |
919 | - 'description' => __( 'Image URL.', 'woocommerce' ), |
|
919 | + 'description' => __('Image URL.', 'woocommerce'), |
|
920 | 920 | 'type' => 'string', |
921 | 921 | 'format' => 'uri', |
922 | - 'context' => array( 'view', 'edit' ), |
|
922 | + 'context' => array('view', 'edit'), |
|
923 | 923 | ), |
924 | 924 | 'name' => array( |
925 | - 'description' => __( 'Image name.', 'woocommerce' ), |
|
925 | + 'description' => __('Image name.', 'woocommerce'), |
|
926 | 926 | 'type' => 'string', |
927 | - 'context' => array( 'view', 'edit' ), |
|
927 | + 'context' => array('view', 'edit'), |
|
928 | 928 | ), |
929 | 929 | 'alt' => array( |
930 | - 'description' => __( 'Image alternative text.', 'woocommerce' ), |
|
930 | + 'description' => __('Image alternative text.', 'woocommerce'), |
|
931 | 931 | 'type' => 'string', |
932 | - 'context' => array( 'view', 'edit' ), |
|
932 | + 'context' => array('view', 'edit'), |
|
933 | 933 | ), |
934 | 934 | 'position' => array( |
935 | - 'description' => __( 'Image position. 0 means that the image is featured.', 'woocommerce' ), |
|
935 | + 'description' => __('Image position. 0 means that the image is featured.', 'woocommerce'), |
|
936 | 936 | 'type' => 'integer', |
937 | - 'context' => array( 'view', 'edit' ), |
|
937 | + 'context' => array('view', 'edit'), |
|
938 | 938 | ), |
939 | 939 | ), |
940 | 940 | ), |
941 | 941 | 'attributes' => array( |
942 | - 'description' => __( 'List of attributes.', 'woocommerce' ), |
|
942 | + 'description' => __('List of attributes.', 'woocommerce'), |
|
943 | 943 | 'type' => 'array', |
944 | - 'context' => array( 'view', 'edit' ), |
|
944 | + 'context' => array('view', 'edit'), |
|
945 | 945 | 'items' => array( |
946 | 946 | 'type' => 'object', |
947 | 947 | 'properties' => array( |
948 | 948 | 'id' => array( |
949 | - 'description' => __( 'Attribute ID.', 'woocommerce' ), |
|
949 | + 'description' => __('Attribute ID.', 'woocommerce'), |
|
950 | 950 | 'type' => 'integer', |
951 | - 'context' => array( 'view', 'edit' ), |
|
951 | + 'context' => array('view', 'edit'), |
|
952 | 952 | ), |
953 | 953 | 'name' => array( |
954 | - 'description' => __( 'Attribute name.', 'woocommerce' ), |
|
954 | + 'description' => __('Attribute name.', 'woocommerce'), |
|
955 | 955 | 'type' => 'string', |
956 | - 'context' => array( 'view', 'edit' ), |
|
956 | + 'context' => array('view', 'edit'), |
|
957 | 957 | ), |
958 | 958 | 'option' => array( |
959 | - 'description' => __( 'Selected attribute term name.', 'woocommerce' ), |
|
959 | + 'description' => __('Selected attribute term name.', 'woocommerce'), |
|
960 | 960 | 'type' => 'string', |
961 | - 'context' => array( 'view', 'edit' ), |
|
961 | + 'context' => array('view', 'edit'), |
|
962 | 962 | ), |
963 | 963 | ), |
964 | 964 | ), |
965 | 965 | ), |
966 | 966 | 'menu_order' => array( |
967 | - 'description' => __( 'Menu order, used to custom sort products.', 'woocommerce' ), |
|
967 | + 'description' => __('Menu order, used to custom sort products.', 'woocommerce'), |
|
968 | 968 | 'type' => 'integer', |
969 | - 'context' => array( 'view', 'edit' ), |
|
969 | + 'context' => array('view', 'edit'), |
|
970 | 970 | ), |
971 | 971 | 'meta_data' => array( |
972 | - 'description' => __( 'Meta data.', 'woocommerce' ), |
|
972 | + 'description' => __('Meta data.', 'woocommerce'), |
|
973 | 973 | 'type' => 'array', |
974 | - 'context' => array( 'view', 'edit' ), |
|
974 | + 'context' => array('view', 'edit'), |
|
975 | 975 | 'items' => array( |
976 | 976 | 'type' => 'object', |
977 | 977 | 'properties' => array( |
978 | 978 | 'id' => array( |
979 | - 'description' => __( 'Meta ID.', 'woocommerce' ), |
|
979 | + 'description' => __('Meta ID.', 'woocommerce'), |
|
980 | 980 | 'type' => 'integer', |
981 | - 'context' => array( 'view', 'edit' ), |
|
981 | + 'context' => array('view', 'edit'), |
|
982 | 982 | 'readonly' => true, |
983 | 983 | ), |
984 | 984 | 'key' => array( |
985 | - 'description' => __( 'Meta key.', 'woocommerce' ), |
|
985 | + 'description' => __('Meta key.', 'woocommerce'), |
|
986 | 986 | 'type' => 'string', |
987 | - 'context' => array( 'view', 'edit' ), |
|
987 | + 'context' => array('view', 'edit'), |
|
988 | 988 | ), |
989 | 989 | 'value' => array( |
990 | - 'description' => __( 'Meta value.', 'woocommerce' ), |
|
990 | + 'description' => __('Meta value.', 'woocommerce'), |
|
991 | 991 | 'type' => 'mixed', |
992 | - 'context' => array( 'view', 'edit' ), |
|
992 | + 'context' => array('view', 'edit'), |
|
993 | 993 | ), |
994 | 994 | ), |
995 | 995 | ), |
@@ -997,6 +997,6 @@ discard block |
||
997 | 997 | ), |
998 | 998 | ); |
999 | 999 | |
1000 | - return $this->add_additional_fields_schema( $schema ); |
|
1000 | + return $this->add_additional_fields_schema($schema); |
|
1001 | 1001 | } |
1002 | 1002 | } |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * @since 2.6.0 |
9 | 9 | */ |
10 | 10 | |
11 | -defined( 'ABSPATH' ) || exit; |
|
11 | +defined('ABSPATH') || exit; |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * REST API Webhook Deliveries controller class. |
@@ -33,17 +33,17 @@ discard block |
||
33 | 33 | * @param WP_REST_Request $request Request object. |
34 | 34 | * @return WP_REST_Response |
35 | 35 | */ |
36 | - public function prepare_item_for_response( $log, $request ) { |
|
36 | + public function prepare_item_for_response($log, $request) { |
|
37 | 37 | $data = (array) $log; |
38 | 38 | |
39 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
40 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
41 | - $data = $this->filter_response_by_context( $data, $context ); |
|
39 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
40 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
41 | + $data = $this->filter_response_by_context($data, $context); |
|
42 | 42 | |
43 | 43 | // Wrap the data in a response object. |
44 | - $response = rest_ensure_response( $data ); |
|
44 | + $response = rest_ensure_response($data); |
|
45 | 45 | |
46 | - $response->add_links( $this->prepare_links( $log ) ); |
|
46 | + $response->add_links($this->prepare_links($log)); |
|
47 | 47 | |
48 | 48 | /** |
49 | 49 | * Filter webhook delivery object returned from the REST API. |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | * @param stdClass $log Delivery log object used to create response. |
53 | 53 | * @param WP_REST_Request $request Request object. |
54 | 54 | */ |
55 | - return apply_filters( 'woocommerce_rest_prepare_webhook_delivery', $response, $log, $request ); |
|
55 | + return apply_filters('woocommerce_rest_prepare_webhook_delivery', $response, $log, $request); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | /** |
@@ -67,87 +67,87 @@ discard block |
||
67 | 67 | 'type' => 'object', |
68 | 68 | 'properties' => array( |
69 | 69 | 'id' => array( |
70 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
70 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
71 | 71 | 'type' => 'integer', |
72 | - 'context' => array( 'view' ), |
|
72 | + 'context' => array('view'), |
|
73 | 73 | 'readonly' => true, |
74 | 74 | ), |
75 | 75 | 'duration' => array( |
76 | - 'description' => __( 'The delivery duration, in seconds.', 'woocommerce' ), |
|
76 | + 'description' => __('The delivery duration, in seconds.', 'woocommerce'), |
|
77 | 77 | 'type' => 'string', |
78 | - 'context' => array( 'view' ), |
|
78 | + 'context' => array('view'), |
|
79 | 79 | 'readonly' => true, |
80 | 80 | ), |
81 | 81 | 'summary' => array( |
82 | - 'description' => __( 'A friendly summary of the response including the HTTP response code, message, and body.', 'woocommerce' ), |
|
82 | + 'description' => __('A friendly summary of the response including the HTTP response code, message, and body.', 'woocommerce'), |
|
83 | 83 | 'type' => 'string', |
84 | - 'context' => array( 'view' ), |
|
84 | + 'context' => array('view'), |
|
85 | 85 | 'readonly' => true, |
86 | 86 | ), |
87 | 87 | 'request_url' => array( |
88 | - 'description' => __( 'The URL where the webhook was delivered.', 'woocommerce' ), |
|
88 | + 'description' => __('The URL where the webhook was delivered.', 'woocommerce'), |
|
89 | 89 | 'type' => 'string', |
90 | 90 | 'format' => 'uri', |
91 | - 'context' => array( 'view' ), |
|
91 | + 'context' => array('view'), |
|
92 | 92 | 'readonly' => true, |
93 | 93 | ), |
94 | 94 | 'request_headers' => array( |
95 | - 'description' => __( 'Request headers.', 'woocommerce' ), |
|
95 | + 'description' => __('Request headers.', 'woocommerce'), |
|
96 | 96 | 'type' => 'array', |
97 | - 'context' => array( 'view' ), |
|
97 | + 'context' => array('view'), |
|
98 | 98 | 'readonly' => true, |
99 | 99 | 'items' => array( |
100 | 100 | 'type' => 'string', |
101 | 101 | ), |
102 | 102 | ), |
103 | 103 | 'request_body' => array( |
104 | - 'description' => __( 'Request body.', 'woocommerce' ), |
|
104 | + 'description' => __('Request body.', 'woocommerce'), |
|
105 | 105 | 'type' => 'string', |
106 | - 'context' => array( 'view' ), |
|
106 | + 'context' => array('view'), |
|
107 | 107 | 'readonly' => true, |
108 | 108 | ), |
109 | 109 | 'response_code' => array( |
110 | - 'description' => __( 'The HTTP response code from the receiving server.', 'woocommerce' ), |
|
110 | + 'description' => __('The HTTP response code from the receiving server.', 'woocommerce'), |
|
111 | 111 | 'type' => 'string', |
112 | - 'context' => array( 'view' ), |
|
112 | + 'context' => array('view'), |
|
113 | 113 | 'readonly' => true, |
114 | 114 | ), |
115 | 115 | 'response_message' => array( |
116 | - 'description' => __( 'The HTTP response message from the receiving server.', 'woocommerce' ), |
|
116 | + 'description' => __('The HTTP response message from the receiving server.', 'woocommerce'), |
|
117 | 117 | 'type' => 'string', |
118 | - 'context' => array( 'view' ), |
|
118 | + 'context' => array('view'), |
|
119 | 119 | 'readonly' => true, |
120 | 120 | ), |
121 | 121 | 'response_headers' => array( |
122 | - 'description' => __( 'Array of the response headers from the receiving server.', 'woocommerce' ), |
|
122 | + 'description' => __('Array of the response headers from the receiving server.', 'woocommerce'), |
|
123 | 123 | 'type' => 'array', |
124 | - 'context' => array( 'view' ), |
|
124 | + 'context' => array('view'), |
|
125 | 125 | 'readonly' => true, |
126 | 126 | 'items' => array( |
127 | 127 | 'type' => 'string', |
128 | 128 | ), |
129 | 129 | ), |
130 | 130 | 'response_body' => array( |
131 | - 'description' => __( 'The response body from the receiving server.', 'woocommerce' ), |
|
131 | + 'description' => __('The response body from the receiving server.', 'woocommerce'), |
|
132 | 132 | 'type' => 'string', |
133 | - 'context' => array( 'view' ), |
|
133 | + 'context' => array('view'), |
|
134 | 134 | 'readonly' => true, |
135 | 135 | ), |
136 | 136 | 'date_created' => array( |
137 | - 'description' => __( "The date the webhook delivery was logged, in the site's timezone.", 'woocommerce' ), |
|
137 | + 'description' => __("The date the webhook delivery was logged, in the site's timezone.", 'woocommerce'), |
|
138 | 138 | 'type' => 'date-time', |
139 | - 'context' => array( 'view', 'edit' ), |
|
139 | + 'context' => array('view', 'edit'), |
|
140 | 140 | 'readonly' => true, |
141 | 141 | ), |
142 | 142 | 'date_created_gmt' => array( |
143 | - 'description' => __( 'The date the webhook delivery was logged, as GMT.', 'woocommerce' ), |
|
143 | + 'description' => __('The date the webhook delivery was logged, as GMT.', 'woocommerce'), |
|
144 | 144 | 'type' => 'date-time', |
145 | - 'context' => array( 'view', 'edit' ), |
|
145 | + 'context' => array('view', 'edit'), |
|
146 | 146 | 'readonly' => true, |
147 | 147 | ), |
148 | 148 | ), |
149 | 149 | ); |
150 | 150 | |
151 | - return $this->add_additional_fields_schema( $schema ); |
|
151 | + return $this->add_additional_fields_schema($schema); |
|
152 | 152 | } |
153 | 153 | } |
@@ -8,7 +8,7 @@ |
||
8 | 8 | * @since 2.6.0 |
9 | 9 | */ |
10 | 10 | |
11 | -defined( 'ABSPATH' ) || exit; |
|
11 | +defined('ABSPATH') || exit; |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * REST API Product Attribute Terms controller class. |
@@ -8,7 +8,7 @@ |
||
8 | 8 | * @since 2.6.0 |
9 | 9 | */ |
10 | 10 | |
11 | -defined( 'ABSPATH' ) || exit; |
|
11 | +defined('ABSPATH') || exit; |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * REST API Report Top Sellers controller class. |
@@ -8,7 +8,7 @@ |
||
8 | 8 | * @since 2.6.0 |
9 | 9 | */ |
10 | 10 | |
11 | -defined( 'ABSPATH' ) || exit; |
|
11 | +defined('ABSPATH') || exit; |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * REST API Product Attributes controller class. |