1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* REST API WC System Status controller |
4
|
|
|
* |
5
|
|
|
* Handles requests to the /system_status endpoint. |
6
|
|
|
* |
7
|
|
|
* @package WooCommerce/RestApi |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace WooCommerce\RestApi\Controllers\Version4; |
11
|
|
|
|
12
|
|
|
defined( 'ABSPATH' ) || exit; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* REST API System Status controller class. |
16
|
|
|
*/ |
17
|
|
|
class SystemStatus extends AbstractController { |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Route base. |
21
|
|
|
* |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
protected $rest_base = 'system_status'; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Register the route for /system_status |
28
|
|
|
*/ |
29
|
|
|
public function register_routes() { |
30
|
|
|
register_rest_route( |
31
|
|
|
$this->namespace, |
32
|
|
|
'/' . $this->rest_base, |
33
|
|
|
array( |
34
|
|
|
array( |
35
|
|
|
'methods' => \WP_REST_Server::READABLE, |
|
|
|
|
36
|
|
|
'callback' => array( $this, 'get_items' ), |
37
|
|
|
'permission_callback' => array( $this, 'get_items_permissions_check' ), |
38
|
|
|
'args' => $this->get_collection_params(), |
39
|
|
|
), |
40
|
|
|
'schema' => array( $this, 'get_public_item_schema' ), |
41
|
|
|
), |
42
|
|
|
true |
43
|
|
|
); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Check whether a given request has permission to view system status. |
48
|
|
|
* |
49
|
|
|
* @param \WP_REST_Request $request Full details about the request. |
|
|
|
|
50
|
|
|
* @return \WP_Error|boolean |
51
|
|
|
*/ |
52
|
|
|
public function get_items_permissions_check( $request ) { |
53
|
|
|
if ( ! wc_rest_check_manager_permissions( 'system_status', 'read' ) ) { |
54
|
|
|
return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
|
|
|
55
|
|
|
} |
56
|
|
|
return true; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Get a system status info, by section. |
61
|
|
|
* |
62
|
|
|
* @param \WP_REST_Request $request Full details about the request. |
63
|
|
|
* @return \WP_Error\WP_REST_Response |
|
|
|
|
64
|
|
|
*/ |
65
|
|
|
public function get_items( $request ) { |
66
|
|
|
$schema = $this->get_item_schema(); |
67
|
|
|
$mappings = $this->get_item_mappings(); |
68
|
|
|
$response = array(); |
69
|
|
|
|
70
|
|
|
foreach ( $mappings as $section => $values ) { |
71
|
|
|
foreach ( $values as $key => $value ) { |
72
|
|
|
if ( isset( $schema['properties'][ $section ]['properties'][ $key ]['type'] ) ) { |
73
|
|
|
settype( $values[ $key ], $schema['properties'][ $section ]['properties'][ $key ]['type'] ); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
settype( $values, $schema['properties'][ $section ]['type'] ); |
77
|
|
|
$response[ $section ] = $values; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
$response = $this->prepare_item_for_response( $response, $request ); |
81
|
|
|
|
82
|
|
|
return rest_ensure_response( $response ); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Get the system status schema, conforming to JSON Schema. |
87
|
|
|
* |
88
|
|
|
* @return array |
89
|
|
|
*/ |
90
|
|
|
public function get_item_schema() { |
91
|
|
|
$schema = array( |
92
|
|
|
'$schema' => 'http://json-schema.org/draft-04/schema#', |
93
|
|
|
'title' => 'system_status', |
94
|
|
|
'type' => 'object', |
95
|
|
|
'properties' => array( |
96
|
|
|
'environment' => array( |
97
|
|
|
'description' => __( 'Environment.', 'woocommerce' ), |
98
|
|
|
'type' => 'object', |
99
|
|
|
'context' => array( 'view' ), |
100
|
|
|
'readonly' => true, |
101
|
|
|
'properties' => array( |
102
|
|
|
'home_url' => array( |
103
|
|
|
'description' => __( 'Home URL.', 'woocommerce' ), |
104
|
|
|
'type' => 'string', |
105
|
|
|
'format' => 'uri', |
106
|
|
|
'context' => array( 'view' ), |
107
|
|
|
'readonly' => true, |
108
|
|
|
), |
109
|
|
|
'site_url' => array( |
110
|
|
|
'description' => __( 'Site URL.', 'woocommerce' ), |
111
|
|
|
'type' => 'string', |
112
|
|
|
'format' => 'uri', |
113
|
|
|
'context' => array( 'view' ), |
114
|
|
|
'readonly' => true, |
115
|
|
|
), |
116
|
|
|
'wc_version' => array( |
117
|
|
|
'description' => __( 'WooCommerce version.', 'woocommerce' ), |
118
|
|
|
'type' => 'string', |
119
|
|
|
'context' => array( 'view' ), |
120
|
|
|
'readonly' => true, |
121
|
|
|
), |
122
|
|
|
'log_directory' => array( |
123
|
|
|
'description' => __( 'Log directory.', 'woocommerce' ), |
124
|
|
|
'type' => 'string', |
125
|
|
|
'context' => array( 'view' ), |
126
|
|
|
'readonly' => true, |
127
|
|
|
), |
128
|
|
|
'log_directory_writable' => array( |
129
|
|
|
'description' => __( 'Is log directory writable?', 'woocommerce' ), |
130
|
|
|
'type' => 'boolean', |
131
|
|
|
'context' => array( 'view' ), |
132
|
|
|
'readonly' => true, |
133
|
|
|
), |
134
|
|
|
'wp_version' => array( |
135
|
|
|
'description' => __( 'WordPress version.', 'woocommerce' ), |
136
|
|
|
'type' => 'string', |
137
|
|
|
'context' => array( 'view' ), |
138
|
|
|
'readonly' => true, |
139
|
|
|
), |
140
|
|
|
'wp_multisite' => array( |
141
|
|
|
'description' => __( 'Is WordPress multisite?', 'woocommerce' ), |
142
|
|
|
'type' => 'boolean', |
143
|
|
|
'context' => array( 'view' ), |
144
|
|
|
'readonly' => true, |
145
|
|
|
), |
146
|
|
|
'wp_memory_limit' => array( |
147
|
|
|
'description' => __( 'WordPress memory limit.', 'woocommerce' ), |
148
|
|
|
'type' => 'integer', |
149
|
|
|
'context' => array( 'view' ), |
150
|
|
|
'readonly' => true, |
151
|
|
|
), |
152
|
|
|
'wp_debug_mode' => array( |
153
|
|
|
'description' => __( 'Is WordPress debug mode active?', 'woocommerce' ), |
154
|
|
|
'type' => 'boolean', |
155
|
|
|
'context' => array( 'view' ), |
156
|
|
|
'readonly' => true, |
157
|
|
|
), |
158
|
|
|
'wp_cron' => array( |
159
|
|
|
'description' => __( 'Are WordPress cron jobs enabled?', 'woocommerce' ), |
160
|
|
|
'type' => 'boolean', |
161
|
|
|
'context' => array( 'view' ), |
162
|
|
|
'readonly' => true, |
163
|
|
|
), |
164
|
|
|
'language' => array( |
165
|
|
|
'description' => __( 'WordPress language.', 'woocommerce' ), |
166
|
|
|
'type' => 'string', |
167
|
|
|
'context' => array( 'view' ), |
168
|
|
|
'readonly' => true, |
169
|
|
|
), |
170
|
|
|
'server_info' => array( |
171
|
|
|
'description' => __( 'Server info.', 'woocommerce' ), |
172
|
|
|
'type' => 'string', |
173
|
|
|
'context' => array( 'view' ), |
174
|
|
|
'readonly' => true, |
175
|
|
|
), |
176
|
|
|
'php_version' => array( |
177
|
|
|
'description' => __( 'PHP version.', 'woocommerce' ), |
178
|
|
|
'type' => 'string', |
179
|
|
|
'context' => array( 'view' ), |
180
|
|
|
'readonly' => true, |
181
|
|
|
), |
182
|
|
|
'php_post_max_size' => array( |
183
|
|
|
'description' => __( 'PHP post max size.', 'woocommerce' ), |
184
|
|
|
'type' => 'integer', |
185
|
|
|
'context' => array( 'view' ), |
186
|
|
|
'readonly' => true, |
187
|
|
|
), |
188
|
|
|
'php_max_execution_time' => array( |
189
|
|
|
'description' => __( 'PHP max execution time.', 'woocommerce' ), |
190
|
|
|
'type' => 'integer', |
191
|
|
|
'context' => array( 'view' ), |
192
|
|
|
'readonly' => true, |
193
|
|
|
), |
194
|
|
|
'php_max_input_vars' => array( |
195
|
|
|
'description' => __( 'PHP max input vars.', 'woocommerce' ), |
196
|
|
|
'type' => 'integer', |
197
|
|
|
'context' => array( 'view' ), |
198
|
|
|
'readonly' => true, |
199
|
|
|
), |
200
|
|
|
'curl_version' => array( |
201
|
|
|
'description' => __( 'cURL version.', 'woocommerce' ), |
202
|
|
|
'type' => 'string', |
203
|
|
|
'context' => array( 'view' ), |
204
|
|
|
'readonly' => true, |
205
|
|
|
), |
206
|
|
|
'suhosin_installed' => array( |
207
|
|
|
'description' => __( 'Is SUHOSIN installed?', 'woocommerce' ), |
208
|
|
|
'type' => 'boolean', |
209
|
|
|
'context' => array( 'view' ), |
210
|
|
|
'readonly' => true, |
211
|
|
|
), |
212
|
|
|
'max_upload_size' => array( |
213
|
|
|
'description' => __( 'Max upload size.', 'woocommerce' ), |
214
|
|
|
'type' => 'integer', |
215
|
|
|
'context' => array( 'view' ), |
216
|
|
|
'readonly' => true, |
217
|
|
|
), |
218
|
|
|
'mysql_version' => array( |
219
|
|
|
'description' => __( 'MySQL version.', 'woocommerce' ), |
220
|
|
|
'type' => 'string', |
221
|
|
|
'context' => array( 'view' ), |
222
|
|
|
'readonly' => true, |
223
|
|
|
), |
224
|
|
|
'mysql_version_string' => array( |
225
|
|
|
'description' => __( 'MySQL version string.', 'woocommerce' ), |
226
|
|
|
'type' => 'string', |
227
|
|
|
'context' => array( 'view' ), |
228
|
|
|
'readonly' => true, |
229
|
|
|
), |
230
|
|
|
'default_timezone' => array( |
231
|
|
|
'description' => __( 'Default timezone.', 'woocommerce' ), |
232
|
|
|
'type' => 'string', |
233
|
|
|
'context' => array( 'view' ), |
234
|
|
|
'readonly' => true, |
235
|
|
|
), |
236
|
|
|
'fsockopen_or_curl_enabled' => array( |
237
|
|
|
'description' => __( 'Is fsockopen/cURL enabled?', 'woocommerce' ), |
238
|
|
|
'type' => 'boolean', |
239
|
|
|
'context' => array( 'view' ), |
240
|
|
|
'readonly' => true, |
241
|
|
|
), |
242
|
|
|
'soapclient_enabled' => array( |
243
|
|
|
'description' => __( 'Is SoapClient class enabled?', 'woocommerce' ), |
244
|
|
|
'type' => 'boolean', |
245
|
|
|
'context' => array( 'view' ), |
246
|
|
|
'readonly' => true, |
247
|
|
|
), |
248
|
|
|
'domdocument_enabled' => array( |
249
|
|
|
'description' => __( 'Is DomDocument class enabled?', 'woocommerce' ), |
250
|
|
|
'type' => 'boolean', |
251
|
|
|
'context' => array( 'view' ), |
252
|
|
|
'readonly' => true, |
253
|
|
|
), |
254
|
|
|
'gzip_enabled' => array( |
255
|
|
|
'description' => __( 'Is GZip enabled?', 'woocommerce' ), |
256
|
|
|
'type' => 'boolean', |
257
|
|
|
'context' => array( 'view' ), |
258
|
|
|
'readonly' => true, |
259
|
|
|
), |
260
|
|
|
'mbstring_enabled' => array( |
261
|
|
|
'description' => __( 'Is mbstring enabled?', 'woocommerce' ), |
262
|
|
|
'type' => 'boolean', |
263
|
|
|
'context' => array( 'view' ), |
264
|
|
|
'readonly' => true, |
265
|
|
|
), |
266
|
|
|
'remote_post_successful' => array( |
267
|
|
|
'description' => __( 'Remote POST successful?', 'woocommerce' ), |
268
|
|
|
'type' => 'boolean', |
269
|
|
|
'context' => array( 'view' ), |
270
|
|
|
'readonly' => true, |
271
|
|
|
), |
272
|
|
|
'remote_post_response' => array( |
273
|
|
|
'description' => __( 'Remote POST response.', 'woocommerce' ), |
274
|
|
|
'type' => 'string', |
275
|
|
|
'context' => array( 'view' ), |
276
|
|
|
'readonly' => true, |
277
|
|
|
), |
278
|
|
|
'remote_get_successful' => array( |
279
|
|
|
'description' => __( 'Remote GET successful?', 'woocommerce' ), |
280
|
|
|
'type' => 'boolean', |
281
|
|
|
'context' => array( 'view' ), |
282
|
|
|
'readonly' => true, |
283
|
|
|
), |
284
|
|
|
'remote_get_response' => array( |
285
|
|
|
'description' => __( 'Remote GET response.', 'woocommerce' ), |
286
|
|
|
'type' => 'string', |
287
|
|
|
'context' => array( 'view' ), |
288
|
|
|
'readonly' => true, |
289
|
|
|
), |
290
|
|
|
), |
291
|
|
|
), |
292
|
|
|
'database' => array( |
293
|
|
|
'description' => __( 'Database.', 'woocommerce' ), |
294
|
|
|
'type' => 'object', |
295
|
|
|
'context' => array( 'view' ), |
296
|
|
|
'readonly' => true, |
297
|
|
|
'properties' => array( |
298
|
|
|
'wc_database_version' => array( |
299
|
|
|
'description' => __( 'WC database version.', 'woocommerce' ), |
300
|
|
|
'type' => 'string', |
301
|
|
|
'context' => array( 'view' ), |
302
|
|
|
'readonly' => true, |
303
|
|
|
), |
304
|
|
|
'database_prefix' => array( |
305
|
|
|
'description' => __( 'Database prefix.', 'woocommerce' ), |
306
|
|
|
'type' => 'string', |
307
|
|
|
'context' => array( 'view' ), |
308
|
|
|
'readonly' => true, |
309
|
|
|
), |
310
|
|
|
'maxmind_geoip_database' => array( |
311
|
|
|
'description' => __( 'MaxMind GeoIP database.', 'woocommerce' ), |
312
|
|
|
'type' => 'string', |
313
|
|
|
'context' => array( 'view' ), |
314
|
|
|
'readonly' => true, |
315
|
|
|
), |
316
|
|
|
'database_tables' => array( |
317
|
|
|
'description' => __( 'Database tables.', 'woocommerce' ), |
318
|
|
|
'type' => 'array', |
319
|
|
|
'context' => array( 'view' ), |
320
|
|
|
'readonly' => true, |
321
|
|
|
'items' => array( |
322
|
|
|
'type' => 'string', |
323
|
|
|
), |
324
|
|
|
), |
325
|
|
|
), |
326
|
|
|
), |
327
|
|
|
'active_plugins' => array( |
328
|
|
|
'description' => __( 'Active plugins.', 'woocommerce' ), |
329
|
|
|
'type' => 'array', |
330
|
|
|
'context' => array( 'view' ), |
331
|
|
|
'readonly' => true, |
332
|
|
|
'items' => array( |
333
|
|
|
'type' => 'string', |
334
|
|
|
), |
335
|
|
|
), |
336
|
|
|
'inactive_plugins' => array( |
337
|
|
|
'description' => __( 'Inactive plugins.', 'woocommerce' ), |
338
|
|
|
'type' => 'array', |
339
|
|
|
'context' => array( 'view' ), |
340
|
|
|
'readonly' => true, |
341
|
|
|
'items' => array( |
342
|
|
|
'type' => 'string', |
343
|
|
|
), |
344
|
|
|
), |
345
|
|
|
'dropins_mu_plugins' => array( |
346
|
|
|
'description' => __( 'Dropins & MU plugins.', 'woocommerce' ), |
347
|
|
|
'type' => 'array', |
348
|
|
|
'context' => array( 'view' ), |
349
|
|
|
'readonly' => true, |
350
|
|
|
'items' => array( |
351
|
|
|
'type' => 'string', |
352
|
|
|
), |
353
|
|
|
), |
354
|
|
|
'theme' => array( |
355
|
|
|
'description' => __( 'Theme.', 'woocommerce' ), |
356
|
|
|
'type' => 'object', |
357
|
|
|
'context' => array( 'view' ), |
358
|
|
|
'readonly' => true, |
359
|
|
|
'properties' => array( |
360
|
|
|
'name' => array( |
361
|
|
|
'description' => __( 'Theme name.', 'woocommerce' ), |
362
|
|
|
'type' => 'string', |
363
|
|
|
'context' => array( 'view' ), |
364
|
|
|
'readonly' => true, |
365
|
|
|
), |
366
|
|
|
'version' => array( |
367
|
|
|
'description' => __( 'Theme version.', 'woocommerce' ), |
368
|
|
|
'type' => 'string', |
369
|
|
|
'context' => array( 'view' ), |
370
|
|
|
'readonly' => true, |
371
|
|
|
), |
372
|
|
|
'version_latest' => array( |
373
|
|
|
'description' => __( 'Latest version of theme.', 'woocommerce' ), |
374
|
|
|
'type' => 'string', |
375
|
|
|
'context' => array( 'view' ), |
376
|
|
|
'readonly' => true, |
377
|
|
|
), |
378
|
|
|
'author_url' => array( |
379
|
|
|
'description' => __( 'Theme author URL.', 'woocommerce' ), |
380
|
|
|
'type' => 'string', |
381
|
|
|
'format' => 'uri', |
382
|
|
|
'context' => array( 'view' ), |
383
|
|
|
'readonly' => true, |
384
|
|
|
), |
385
|
|
|
'is_child_theme' => array( |
386
|
|
|
'description' => __( 'Is this theme a child theme?', 'woocommerce' ), |
387
|
|
|
'type' => 'boolean', |
388
|
|
|
'context' => array( 'view' ), |
389
|
|
|
'readonly' => true, |
390
|
|
|
), |
391
|
|
|
'has_woocommerce_support' => array( |
392
|
|
|
'description' => __( 'Does the theme declare WooCommerce support?', 'woocommerce' ), |
393
|
|
|
'type' => 'boolean', |
394
|
|
|
'context' => array( 'view' ), |
395
|
|
|
'readonly' => true, |
396
|
|
|
), |
397
|
|
|
'has_woocommerce_file' => array( |
398
|
|
|
'description' => __( 'Does the theme have a woocommerce.php file?', 'woocommerce' ), |
399
|
|
|
'type' => 'boolean', |
400
|
|
|
'context' => array( 'view' ), |
401
|
|
|
'readonly' => true, |
402
|
|
|
), |
403
|
|
|
'has_outdated_templates' => array( |
404
|
|
|
'description' => __( 'Does this theme have outdated templates?', 'woocommerce' ), |
405
|
|
|
'type' => 'boolean', |
406
|
|
|
'context' => array( 'view' ), |
407
|
|
|
'readonly' => true, |
408
|
|
|
), |
409
|
|
|
'overrides' => array( |
410
|
|
|
'description' => __( 'Template overrides.', 'woocommerce' ), |
411
|
|
|
'type' => 'array', |
412
|
|
|
'context' => array( 'view' ), |
413
|
|
|
'readonly' => true, |
414
|
|
|
'items' => array( |
415
|
|
|
'type' => 'string', |
416
|
|
|
), |
417
|
|
|
), |
418
|
|
|
'parent_name' => array( |
419
|
|
|
'description' => __( 'Parent theme name.', 'woocommerce' ), |
420
|
|
|
'type' => 'string', |
421
|
|
|
'context' => array( 'view' ), |
422
|
|
|
'readonly' => true, |
423
|
|
|
), |
424
|
|
|
'parent_version' => array( |
425
|
|
|
'description' => __( 'Parent theme version.', 'woocommerce' ), |
426
|
|
|
'type' => 'string', |
427
|
|
|
'context' => array( 'view' ), |
428
|
|
|
'readonly' => true, |
429
|
|
|
), |
430
|
|
|
'parent_author_url' => array( |
431
|
|
|
'description' => __( 'Parent theme author URL.', 'woocommerce' ), |
432
|
|
|
'type' => 'string', |
433
|
|
|
'format' => 'uri', |
434
|
|
|
'context' => array( 'view' ), |
435
|
|
|
'readonly' => true, |
436
|
|
|
), |
437
|
|
|
), |
438
|
|
|
), |
439
|
|
|
'settings' => array( |
440
|
|
|
'description' => __( 'Settings.', 'woocommerce' ), |
441
|
|
|
'type' => 'object', |
442
|
|
|
'context' => array( 'view' ), |
443
|
|
|
'readonly' => true, |
444
|
|
|
'properties' => array( |
445
|
|
|
'api_enabled' => array( |
446
|
|
|
'description' => __( 'REST API enabled?', 'woocommerce' ), |
447
|
|
|
'type' => 'boolean', |
448
|
|
|
'context' => array( 'view' ), |
449
|
|
|
'readonly' => true, |
450
|
|
|
), |
451
|
|
|
'force_ssl' => array( |
452
|
|
|
'description' => __( 'SSL forced?', 'woocommerce' ), |
453
|
|
|
'type' => 'boolean', |
454
|
|
|
'context' => array( 'view' ), |
455
|
|
|
'readonly' => true, |
456
|
|
|
), |
457
|
|
|
'currency' => array( |
458
|
|
|
'description' => __( 'Currency.', 'woocommerce' ), |
459
|
|
|
'type' => 'string', |
460
|
|
|
'context' => array( 'view' ), |
461
|
|
|
'readonly' => true, |
462
|
|
|
), |
463
|
|
|
'currency_symbol' => array( |
464
|
|
|
'description' => __( 'Currency symbol.', 'woocommerce' ), |
465
|
|
|
'type' => 'string', |
466
|
|
|
'context' => array( 'view' ), |
467
|
|
|
'readonly' => true, |
468
|
|
|
), |
469
|
|
|
'currency_position' => array( |
470
|
|
|
'description' => __( 'Currency position.', 'woocommerce' ), |
471
|
|
|
'type' => 'string', |
472
|
|
|
'context' => array( 'view' ), |
473
|
|
|
'readonly' => true, |
474
|
|
|
), |
475
|
|
|
'thousand_separator' => array( |
476
|
|
|
'description' => __( 'Thousand separator.', 'woocommerce' ), |
477
|
|
|
'type' => 'string', |
478
|
|
|
'context' => array( 'view' ), |
479
|
|
|
'readonly' => true, |
480
|
|
|
), |
481
|
|
|
'decimal_separator' => array( |
482
|
|
|
'description' => __( 'Decimal separator.', 'woocommerce' ), |
483
|
|
|
'type' => 'string', |
484
|
|
|
'context' => array( 'view' ), |
485
|
|
|
'readonly' => true, |
486
|
|
|
), |
487
|
|
|
'number_of_decimals' => array( |
488
|
|
|
'description' => __( 'Number of decimals.', 'woocommerce' ), |
489
|
|
|
'type' => 'integer', |
490
|
|
|
'context' => array( 'view' ), |
491
|
|
|
'readonly' => true, |
492
|
|
|
), |
493
|
|
|
'geolocation_enabled' => array( |
494
|
|
|
'description' => __( 'Geolocation enabled?', 'woocommerce' ), |
495
|
|
|
'type' => 'boolean', |
496
|
|
|
'context' => array( 'view' ), |
497
|
|
|
'readonly' => true, |
498
|
|
|
), |
499
|
|
|
'taxonomies' => array( |
500
|
|
|
'description' => __( 'Taxonomy terms for product/order statuses.', 'woocommerce' ), |
501
|
|
|
'type' => 'array', |
502
|
|
|
'context' => array( 'view' ), |
503
|
|
|
'readonly' => true, |
504
|
|
|
'items' => array( |
505
|
|
|
'type' => 'string', |
506
|
|
|
), |
507
|
|
|
), |
508
|
|
|
'product_visibility_terms' => array( |
509
|
|
|
'description' => __( 'Terms in the product visibility taxonomy.', 'woocommerce' ), |
510
|
|
|
'type' => 'array', |
511
|
|
|
'context' => array( 'view' ), |
512
|
|
|
'readonly' => true, |
513
|
|
|
'items' => array( |
514
|
|
|
'type' => 'string', |
515
|
|
|
), |
516
|
|
|
), |
517
|
|
|
), |
518
|
|
|
), |
519
|
|
|
'security' => array( |
520
|
|
|
'description' => __( 'Security.', 'woocommerce' ), |
521
|
|
|
'type' => 'object', |
522
|
|
|
'context' => array( 'view' ), |
523
|
|
|
'readonly' => true, |
524
|
|
|
'properties' => array( |
525
|
|
|
'secure_connection' => array( |
526
|
|
|
'description' => __( 'Is the connection to your store secure?', 'woocommerce' ), |
527
|
|
|
'type' => 'boolean', |
528
|
|
|
'context' => array( 'view' ), |
529
|
|
|
'readonly' => true, |
530
|
|
|
), |
531
|
|
|
'hide_errors' => array( |
532
|
|
|
'description' => __( 'Hide errors from visitors?', 'woocommerce' ), |
533
|
|
|
'type' => 'boolean', |
534
|
|
|
'context' => array( 'view' ), |
535
|
|
|
'readonly' => true, |
536
|
|
|
), |
537
|
|
|
), |
538
|
|
|
), |
539
|
|
|
'pages' => array( |
540
|
|
|
'description' => __( 'WooCommerce pages.', 'woocommerce' ), |
541
|
|
|
'type' => 'array', |
542
|
|
|
'context' => array( 'view' ), |
543
|
|
|
'readonly' => true, |
544
|
|
|
'items' => array( |
545
|
|
|
'type' => 'string', |
546
|
|
|
), |
547
|
|
|
), |
548
|
|
|
'post_type_counts' => array( |
549
|
|
|
'description' => __( 'Post type counts.', 'woocommerce' ), |
550
|
|
|
'type' => 'array', |
551
|
|
|
'context' => array( 'view' ), |
552
|
|
|
'readonly' => true, |
553
|
|
|
'items' => array( |
554
|
|
|
'type' => 'string', |
555
|
|
|
), |
556
|
|
|
), |
557
|
|
|
), |
558
|
|
|
); |
559
|
|
|
|
560
|
|
|
return $this->add_additional_fields_schema( $schema ); |
561
|
|
|
} |
562
|
|
|
|
563
|
|
|
/** |
564
|
|
|
* Return an array of sections and the data associated with each. |
565
|
|
|
* |
566
|
|
|
* @return array |
567
|
|
|
*/ |
568
|
|
|
public function get_item_mappings() { |
569
|
|
|
return array( |
570
|
|
|
'environment' => $this->get_environment_info(), |
571
|
|
|
'database' => $this->get_database_info(), |
572
|
|
|
'active_plugins' => $this->get_active_plugins(), |
573
|
|
|
'inactive_plugins' => $this->get_inactive_plugins(), |
574
|
|
|
'dropins_mu_plugins' => $this->get_dropins_mu_plugins(), |
575
|
|
|
'theme' => $this->get_theme_info(), |
576
|
|
|
'settings' => $this->get_settings(), |
577
|
|
|
'security' => $this->get_security_info(), |
578
|
|
|
'pages' => $this->get_pages(), |
579
|
|
|
'post_type_counts' => $this->get_post_type_counts(), |
580
|
|
|
); |
581
|
|
|
} |
582
|
|
|
|
583
|
|
|
/** |
584
|
|
|
* Get array of environment information. Includes thing like software |
585
|
|
|
* versions, and various server settings. |
586
|
|
|
* |
587
|
|
|
* @return array |
588
|
|
|
*/ |
589
|
|
|
public function get_environment_info() { |
590
|
|
|
global $wpdb; |
591
|
|
|
|
592
|
|
|
// Figure out cURL version, if installed. |
593
|
|
|
$curl_version = ''; |
594
|
|
|
if ( function_exists( 'curl_version' ) ) { |
595
|
|
|
$curl_version = curl_version(); |
596
|
|
|
$curl_version = $curl_version['version'] . ', ' . $curl_version['ssl_version']; |
597
|
|
|
} elseif ( extension_loaded( 'curl' ) ) { |
598
|
|
|
$curl_version = __( 'cURL installed but unable to retrieve version.', 'woocommerce' ); |
599
|
|
|
} |
600
|
|
|
|
601
|
|
|
// WP memory limit. |
602
|
|
|
$wp_memory_limit = wc_let_to_num( WP_MEMORY_LIMIT ); |
|
|
|
|
603
|
|
|
if ( function_exists( 'memory_get_usage' ) ) { |
604
|
|
|
$wp_memory_limit = max( $wp_memory_limit, wc_let_to_num( @ini_get( 'memory_limit' ) ) ); |
605
|
|
|
} |
606
|
|
|
|
607
|
|
|
// Test POST requests. |
608
|
|
|
$post_response_code = get_transient( 'woocommerce_test_remote_post' ); |
609
|
|
|
|
610
|
|
|
if ( false === $post_response_code || is_wp_error( $post_response_code ) ) { |
611
|
|
|
$response = wp_safe_remote_post( |
612
|
|
|
'https://www.paypal.com/cgi-bin/webscr', |
613
|
|
|
array( |
614
|
|
|
'timeout' => 10, |
615
|
|
|
'user-agent' => 'WooCommerce/' . WC()->version, |
616
|
|
|
'httpversion' => '1.1', |
617
|
|
|
'body' => array( |
618
|
|
|
'cmd' => '_notify-validate', |
619
|
|
|
), |
620
|
|
|
) |
621
|
|
|
); |
622
|
|
|
if ( ! is_wp_error( $response ) ) { |
623
|
|
|
$post_response_code = $response['response']['code']; |
624
|
|
|
} |
625
|
|
|
set_transient( 'woocommerce_test_remote_post', $post_response_code, HOUR_IN_SECONDS ); |
|
|
|
|
626
|
|
|
} |
627
|
|
|
|
628
|
|
|
$post_response_successful = ! is_wp_error( $post_response_code ) && $post_response_code >= 200 && $post_response_code < 300; |
629
|
|
|
|
630
|
|
|
// Test GET requests. |
631
|
|
|
$get_response_code = get_transient( 'woocommerce_test_remote_get' ); |
632
|
|
|
|
633
|
|
|
if ( false === $get_response_code || is_wp_error( $get_response_code ) ) { |
634
|
|
|
$response = wp_safe_remote_get( 'https://woocommerce.com/wc-api/product-key-api?request=ping&network=' . ( is_multisite() ? '1' : '0' ) ); |
635
|
|
|
if ( ! is_wp_error( $response ) ) { |
636
|
|
|
$get_response_code = $response['response']['code']; |
637
|
|
|
} |
638
|
|
|
set_transient( 'woocommerce_test_remote_get', $get_response_code, HOUR_IN_SECONDS ); |
639
|
|
|
} |
640
|
|
|
|
641
|
|
|
$get_response_successful = ! is_wp_error( $get_response_code ) && $get_response_code >= 200 && $get_response_code < 300; |
642
|
|
|
|
643
|
|
|
$database_version = wc_get_server_database_version(); |
644
|
|
|
|
645
|
|
|
// Return all environment info. Described by JSON Schema. |
646
|
|
|
return array( |
647
|
|
|
'home_url' => get_option( 'home' ), |
648
|
|
|
'site_url' => get_option( 'siteurl' ), |
649
|
|
|
'version' => WC()->version, |
650
|
|
|
'log_directory' => WC_LOG_DIR, |
|
|
|
|
651
|
|
|
'log_directory_writable' => (bool) @fopen( WC_LOG_DIR . 'test-log.log', 'a' ), |
652
|
|
|
'wp_version' => get_bloginfo( 'version' ), |
653
|
|
|
'wp_multisite' => is_multisite(), |
654
|
|
|
'wp_memory_limit' => $wp_memory_limit, |
655
|
|
|
'wp_debug_mode' => ( defined( 'WP_DEBUG' ) && WP_DEBUG ), |
|
|
|
|
656
|
|
|
'wp_cron' => ! ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ), |
|
|
|
|
657
|
|
|
'language' => get_locale(), |
658
|
|
|
'external_object_cache' => wp_using_ext_object_cache(), |
659
|
|
|
'server_info' => isset( $_SERVER['SERVER_SOFTWARE'] ) ? wc_clean( wp_unslash( $_SERVER['SERVER_SOFTWARE'] ) ) : '', |
660
|
|
|
'php_version' => phpversion(), |
661
|
|
|
'php_post_max_size' => wc_let_to_num( ini_get( 'post_max_size' ) ), |
662
|
|
|
'php_max_execution_time' => ini_get( 'max_execution_time' ), |
663
|
|
|
'php_max_input_vars' => ini_get( 'max_input_vars' ), |
664
|
|
|
'curl_version' => $curl_version, |
665
|
|
|
'suhosin_installed' => extension_loaded( 'suhosin' ), |
666
|
|
|
'max_upload_size' => wp_max_upload_size(), |
667
|
|
|
'mysql_version' => $database_version['number'], |
668
|
|
|
'mysql_version_string' => $database_version['string'], |
669
|
|
|
'default_timezone' => date_default_timezone_get(), |
670
|
|
|
'fsockopen_or_curl_enabled' => ( function_exists( 'fsockopen' ) || function_exists( 'curl_init' ) ), |
671
|
|
|
'soapclient_enabled' => class_exists( 'SoapClient' ), |
672
|
|
|
'domdocument_enabled' => class_exists( 'DOMDocument' ), |
673
|
|
|
'gzip_enabled' => is_callable( 'gzopen' ), |
674
|
|
|
'mbstring_enabled' => extension_loaded( 'mbstring' ), |
675
|
|
|
'remote_post_successful' => $post_response_successful, |
676
|
|
|
'remote_post_response' => is_wp_error( $post_response_code ) ? $post_response_code->get_error_message() : $post_response_code, |
677
|
|
|
'remote_get_successful' => $get_response_successful, |
678
|
|
|
'remote_get_response' => is_wp_error( $get_response_code ) ? $get_response_code->get_error_message() : $get_response_code, |
679
|
|
|
); |
680
|
|
|
} |
681
|
|
|
|
682
|
|
|
/** |
683
|
|
|
* Add prefix to table. |
684
|
|
|
* |
685
|
|
|
* @param string $table Table name. |
686
|
|
|
* @return stromg |
|
|
|
|
687
|
|
|
*/ |
688
|
|
|
protected function add_db_table_prefix( $table ) { |
689
|
|
|
global $wpdb; |
690
|
|
|
return $wpdb->prefix . $table; |
691
|
|
|
} |
692
|
|
|
|
693
|
|
|
/** |
694
|
|
|
* Get array of database information. Version, prefix, and table existence. |
695
|
|
|
* |
696
|
|
|
* @return array |
697
|
|
|
*/ |
698
|
|
|
public function get_database_info() { |
699
|
|
|
global $wpdb; |
700
|
|
|
|
701
|
|
|
$database_table_information = $wpdb->get_results( |
702
|
|
|
$wpdb->prepare( |
703
|
|
|
"SELECT |
704
|
|
|
table_name AS 'name', |
705
|
|
|
engine, |
706
|
|
|
round( ( data_length / 1024 / 1024 ), 2 ) 'data', |
707
|
|
|
round( ( index_length / 1024 / 1024 ), 2 ) 'index' |
708
|
|
|
FROM information_schema.TABLES |
709
|
|
|
WHERE table_schema = %s |
710
|
|
|
ORDER BY name ASC;", |
711
|
|
|
DB_NAME |
|
|
|
|
712
|
|
|
) |
713
|
|
|
); |
714
|
|
|
|
715
|
|
|
// WC Core tables to check existence of. |
716
|
|
|
$core_tables = apply_filters( |
717
|
|
|
'woocommerce_database_tables', |
718
|
|
|
array( |
719
|
|
|
'woocommerce_sessions', |
720
|
|
|
'woocommerce_api_keys', |
721
|
|
|
'woocommerce_attribute_taxonomies', |
722
|
|
|
'woocommerce_downloadable_product_permissions', |
723
|
|
|
'woocommerce_order_items', |
724
|
|
|
'woocommerce_order_itemmeta', |
725
|
|
|
'woocommerce_tax_rates', |
726
|
|
|
'woocommerce_tax_rate_locations', |
727
|
|
|
'woocommerce_shipping_zones', |
728
|
|
|
'woocommerce_shipping_zone_locations', |
729
|
|
|
'woocommerce_shipping_zone_methods', |
730
|
|
|
'woocommerce_payment_tokens', |
731
|
|
|
'woocommerce_payment_tokenmeta', |
732
|
|
|
'woocommerce_log', |
733
|
|
|
) |
734
|
|
|
); |
735
|
|
|
|
736
|
|
|
/** |
737
|
|
|
* Adding the prefix to the tables array, for backwards compatibility. |
738
|
|
|
* |
739
|
|
|
* If we changed the tables above to include the prefix, then any filters against that table could break. |
740
|
|
|
*/ |
741
|
|
|
$core_tables = array_map( array( $this, 'add_db_table_prefix' ), $core_tables ); |
742
|
|
|
|
743
|
|
|
/** |
744
|
|
|
* Organize WooCommerce and non-WooCommerce tables separately for display purposes later. |
745
|
|
|
* |
746
|
|
|
* To ensure we include all WC tables, even if they do not exist, pre-populate the WC array with all the tables. |
747
|
|
|
*/ |
748
|
|
|
$tables = array( |
749
|
|
|
'woocommerce' => array_fill_keys( $core_tables, false ), |
750
|
|
|
'other' => array(), |
751
|
|
|
); |
752
|
|
|
|
753
|
|
|
$database_size = array( |
754
|
|
|
'data' => 0, |
755
|
|
|
'index' => 0, |
756
|
|
|
); |
757
|
|
|
|
758
|
|
|
$site_tables_prefix = $wpdb->get_blog_prefix( get_current_blog_id() ); |
759
|
|
|
$global_tables = $wpdb->tables( 'global', true ); |
760
|
|
|
foreach ( $database_table_information as $table ) { |
761
|
|
|
// 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. |
762
|
|
|
if ( is_multisite() && 0 !== strpos( $table->name, $site_tables_prefix ) && ! in_array( $table->name, $global_tables, true ) ) { |
763
|
|
|
continue; |
764
|
|
|
} |
765
|
|
|
$table_type = in_array( $table->name, $core_tables, true ) ? 'woocommerce' : 'other'; |
766
|
|
|
|
767
|
|
|
$tables[ $table_type ][ $table->name ] = array( |
768
|
|
|
'data' => $table->data, |
769
|
|
|
'index' => $table->index, |
770
|
|
|
'engine' => $table->engine, |
771
|
|
|
); |
772
|
|
|
|
773
|
|
|
$database_size['data'] += $table->data; |
774
|
|
|
$database_size['index'] += $table->index; |
775
|
|
|
} |
776
|
|
|
|
777
|
|
|
// Return all database info. Described by JSON Schema. |
778
|
|
|
return array( |
779
|
|
|
'wc_database_version' => get_option( 'woocommerce_db_version' ), |
780
|
|
|
'database_prefix' => $wpdb->prefix, |
781
|
|
|
'maxmind_geoip_database' => \WC_Geolocation::get_local_database_path(), |
|
|
|
|
782
|
|
|
'database_tables' => $tables, |
783
|
|
|
'database_size' => $database_size, |
784
|
|
|
); |
785
|
|
|
} |
786
|
|
|
|
787
|
|
|
/** |
788
|
|
|
* Get array of counts of objects. Orders, products, etc. |
789
|
|
|
* |
790
|
|
|
* @return array |
791
|
|
|
*/ |
792
|
|
|
public function get_post_type_counts() { |
793
|
|
|
global $wpdb; |
794
|
|
|
|
795
|
|
|
$post_type_counts = $wpdb->get_results( "SELECT post_type AS 'type', count(1) AS 'count' FROM {$wpdb->posts} GROUP BY post_type;" ); |
796
|
|
|
|
797
|
|
|
return is_array( $post_type_counts ) ? $post_type_counts : array(); |
798
|
|
|
} |
799
|
|
|
|
800
|
|
|
/** |
801
|
|
|
* Get a list of plugins active on the site. |
802
|
|
|
* |
803
|
|
|
* @return array |
804
|
|
|
*/ |
805
|
|
|
public function get_active_plugins() { |
806
|
|
|
require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
|
|
|
807
|
|
|
|
808
|
|
|
if ( ! function_exists( 'get_plugin_data' ) ) { |
809
|
|
|
return array(); |
810
|
|
|
} |
811
|
|
|
|
812
|
|
|
$active_plugins = (array) get_option( 'active_plugins', array() ); |
813
|
|
|
if ( is_multisite() ) { |
814
|
|
|
$network_activated_plugins = array_keys( get_site_option( 'active_sitewide_plugins', array() ) ); |
815
|
|
|
$active_plugins = array_merge( $active_plugins, $network_activated_plugins ); |
816
|
|
|
} |
817
|
|
|
|
818
|
|
|
$active_plugins_data = array(); |
819
|
|
|
|
820
|
|
|
foreach ( $active_plugins as $plugin ) { |
821
|
|
|
$data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin ); |
|
|
|
|
822
|
|
|
$active_plugins_data[] = $this->format_plugin_data( $plugin, $data ); |
823
|
|
|
} |
824
|
|
|
|
825
|
|
|
return $active_plugins_data; |
826
|
|
|
} |
827
|
|
|
|
828
|
|
|
/** |
829
|
|
|
* Get a list of inplugins active on the site. |
830
|
|
|
* |
831
|
|
|
* @return array |
832
|
|
|
*/ |
833
|
|
|
public function get_inactive_plugins() { |
834
|
|
|
require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
|
|
|
835
|
|
|
|
836
|
|
|
if ( ! function_exists( 'get_plugins' ) ) { |
837
|
|
|
return array(); |
838
|
|
|
} |
839
|
|
|
|
840
|
|
|
$plugins = get_plugins(); |
841
|
|
|
$active_plugins = (array) get_option( 'active_plugins', array() ); |
842
|
|
|
|
843
|
|
|
if ( is_multisite() ) { |
844
|
|
|
$network_activated_plugins = array_keys( get_site_option( 'active_sitewide_plugins', array() ) ); |
845
|
|
|
$active_plugins = array_merge( $active_plugins, $network_activated_plugins ); |
846
|
|
|
} |
847
|
|
|
|
848
|
|
|
$plugins_data = array(); |
849
|
|
|
|
850
|
|
|
foreach ( $plugins as $plugin => $data ) { |
851
|
|
|
if ( in_array( $plugin, $active_plugins, true ) ) { |
852
|
|
|
continue; |
853
|
|
|
} |
854
|
|
|
$plugins_data[] = $this->format_plugin_data( $plugin, $data ); |
855
|
|
|
} |
856
|
|
|
|
857
|
|
|
return $plugins_data; |
858
|
|
|
} |
859
|
|
|
|
860
|
|
|
/** |
861
|
|
|
* Format plugin data, including data on updates, into a standard format. |
862
|
|
|
* |
863
|
|
|
* @since 3.6.0 |
864
|
|
|
* @param string $plugin Plugin directory/file. |
865
|
|
|
* @param array $data Plugin data from WP. |
866
|
|
|
* @return array Formatted data. |
867
|
|
|
*/ |
868
|
|
|
protected function format_plugin_data( $plugin, $data ) { |
869
|
|
|
require_once ABSPATH . 'wp-admin/includes/update.php'; |
|
|
|
|
870
|
|
|
|
871
|
|
|
if ( ! function_exists( 'get_plugin_updates' ) ) { |
872
|
|
|
return array(); |
873
|
|
|
} |
874
|
|
|
|
875
|
|
|
// Use WP API to lookup latest updates for plugins. WC_Helper injects updates for premium plugins. |
876
|
|
|
if ( empty( $this->available_updates ) ) { |
877
|
|
|
$this->available_updates = get_plugin_updates(); |
|
|
|
|
878
|
|
|
} |
879
|
|
|
|
880
|
|
|
$version_latest = $data['Version']; |
881
|
|
|
|
882
|
|
|
// Find latest version. |
883
|
|
|
if ( isset( $this->available_updates[ $plugin ]->update->new_version ) ) { |
884
|
|
|
$version_latest = $this->available_updates[ $plugin ]->update->new_version; |
885
|
|
|
} |
886
|
|
|
|
887
|
|
|
return array( |
888
|
|
|
'plugin' => $plugin, |
889
|
|
|
'name' => $data['Name'], |
890
|
|
|
'version' => $data['Version'], |
891
|
|
|
'version_latest' => $version_latest, |
892
|
|
|
'url' => $data['PluginURI'], |
893
|
|
|
'author_name' => $data['AuthorName'], |
894
|
|
|
'author_url' => esc_url_raw( $data['AuthorURI'] ), |
895
|
|
|
'network_activated' => $data['Network'], |
896
|
|
|
); |
897
|
|
|
} |
898
|
|
|
|
899
|
|
|
/** |
900
|
|
|
* Get a list of Dropins and MU plugins. |
901
|
|
|
* |
902
|
|
|
* @since 3.6.0 |
903
|
|
|
* @return array |
904
|
|
|
*/ |
905
|
|
|
public function get_dropins_mu_plugins() { |
906
|
|
|
$dropins = get_dropins(); |
907
|
|
|
$plugins = array( |
908
|
|
|
'dropins' => array(), |
909
|
|
|
'mu_plugins' => array(), |
910
|
|
|
); |
911
|
|
|
foreach ( $dropins as $key => $dropin ) { |
912
|
|
|
$plugins['dropins'][] = array( |
913
|
|
|
'plugin' => $key, |
914
|
|
|
'name' => $dropin['Name'], |
915
|
|
|
); |
916
|
|
|
} |
917
|
|
|
|
918
|
|
|
$mu_plugins = get_mu_plugins(); |
919
|
|
|
foreach ( $mu_plugins as $plugin => $mu_plugin ) { |
920
|
|
|
$plugins['mu_plugins'][] = array( |
921
|
|
|
'plugin' => $plugin, |
922
|
|
|
'name' => $mu_plugin['Name'], |
923
|
|
|
'version' => $mu_plugin['Version'], |
924
|
|
|
'url' => $mu_plugin['PluginURI'], |
925
|
|
|
'author_name' => $mu_plugin['AuthorName'], |
926
|
|
|
'author_url' => esc_url_raw( $mu_plugin['AuthorURI'] ), |
927
|
|
|
); |
928
|
|
|
} |
929
|
|
|
return $plugins; |
930
|
|
|
} |
931
|
|
|
|
932
|
|
|
/** |
933
|
|
|
* Get info on the current active theme, info on parent theme (if presnet) |
934
|
|
|
* and a list of template overrides. |
935
|
|
|
* |
936
|
|
|
* @return array |
937
|
|
|
*/ |
938
|
|
|
public function get_theme_info() { |
939
|
|
|
$active_theme = wp_get_theme(); |
940
|
|
|
|
941
|
|
|
// Get parent theme info if this theme is a child theme, otherwise |
942
|
|
|
// pass empty info in the response. |
943
|
|
|
if ( is_child_theme() ) { |
944
|
|
|
$parent_theme = wp_get_theme( $active_theme->template ); |
945
|
|
|
$parent_theme_info = array( |
946
|
|
|
'parent_name' => $parent_theme->name, |
947
|
|
|
'parent_version' => $parent_theme->version, |
948
|
|
|
'parent_version_latest' => \WC_Admin_Status::get_latest_theme_version( $parent_theme ), |
|
|
|
|
949
|
|
|
'parent_author_url' => $parent_theme->{'Author URI'}, |
950
|
|
|
); |
951
|
|
|
} else { |
952
|
|
|
$parent_theme_info = array( |
953
|
|
|
'parent_name' => '', |
954
|
|
|
'parent_version' => '', |
955
|
|
|
'parent_version_latest' => '', |
956
|
|
|
'parent_author_url' => '', |
957
|
|
|
); |
958
|
|
|
} |
959
|
|
|
|
960
|
|
|
/** |
961
|
|
|
* Scan the theme directory for all WC templates to see if our theme |
962
|
|
|
* overrides any of them. |
963
|
|
|
*/ |
964
|
|
|
$override_files = array(); |
965
|
|
|
$outdated_templates = false; |
966
|
|
|
$scan_files = \WC_Admin_Status::scan_template_files( WC()->plugin_path() . '/templates/' ); |
967
|
|
|
foreach ( $scan_files as $file ) { |
968
|
|
|
$located = apply_filters( 'wc_get_template', $file, $file, array(), WC()->template_path(), WC()->plugin_path() . '/templates/' ); |
969
|
|
|
|
970
|
|
|
if ( file_exists( $located ) ) { |
971
|
|
|
$theme_file = $located; |
972
|
|
|
} elseif ( file_exists( get_stylesheet_directory() . '/' . $file ) ) { |
973
|
|
|
$theme_file = get_stylesheet_directory() . '/' . $file; |
974
|
|
|
} elseif ( file_exists( get_stylesheet_directory() . '/' . WC()->template_path() . $file ) ) { |
975
|
|
|
$theme_file = get_stylesheet_directory() . '/' . WC()->template_path() . $file; |
976
|
|
|
} elseif ( file_exists( get_template_directory() . '/' . $file ) ) { |
977
|
|
|
$theme_file = get_template_directory() . '/' . $file; |
978
|
|
|
} elseif ( file_exists( get_template_directory() . '/' . WC()->template_path() . $file ) ) { |
979
|
|
|
$theme_file = get_template_directory() . '/' . WC()->template_path() . $file; |
980
|
|
|
} else { |
981
|
|
|
$theme_file = false; |
982
|
|
|
} |
983
|
|
|
|
984
|
|
|
if ( ! empty( $theme_file ) ) { |
985
|
|
|
$core_version = \WC_Admin_Status::get_file_version( WC()->plugin_path() . '/templates/' . $file ); |
986
|
|
|
$theme_version = \WC_Admin_Status::get_file_version( $theme_file ); |
987
|
|
|
if ( $core_version && ( empty( $theme_version ) || version_compare( $theme_version, $core_version, '<' ) ) ) { |
988
|
|
|
if ( ! $outdated_templates ) { |
989
|
|
|
$outdated_templates = true; |
990
|
|
|
} |
991
|
|
|
} |
992
|
|
|
$override_files[] = array( |
993
|
|
|
'file' => str_replace( WP_CONTENT_DIR . '/themes/', '', $theme_file ), |
|
|
|
|
994
|
|
|
'version' => $theme_version, |
995
|
|
|
'core_version' => $core_version, |
996
|
|
|
); |
997
|
|
|
} |
998
|
|
|
} |
999
|
|
|
|
1000
|
|
|
$active_theme_info = array( |
1001
|
|
|
'name' => $active_theme->name, |
1002
|
|
|
'version' => $active_theme->version, |
1003
|
|
|
'version_latest' => \WC_Admin_Status::get_latest_theme_version( $active_theme ), |
1004
|
|
|
'author_url' => esc_url_raw( $active_theme->{'Author URI'} ), |
1005
|
|
|
'is_child_theme' => is_child_theme(), |
1006
|
|
|
'has_woocommerce_support' => current_theme_supports( 'woocommerce' ), |
1007
|
|
|
'has_woocommerce_file' => ( file_exists( get_stylesheet_directory() . '/woocommerce.php' ) || file_exists( get_template_directory() . '/woocommerce.php' ) ), |
1008
|
|
|
'has_outdated_templates' => $outdated_templates, |
1009
|
|
|
'overrides' => $override_files, |
1010
|
|
|
); |
1011
|
|
|
|
1012
|
|
|
return array_merge( $active_theme_info, $parent_theme_info ); |
1013
|
|
|
} |
1014
|
|
|
|
1015
|
|
|
/** |
1016
|
|
|
* Get some setting values for the site that are useful for debugging |
1017
|
|
|
* purposes. For full settings access, use the settings api. |
1018
|
|
|
* |
1019
|
|
|
* @return array |
1020
|
|
|
*/ |
1021
|
|
|
public function get_settings() { |
1022
|
|
|
// Get a list of terms used for product/order taxonomies. |
1023
|
|
|
$term_response = array(); |
1024
|
|
|
$terms = get_terms( 'product_type', array( 'hide_empty' => 0 ) ); |
1025
|
|
|
foreach ( $terms as $term ) { |
1026
|
|
|
$term_response[ $term->slug ] = strtolower( $term->name ); |
1027
|
|
|
} |
1028
|
|
|
|
1029
|
|
|
// Get a list of terms used for product visibility. |
1030
|
|
|
$product_visibility_terms = array(); |
1031
|
|
|
$terms = get_terms( 'product_visibility', array( 'hide_empty' => 0 ) ); |
1032
|
|
|
foreach ( $terms as $term ) { |
1033
|
|
|
$product_visibility_terms[ $term->slug ] = strtolower( $term->name ); |
1034
|
|
|
} |
1035
|
|
|
|
1036
|
|
|
// Check if WooCommerce.com account is connected. |
1037
|
|
|
$woo_com_connected = 'no'; |
1038
|
|
|
$helper_options = get_option( 'woocommerce_helper_data', array() ); |
1039
|
|
|
if ( array_key_exists( 'auth', $helper_options ) && ! empty( $helper_options['auth'] ) ) { |
1040
|
|
|
$woo_com_connected = 'yes'; |
1041
|
|
|
} |
1042
|
|
|
|
1043
|
|
|
// Return array of useful settings for debugging. |
1044
|
|
|
return array( |
1045
|
|
|
'api_enabled' => 'yes' === get_option( 'woocommerce_api_enabled' ), |
1046
|
|
|
'force_ssl' => 'yes' === get_option( 'woocommerce_force_ssl_checkout' ), |
1047
|
|
|
'currency' => get_woocommerce_currency(), |
1048
|
|
|
'currency_symbol' => get_woocommerce_currency_symbol(), |
1049
|
|
|
'currency_position' => get_option( 'woocommerce_currency_pos' ), |
1050
|
|
|
'thousand_separator' => wc_get_price_thousand_separator(), |
1051
|
|
|
'decimal_separator' => wc_get_price_decimal_separator(), |
1052
|
|
|
'number_of_decimals' => wc_get_price_decimals(), |
1053
|
|
|
'geolocation_enabled' => in_array( get_option( 'woocommerce_default_customer_address' ), array( 'geolocation_ajax', 'geolocation' ) ), |
1054
|
|
|
'taxonomies' => $term_response, |
1055
|
|
|
'product_visibility_terms' => $product_visibility_terms, |
1056
|
|
|
'woocommerce_com_connected' => $woo_com_connected, |
1057
|
|
|
); |
1058
|
|
|
} |
1059
|
|
|
|
1060
|
|
|
/** |
1061
|
|
|
* Returns security tips. |
1062
|
|
|
* |
1063
|
|
|
* @return array |
1064
|
|
|
*/ |
1065
|
|
|
public function get_security_info() { |
1066
|
|
|
$check_page = wc_get_page_permalink( 'shop' ); |
1067
|
|
|
return array( |
1068
|
|
|
'secure_connection' => 'https' === substr( $check_page, 0, 5 ), |
1069
|
|
|
'hide_errors' => ! ( defined( 'WP_DEBUG' ) && defined( 'WP_DEBUG_DISPLAY' ) && WP_DEBUG && WP_DEBUG_DISPLAY ) || 0 === intval( ini_get( 'display_errors' ) ), |
|
|
|
|
1070
|
|
|
); |
1071
|
|
|
} |
1072
|
|
|
|
1073
|
|
|
/** |
1074
|
|
|
* Returns a mini-report on WC pages and if they are configured correctly: |
1075
|
|
|
* Present, visible, and including the correct shortcode. |
1076
|
|
|
* |
1077
|
|
|
* @return array |
1078
|
|
|
*/ |
1079
|
|
|
public function get_pages() { |
1080
|
|
|
// WC pages to check against. |
1081
|
|
|
$check_pages = array( |
1082
|
|
|
_x( 'Shop base', 'Page setting', 'woocommerce' ) => array( |
1083
|
|
|
'option' => 'woocommerce_shop_page_id', |
1084
|
|
|
'shortcode' => '', |
1085
|
|
|
), |
1086
|
|
|
_x( 'Cart', 'Page setting', 'woocommerce' ) => array( |
1087
|
|
|
'option' => 'woocommerce_cart_page_id', |
1088
|
|
|
'shortcode' => '[' . apply_filters( 'woocommerce_cart_shortcode_tag', 'woocommerce_cart' ) . ']', |
1089
|
|
|
), |
1090
|
|
|
_x( 'Checkout', 'Page setting', 'woocommerce' ) => array( |
1091
|
|
|
'option' => 'woocommerce_checkout_page_id', |
1092
|
|
|
'shortcode' => '[' . apply_filters( 'woocommerce_checkout_shortcode_tag', 'woocommerce_checkout' ) . ']', |
1093
|
|
|
), |
1094
|
|
|
_x( 'My account', 'Page setting', 'woocommerce' ) => array( |
1095
|
|
|
'option' => 'woocommerce_myaccount_page_id', |
1096
|
|
|
'shortcode' => '[' . apply_filters( 'woocommerce_my_account_shortcode_tag', 'woocommerce_my_account' ) . ']', |
1097
|
|
|
), |
1098
|
|
|
_x( 'Terms and conditions', 'Page setting', 'woocommerce' ) => array( |
1099
|
|
|
'option' => 'woocommerce_terms_page_id', |
1100
|
|
|
'shortcode' => '', |
1101
|
|
|
), |
1102
|
|
|
); |
1103
|
|
|
|
1104
|
|
|
$pages_output = array(); |
1105
|
|
|
foreach ( $check_pages as $page_name => $values ) { |
1106
|
|
|
$page_id = get_option( $values['option'] ); |
1107
|
|
|
$page_set = false; |
1108
|
|
|
$page_exists = false; |
1109
|
|
|
$page_visible = false; |
1110
|
|
|
$shortcode_present = false; |
1111
|
|
|
$shortcode_required = false; |
1112
|
|
|
|
1113
|
|
|
// Page checks. |
1114
|
|
|
if ( $page_id ) { |
1115
|
|
|
$page_set = true; |
1116
|
|
|
} |
1117
|
|
|
if ( get_post( $page_id ) ) { |
1118
|
|
|
$page_exists = true; |
1119
|
|
|
} |
1120
|
|
|
if ( 'publish' === get_post_status( $page_id ) ) { |
1121
|
|
|
$page_visible = true; |
1122
|
|
|
} |
1123
|
|
|
|
1124
|
|
|
// Shortcode checks. |
1125
|
|
|
if ( $values['shortcode'] && get_post( $page_id ) ) { |
1126
|
|
|
$shortcode_required = true; |
1127
|
|
|
$page = get_post( $page_id ); |
1128
|
|
|
if ( strstr( $page->post_content, $values['shortcode'] ) ) { |
1129
|
|
|
$shortcode_present = true; |
1130
|
|
|
} |
1131
|
|
|
} |
1132
|
|
|
|
1133
|
|
|
// Wrap up our findings into an output array. |
1134
|
|
|
$pages_output[] = array( |
1135
|
|
|
'page_name' => $page_name, |
1136
|
|
|
'page_id' => $page_id, |
1137
|
|
|
'page_set' => $page_set, |
1138
|
|
|
'page_exists' => $page_exists, |
1139
|
|
|
'page_visible' => $page_visible, |
1140
|
|
|
'shortcode' => $values['shortcode'], |
1141
|
|
|
'shortcode_required' => $shortcode_required, |
1142
|
|
|
'shortcode_present' => $shortcode_present, |
1143
|
|
|
); |
1144
|
|
|
} |
1145
|
|
|
|
1146
|
|
|
return $pages_output; |
1147
|
|
|
} |
1148
|
|
|
|
1149
|
|
|
/** |
1150
|
|
|
* Get any query params needed. |
1151
|
|
|
* |
1152
|
|
|
* @return array |
1153
|
|
|
*/ |
1154
|
|
|
public function get_collection_params() { |
1155
|
|
|
return array( |
1156
|
|
|
'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
1157
|
|
|
); |
1158
|
|
|
} |
1159
|
|
|
|
1160
|
|
|
/** |
1161
|
|
|
* Prepare the system status response |
1162
|
|
|
* |
1163
|
|
|
* @param array $system_status System status data. |
1164
|
|
|
* @param \WP_REST_Request $request Request object. |
1165
|
|
|
* @return \WP_REST_Response |
|
|
|
|
1166
|
|
|
*/ |
1167
|
|
|
public function prepare_item_for_response( $system_status, $request ) { |
1168
|
|
|
$data = $this->add_additional_fields_to_object( $system_status, $request ); |
1169
|
|
|
$data = $this->filter_response_by_context( $data, 'view' ); |
1170
|
|
|
|
1171
|
|
|
$response = rest_ensure_response( $data ); |
1172
|
|
|
|
1173
|
|
|
/** |
1174
|
|
|
* Filter the system status returned from the REST API. |
1175
|
|
|
* |
1176
|
|
|
* @param \WP_REST_Response $response The response object. |
1177
|
|
|
* @param mixed $system_status System status |
1178
|
|
|
* @param \WP_REST_Request $request Request object. |
1179
|
|
|
*/ |
1180
|
|
|
return apply_filters( 'woocommerce_rest_prepare_system_status', $response, $system_status, $request ); |
1181
|
|
|
} |
1182
|
|
|
} |
1183
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths