Health Check - Version 1.4.2

Version Description

Download this release

Release Info

Developer Clorith
Plugin Icon 128x128 Health Check
Version 1.4.2
Comparing to
See all releases

Code changes from version 1.4.1 to 1.4.2

health-check.php CHANGED
@@ -9,7 +9,7 @@
9
  * Plugin URI: https://wordpress.org/plugins/health-check/
10
  * Description: Checks the health of your WordPress install.
11
  * Author: The WordPress.org community
12
- * Version: 1.4.1
13
  * Author URI: https://wordpress.org/plugins/health-check/
14
  * Text Domain: health-check
15
  */
@@ -35,7 +35,7 @@ define( 'HEALTH_CHECK_MYSQL_MIN_VERSION', '5.0' );
35
  define( 'HEALTH_CHECK_MYSQL_REC_VERSION', '5.6' );
36
 
37
  // Set the plugin version.
38
- define( 'HEALTH_CHECK_PLUGIN_VERSION', '1.4.1' );
39
 
40
  // Set the plugin file.
41
  define( 'HEALTH_CHECK_PLUGIN_FILE', __FILE__ );
9
  * Plugin URI: https://wordpress.org/plugins/health-check/
10
  * Description: Checks the health of your WordPress install.
11
  * Author: The WordPress.org community
12
+ * Version: 1.4.2
13
  * Author URI: https://wordpress.org/plugins/health-check/
14
  * Text Domain: health-check
15
  */
35
  define( 'HEALTH_CHECK_MYSQL_REC_VERSION', '5.6' );
36
 
37
  // Set the plugin version.
38
+ define( 'HEALTH_CHECK_PLUGIN_VERSION', '1.4.2' );
39
 
40
  // Set the plugin file.
41
  define( 'HEALTH_CHECK_PLUGIN_FILE', __FILE__ );
includes/class-health-check-debug-data.php CHANGED
@@ -1,1463 +1,1473 @@
1
- <?php
2
- /**
3
- * Class for providing debug data based on a users WordPress environment.
4
- *
5
- * @package Health Check
6
- */
7
-
8
- // Make sure the file is not directly accessible.
9
- if ( ! defined( 'ABSPATH' ) ) {
10
- die( 'We\'re sorry, but you can not directly access this file.' );
11
- }
12
-
13
- /**
14
- * Class Health_Check_Debug_Data
15
- */
16
- class Health_Check_Debug_Data {
17
-
18
- /**
19
- * Calls all core functions to check for updates
20
- *
21
- * @uses wp_version_check()
22
- * @uses wp_update_plugins()
23
- * @uses wp_update_themes()
24
- *
25
- * @return void
26
- */
27
- static function check_for_updates() {
28
-
29
- wp_version_check();
30
- wp_update_plugins();
31
- wp_update_themes();
32
-
33
- }
34
-
35
- /**
36
- * Static function for generating site debug data when required.
37
- *
38
- * @since 5.2.0
39
- *
40
- * @throws ImagickException
41
- * @global wpdb $wpdb WordPress database abstraction object.
42
- *
43
- * @return array The debug data for the site.
44
- */
45
- static function debug_data() {
46
- global $wpdb, $is_apache;
47
-
48
- // Save few function calls.
49
- $upload_dir = wp_get_upload_dir();
50
- $permalink_structure = get_option( 'permalink_structure' );
51
- $is_ssl = is_ssl();
52
- $users_can_register = get_option( 'users_can_register' );
53
- $default_comment_status = get_option( 'default_comment_status' );
54
- $is_multisite = is_multisite();
55
- $core_version = get_bloginfo( 'version' );
56
- $core_updates = get_core_updates();
57
- $core_update_needed = '';
58
-
59
- foreach ( $core_updates as $core => $update ) {
60
- if ( 'upgrade' === $update->response ) {
61
- // translators: %s: Latest WordPress version number.
62
- $core_update_needed = ' ' . sprintf( __( '(Latest version: %s)', 'health-check' ), $update->version );
63
- } else {
64
- $core_update_needed = '';
65
- }
66
- }
67
-
68
- // Set up the array that holds all debug information.
69
- $info = array();
70
-
71
- $info['wp-core'] = array(
72
- 'label' => __( 'WordPress', 'health-check' ),
73
- 'fields' => array(
74
- 'version' => array(
75
- 'label' => __( 'Version', 'health-check' ),
76
- 'value' => $core_version . $core_update_needed,
77
- 'debug' => $core_version,
78
- ),
79
- 'site_language' => array(
80
- 'label' => __( 'Site Language', 'health-check' ),
81
- 'value' => get_locale(),
82
- ),
83
- 'user_language' => array(
84
- 'label' => __( 'User Language', 'health-check' ),
85
- 'value' => get_user_locale(),
86
- ),
87
- 'home_url' => array(
88
- 'label' => __( 'Home URL', 'health-check' ),
89
- 'value' => get_bloginfo( 'url' ),
90
- 'private' => true,
91
- ),
92
- 'site_url' => array(
93
- 'label' => __( 'Site URL', 'health-check' ),
94
- 'value' => get_bloginfo( 'wpurl' ),
95
- 'private' => true,
96
- ),
97
- 'permalink' => array(
98
- 'label' => __( 'Permalink structure', 'health-check' ),
99
- 'value' => $permalink_structure ? $permalink_structure : __( 'No permalink structure set', 'health-check' ),
100
- 'debug' => $permalink_structure,
101
- ),
102
- 'https_status' => array(
103
- 'label' => __( 'Is this site using HTTPS?', 'health-check' ),
104
- 'value' => $is_ssl ? __( 'Yes', 'health-check' ) : __( 'No', 'health-check' ),
105
- 'debug' => $is_ssl,
106
- ),
107
- 'user_registration' => array(
108
- 'label' => __( 'Can anyone register on this site?', 'health-check' ),
109
- 'value' => $users_can_register ? __( 'Yes', 'health-check' ) : __( 'No', 'health-check' ),
110
- 'debug' => $users_can_register,
111
- ),
112
- 'default_comment_status' => array(
113
- 'label' => __( 'Default comment status', 'health-check' ),
114
- 'value' => 'open' === $default_comment_status ? _x( 'Open', 'comment status', 'health-check' ) : _x( 'Closed', 'comment status', 'health-check' ),
115
- 'debug' => $default_comment_status,
116
- ),
117
- 'multisite' => array(
118
- 'label' => __( 'Is this a multisite?', 'health-check' ),
119
- 'value' => $is_multisite ? __( 'Yes', 'health-check' ) : __( 'No', 'health-check' ),
120
- 'debug' => $is_multisite,
121
- ),
122
- ),
123
- );
124
-
125
- if ( ! $is_multisite ) {
126
- $info['wp-paths-sizes'] = array(
127
- 'label' => __( 'Directories and Sizes', 'health-check' ),
128
- 'fields' => array(),
129
- );
130
- }
131
-
132
- $info['wp-dropins'] = array(
133
- 'label' => __( 'Drop-ins', 'health-check' ),
134
- 'show_count' => true,
135
- 'description' => __( 'Drop-ins are single files that replace or enhance WordPress features in ways that are not possible for traditional plugins.', 'health-check' ),
136
- 'fields' => array(),
137
- );
138
-
139
- $info['wp-active-theme'] = array(
140
- 'label' => __( 'Active Theme', 'health-check' ),
141
- 'fields' => array(),
142
- );
143
-
144
- $info['wp-parent-theme'] = array(
145
- 'label' => __( 'Parent Theme', 'health-check' ),
146
- 'fields' => array(),
147
- );
148
-
149
- $info['wp-themes-inactive'] = array(
150
- 'label' => __( 'Inactive Themes', 'health-check' ),
151
- 'show_count' => true,
152
- 'fields' => array(),
153
- );
154
-
155
- $info['wp-mu-plugins'] = array(
156
- 'label' => __( 'Must Use Plugins', 'health-check' ),
157
- 'show_count' => true,
158
- 'fields' => array(),
159
- );
160
-
161
- $info['wp-plugins-active'] = array(
162
- 'label' => __( 'Active Plugins', 'health-check' ),
163
- 'show_count' => true,
164
- 'fields' => array(),
165
- );
166
-
167
- $info['wp-plugins-inactive'] = array(
168
- 'label' => __( 'Inactive Plugins', 'health-check' ),
169
- 'show_count' => true,
170
- 'fields' => array(),
171
- );
172
-
173
- $info['wp-media'] = array(
174
- 'label' => __( 'Media Handling', 'health-check' ),
175
- 'fields' => array(),
176
- );
177
-
178
- $info['wp-server'] = array(
179
- 'label' => __( 'Server', 'health-check' ),
180
- 'description' => __( 'The options shown below relate to your server setup. If changes are required, you may need your web host&#8217;s assistance.', 'health-check' ),
181
- 'fields' => array(),
182
- );
183
-
184
- $info['wp-database'] = array(
185
- 'label' => __( 'Database', 'health-check' ),
186
- 'fields' => array(),
187
- );
188
-
189
- // Check if WP_DEBUG_LOG is set.
190
- $wp_debug_log_value = __( 'Disabled', 'health-check' );
191
-
192
- if ( is_string( WP_DEBUG_LOG ) ) {
193
- $wp_debug_log_value = WP_DEBUG_LOG;
194
- } elseif ( WP_DEBUG_LOG ) {
195
- $wp_debug_log_value = __( 'Enabled', 'health-check' );
196
- }
197
-
198
- // Check CONCATENATE_SCRIPTS.
199
- if ( defined( 'CONCATENATE_SCRIPTS' ) ) {
200
- $concatenate_scripts = CONCATENATE_SCRIPTS ? __( 'Enabled', 'health-check' ) : __( 'Disabled', 'health-check' );
201
- $concatenate_scripts_debug = CONCATENATE_SCRIPTS ? 'true' : 'false';
202
- } else {
203
- $concatenate_scripts = __( 'Undefined', 'health-check' );
204
- $concatenate_scripts_debug = 'undefined';
205
- }
206
-
207
- // Check COMPRESS_SCRIPTS.
208
- if ( defined( 'COMPRESS_SCRIPTS' ) ) {
209
- $compress_scripts = COMPRESS_SCRIPTS ? __( 'Enabled', 'health-check' ) : __( 'Disabled', 'health-check' );
210
- $compress_scripts_debug = COMPRESS_SCRIPTS ? 'true' : 'false';
211
- } else {
212
- $compress_scripts = __( 'Undefined', 'health-check' );
213
- $compress_scripts_debug = 'undefined';
214
- }
215
-
216
- // Check COMPRESS_CSS.
217
- if ( defined( 'COMPRESS_CSS' ) ) {
218
- $compress_css = COMPRESS_CSS ? __( 'Enabled', 'health-check' ) : __( 'Disabled', 'health-check' );
219
- $compress_css_debug = COMPRESS_CSS ? 'true' : 'false';
220
- } else {
221
- $compress_css = __( 'Undefined', 'health-check' );
222
- $compress_css_debug = 'undefined';
223
- }
224
-
225
- // Check WP_LOCAL_DEV.
226
- if ( defined( 'WP_LOCAL_DEV' ) ) {
227
- $wp_local_dev = WP_LOCAL_DEV ? __( 'Enabled', 'health-check' ) : __( 'Disabled', 'health-check' );
228
- $wp_local_dev_debug = WP_LOCAL_DEV ? 'true' : 'false';
229
- } else {
230
- $wp_local_dev = __( 'Undefined', 'health-check' );
231
- $wp_local_dev_debug = 'undefined';
232
- }
233
-
234
- $info['wp-constants'] = array(
235
- 'label' => __( 'WordPress Constants', 'health-check' ),
236
- 'description' => __( 'These settings alter where and how parts of WordPress are loaded.', 'health-check' ),
237
- 'fields' => array(
238
- 'ABSPATH' => array(
239
- 'label' => 'ABSPATH',
240
- 'value' => ABSPATH,
241
- 'private' => true,
242
- ),
243
- 'WP_HOME' => array(
244
- 'label' => 'WP_HOME',
245
- 'value' => ( defined( 'WP_HOME' ) ? WP_HOME : __( 'Undefined', 'health-check' ) ),
246
- 'debug' => ( defined( 'WP_HOME' ) ? WP_HOME : 'undefined' ),
247
- ),
248
- 'WP_SITEURL' => array(
249
- 'label' => 'WP_SITEURL',
250
- 'value' => ( defined( 'WP_SITEURL' ) ? WP_SITEURL : __( 'Undefined', 'health-check' ) ),
251
- 'debug' => ( defined( 'WP_SITEURL' ) ? WP_SITEURL : 'undefined' ),
252
- ),
253
- 'WP_CONTENT_DIR' => array(
254
- 'label' => 'WP_CONTENT_DIR',
255
- 'value' => WP_CONTENT_DIR,
256
- ),
257
- 'WP_PLUGIN_DIR' => array(
258
- 'label' => 'WP_PLUGIN_DIR',
259
- 'value' => WP_PLUGIN_DIR,
260
- ),
261
- 'WP_MAX_MEMORY_LIMIT' => array(
262
- 'label' => 'WP_MAX_MEMORY_LIMIT',
263
- 'value' => WP_MAX_MEMORY_LIMIT,
264
- ),
265
- 'WP_DEBUG' => array(
266
- 'label' => 'WP_DEBUG',
267
- 'value' => WP_DEBUG ? __( 'Enabled', 'health-check' ) : __( 'Disabled', 'health-check' ),
268
- 'debug' => WP_DEBUG,
269
- ),
270
- 'WP_DEBUG_DISPLAY' => array(
271
- 'label' => 'WP_DEBUG_DISPLAY',
272
- 'value' => WP_DEBUG_DISPLAY ? __( 'Enabled', 'health-check' ) : __( 'Disabled', 'health-check' ),
273
- 'debug' => WP_DEBUG_DISPLAY,
274
- ),
275
- 'WP_DEBUG_LOG' => array(
276
- 'label' => 'WP_DEBUG_LOG',
277
- 'value' => $wp_debug_log_value,
278
- 'debug' => WP_DEBUG_LOG,
279
- ),
280
- 'SCRIPT_DEBUG' => array(
281
- 'label' => 'SCRIPT_DEBUG',
282
- 'value' => SCRIPT_DEBUG ? __( 'Enabled', 'health-check' ) : __( 'Disabled', 'health-check' ),
283
- 'debug' => SCRIPT_DEBUG,
284
- ),
285
- 'WP_CACHE' => array(
286
- 'label' => 'WP_CACHE',
287
- 'value' => WP_CACHE ? __( 'Enabled', 'health-check' ) : __( 'Disabled', 'health-check' ),
288
- 'debug' => WP_CACHE,
289
- ),
290
- 'CONCATENATE_SCRIPTS' => array(
291
- 'label' => 'CONCATENATE_SCRIPTS',
292
- 'value' => $concatenate_scripts,
293
- 'debug' => $concatenate_scripts_debug,
294
- ),
295
- 'COMPRESS_SCRIPTS' => array(
296
- 'label' => 'COMPRESS_SCRIPTS',
297
- 'value' => $compress_scripts,
298
- 'debug' => $compress_scripts_debug,
299
- ),
300
- 'COMPRESS_CSS' => array(
301
- 'label' => 'COMPRESS_CSS',
302
- 'value' => $compress_css,
303
- 'debug' => $compress_css_debug,
304
- ),
305
- 'WP_LOCAL_DEV' => array(
306
- 'label' => 'WP_LOCAL_DEV',
307
- 'value' => $wp_local_dev,
308
- 'debug' => $wp_local_dev_debug,
309
- ),
310
- ),
311
- );
312
-
313
- $is_writable_abspath = wp_is_writable( ABSPATH );
314
- $is_writable_wp_content_dir = wp_is_writable( WP_CONTENT_DIR );
315
- $is_writable_upload_dir = wp_is_writable( $upload_dir['basedir'] );
316
- $is_writable_wp_plugin_dir = wp_is_writable( WP_PLUGIN_DIR );
317
- $is_writable_template_directory = wp_is_writable( get_template_directory() . '/..' );
318
-
319
- $info['wp-filesystem'] = array(
320
- 'label' => __( 'Filesystem Permissions', 'health-check' ),
321
- 'description' => __( 'Shows whether WordPress is able to write to the directories it needs access to.', 'health-check' ),
322
- 'fields' => array(
323
- 'wordpress' => array(
324
- 'label' => __( 'The main WordPress directory', 'health-check' ),
325
- 'value' => ( $is_writable_abspath ? __( 'Writable', 'health-check' ) : __( 'Not writable', 'health-check' ) ),
326
- 'debug' => ( $is_writable_abspath ? 'writable' : 'not writable' ),
327
- ),
328
- 'wp-content' => array(
329
- 'label' => __( 'The wp-content directory', 'health-check' ),
330
- 'value' => ( $is_writable_wp_content_dir ? __( 'Writable', 'health-check' ) : __( 'Not writable', 'health-check' ) ),
331
- 'debug' => ( $is_writable_wp_content_dir ? 'writable' : 'not writable' ),
332
- ),
333
- 'uploads' => array(
334
- 'label' => __( 'The uploads directory', 'health-check' ),
335
- 'value' => ( $is_writable_upload_dir ? __( 'Writable', 'health-check' ) : __( 'Not writable', 'health-check' ) ),
336
- 'debug' => ( $is_writable_upload_dir ? 'writable' : 'not writable' ),
337
- ),
338
- 'plugins' => array(
339
- 'label' => __( 'The plugins directory', 'health-check' ),
340
- 'value' => ( $is_writable_wp_plugin_dir ? __( 'Writable', 'health-check' ) : __( 'Not writable', 'health-check' ) ),
341
- 'debug' => ( $is_writable_wp_plugin_dir ? 'writable' : 'not writable' ),
342
- ),
343
- 'themes' => array(
344
- 'label' => __( 'The themes directory', 'health-check' ),
345
- 'value' => ( $is_writable_template_directory ? __( 'Writable', 'health-check' ) : __( 'Not writable', 'health-check' ) ),
346
- 'debug' => ( $is_writable_template_directory ? 'writable' : 'not writable' ),
347
- ),
348
- ),
349
- );
350
-
351
- // Conditionally add debug information for multisite setups.
352
- if ( is_multisite() ) {
353
- $network_query = new WP_Network_Query();
354
- $network_ids = $network_query->query(
355
- array(
356
- 'fields' => 'ids',
357
- 'number' => 100,
358
- 'no_found_rows' => false,
359
- )
360
- );
361
-
362
- $site_count = 0;
363
- foreach ( $network_ids as $network_id ) {
364
- $site_count += get_blog_count( $network_id );
365
- }
366
-
367
- $info['wp-core']['fields']['user_count'] = array(
368
- 'label' => __( 'User count', 'health-check' ),
369
- 'value' => get_user_count(),
370
- );
371
-
372
- $info['wp-core']['fields']['site_count'] = array(
373
- 'label' => __( 'Site count', 'health-check' ),
374
- 'value' => $site_count,
375
- );
376
-
377
- $info['wp-core']['fields']['network_count'] = array(
378
- 'label' => __( 'Network count', 'health-check' ),
379
- 'value' => $network_query->found_networks,
380
- );
381
- } else {
382
- $user_count = count_users();
383
-
384
- $info['wp-core']['fields']['user_count'] = array(
385
- 'label' => __( 'User count', 'health-check' ),
386
- 'value' => $user_count['total_users'],
387
- );
388
- }
389
-
390
- // WordPress features requiring processing.
391
- $wp_dotorg = wp_remote_get( 'https://api.wordpress.org', array( 'timeout' => 10 ) );
392
-
393
- if ( ! is_wp_error( $wp_dotorg ) ) {
394
- $info['wp-core']['fields']['dotorg_communication'] = array(
395
- 'label' => __( 'Communication with WordPress.org', 'health-check' ),
396
- 'value' => __( 'WordPress.org is reachable', 'health-check' ),
397
- 'debug' => 'true',
398
- );
399
- } else {
400
- $info['wp-core']['fields']['dotorg_communication'] = array(
401
- 'label' => __( 'Communication with WordPress.org', 'health-check' ),
402
- 'value' => sprintf(
403
- // translators: 1: The IP address WordPress.org resolves to. 2: The error returned by the lookup.
404
- __( 'Unable to reach WordPress.org at %1$s: %2$s', 'health-check' ),
405
- gethostbyname( 'api.wordpress.org' ),
406
- $wp_dotorg->get_error_message()
407
- ),
408
- 'debug' => $wp_dotorg->get_error_message(),
409
- );
410
- }
411
-
412
- // Remove accordion for Directories and Sizes if in Multisite.
413
- if ( ! $is_multisite ) {
414
- $loading = __( 'Loading&hellip;', 'health-check' );
415
-
416
- $info['wp-paths-sizes']['fields'] = array(
417
- 'wordpress_path' => array(
418
- 'label' => __( 'WordPress directory location', 'health-check' ),
419
- 'value' => untrailingslashit( ABSPATH ),
420
- ),
421
- 'wordpress_size' => array(
422
- 'label' => __( 'WordPress directory size', 'health-check' ),
423
- 'value' => $loading,
424
- 'debug' => 'loading...',
425
- ),
426
- 'uploads_path' => array(
427
- 'label' => __( 'Uploads directory location', 'health-check' ),
428
- 'value' => $upload_dir['basedir'],
429
- ),
430
- 'uploads_size' => array(
431
- 'label' => __( 'Uploads directory size', 'health-check' ),
432
- 'value' => $loading,
433
- 'debug' => 'loading...',
434
- ),
435
- 'themes_path' => array(
436
- 'label' => __( 'Themes directory location', 'health-check' ),
437
- 'value' => get_theme_root(),
438
- ),
439
- 'themes_size' => array(
440
- 'label' => __( 'Themes directory size', 'health-check' ),
441
- 'value' => $loading,
442
- 'debug' => 'loading...',
443
- ),
444
- 'plugins_path' => array(
445
- 'label' => __( 'Plugins directory location', 'health-check' ),
446
- 'value' => WP_PLUGIN_DIR,
447
- ),
448
- 'plugins_size' => array(
449
- 'label' => __( 'Plugins directory size', 'health-check' ),
450
- 'value' => $loading,
451
- 'debug' => 'loading...',
452
- ),
453
- 'database_size' => array(
454
- 'label' => __( 'Database size', 'health-check' ),
455
- 'value' => $loading,
456
- 'debug' => 'loading...',
457
- ),
458
- 'total_size' => array(
459
- 'label' => __( 'Total installation size', 'health-check' ),
460
- 'value' => $loading,
461
- 'debug' => 'loading...',
462
- ),
463
- );
464
- }
465
-
466
- // Get a list of all drop-in replacements.
467
- $dropins = get_dropins();
468
-
469
- // Get dropins descriptions.
470
- $dropin_descriptions = _get_dropins();
471
-
472
- // Spare few function calls.
473
- $not_available = __( 'Not available', 'health-check' );
474
-
475
- foreach ( $dropins as $dropin_key => $dropin ) {
476
- $info['wp-dropins']['fields'][ sanitize_text_field( $dropin_key ) ] = array(
477
- 'label' => $dropin_key,
478
- 'value' => $dropin_descriptions[ $dropin_key ][0],
479
- 'debug' => 'true',
480
- );
481
- }
482
-
483
- // Populate the media fields.
484
- $info['wp-media']['fields']['image_editor'] = array(
485
- 'label' => __( 'Active editor', 'health-check' ),
486
- 'value' => _wp_image_editor_choose(),
487
- );
488
-
489
- // Get ImageMagic information, if available.
490
- if ( class_exists( 'Imagick' ) ) {
491
- // Save the Imagick instance for later use.
492
- $imagick = new Imagick();
493
- $imagick_version = $imagick->getVersion();
494
- } else {
495
- $imagick_version = __( 'Not available', 'health-check' );
496
- }
497
-
498
- $info['wp-media']['fields']['imagick_module_version'] = array(
499
- 'label' => __( 'ImageMagick version number', 'health-check' ),
500
- 'value' => ( is_array( $imagick_version ) ? $imagick_version['versionNumber'] : $imagick_version ),
501
- );
502
-
503
- $info['wp-media']['fields']['imagemagick_version'] = array(
504
- 'label' => __( 'ImageMagick version string', 'health-check' ),
505
- 'value' => ( is_array( $imagick_version ) ? $imagick_version['versionString'] : $imagick_version ),
506
- );
507
-
508
- // If Imagick is used as our editor, provide some more information about its limitations.
509
- if ( 'WP_Image_Editor_Imagick' === _wp_image_editor_choose() && isset( $imagick ) && $imagick instanceof Imagick ) {
510
- $limits = array(
511
- 'area' => ( defined( 'imagick::RESOURCETYPE_AREA' ) ? size_format( $imagick->getResourceLimit( imagick::RESOURCETYPE_AREA ) ) : $not_available ),
512
- 'disk' => ( defined( 'imagick::RESOURCETYPE_DISK' ) ? $imagick->getResourceLimit( imagick::RESOURCETYPE_DISK ) : $not_available ),
513
- 'file' => ( defined( 'imagick::RESOURCETYPE_FILE' ) ? $imagick->getResourceLimit( imagick::RESOURCETYPE_FILE ) : $not_available ),
514
- 'map' => ( defined( 'imagick::RESOURCETYPE_MAP' ) ? size_format( $imagick->getResourceLimit( imagick::RESOURCETYPE_MAP ) ) : $not_available ),
515
- 'memory' => ( defined( 'imagick::RESOURCETYPE_MEMORY' ) ? size_format( $imagick->getResourceLimit( imagick::RESOURCETYPE_MEMORY ) ) : $not_available ),
516
- 'thread' => ( defined( 'imagick::RESOURCETYPE_THREAD' ) ? $imagick->getResourceLimit( imagick::RESOURCETYPE_THREAD ) : $not_available ),
517
- );
518
-
519
- $limits_debug = array(
520
- 'imagick::RESOURCETYPE_AREA' => ( defined( 'imagick::RESOURCETYPE_AREA' ) ? size_format( $imagick->getResourceLimit( imagick::RESOURCETYPE_AREA ) ) : 'not available' ),
521
- 'imagick::RESOURCETYPE_DISK' => ( defined( 'imagick::RESOURCETYPE_DISK' ) ? $imagick->getResourceLimit( imagick::RESOURCETYPE_DISK ) : 'not available' ),
522
- 'imagick::RESOURCETYPE_FILE' => ( defined( 'imagick::RESOURCETYPE_FILE' ) ? $imagick->getResourceLimit( imagick::RESOURCETYPE_FILE ) : 'not available' ),
523
- 'imagick::RESOURCETYPE_MAP' => ( defined( 'imagick::RESOURCETYPE_MAP' ) ? size_format( $imagick->getResourceLimit( imagick::RESOURCETYPE_MAP ) ) : 'not available' ),
524
- 'imagick::RESOURCETYPE_MEMORY' => ( defined( 'imagick::RESOURCETYPE_MEMORY' ) ? size_format( $imagick->getResourceLimit( imagick::RESOURCETYPE_MEMORY ) ) : 'not available' ),
525
- 'imagick::RESOURCETYPE_THREAD' => ( defined( 'imagick::RESOURCETYPE_THREAD' ) ? $imagick->getResourceLimit( imagick::RESOURCETYPE_THREAD ) : 'not available' ),
526
- );
527
-
528
- $info['wp-media']['fields']['imagick_limits'] = array(
529
- 'label' => __( 'Imagick Resource Limits', 'health-check' ),
530
- 'value' => $limits,
531
- 'debug' => $limits_debug,
532
- );
533
- }
534
-
535
- // Get GD information, if available.
536
- if ( function_exists( 'gd_info' ) ) {
537
- $gd = gd_info();
538
- } else {
539
- $gd = false;
540
- }
541
-
542
- $info['wp-media']['fields']['gd_version'] = array(
543
- 'label' => __( 'GD version', 'health-check' ),
544
- 'value' => ( is_array( $gd ) ? $gd['GD Version'] : $not_available ),
545
- 'debug' => ( is_array( $gd ) ? $gd['GD Version'] : 'not available' ),
546
- );
547
-
548
- // Get Ghostscript information, if available.
549
- if ( function_exists( 'exec' ) ) {
550
- $gs = exec( 'gs --version' );
551
-
552
- if ( empty( $gs ) ) {
553
- $gs = $not_available;
554
- $gs_debug = 'not available';
555
- } else {
556
- $gs_debug = $gs;
557
- }
558
- } else {
559
- $gs = __( 'Unable to determine if Ghostscript is installed', 'health-check' );
560
- $gs_debug = 'unknown';
561
- }
562
-
563
- $info['wp-media']['fields']['ghostscript_version'] = array(
564
- 'label' => __( 'Ghostscript version', 'health-check' ),
565
- 'value' => $gs,
566
- 'debug' => $gs_debug,
567
- );
568
-
569
- // Populate the server debug fields.
570
- if ( function_exists( 'php_uname' ) ) {
571
- $server_architecture = sprintf( '%s %s %s', php_uname( 's' ), php_uname( 'r' ), php_uname( 'm' ) );
572
- } else {
573
- $server_architecture = 'unknown';
574
- }
575
-
576
- if ( function_exists( 'phpversion' ) ) {
577
- $php_version_debug = phpversion();
578
- // Whether PHP supports 64bit
579
- $php64bit = ( PHP_INT_SIZE * 8 === 64 );
580
-
581
- $php_version = sprintf(
582
- '%s %s',
583
- $php_version_debug,
584
- ( $php64bit ? __( '(Supports 64bit values)', 'health-check' ) : __( '(Does not support 64bit values)', 'health-check' ) )
585
- );
586
-
587
- if ( $php64bit ) {
588
- $php_version_debug .= ' 64bit';
589
- }
590
- } else {
591
- $php_version = __( 'Unable to determine PHP version', 'health-check' );
592
- $php_version_debug = 'unknown';
593
- }
594
-
595
- if ( function_exists( 'php_sapi_name' ) ) {
596
- $php_sapi = php_sapi_name();
597
- } else {
598
- $php_sapi = 'unknown';
599
- }
600
-
601
- if ( function_exists( 'get_current_user' ) && function_exists( 'getmyuid' ) ) {
602
- $php_getuid = sprintf(
603
- '%s (%s)',
604
- get_current_user(),
605
- getmyuid()
606
- );
607
- } else {
608
- $php_getuid = 'unknown';
609
- }
610
-
611
- $info['wp-server']['fields']['server_architecture'] = array(
612
- 'label' => __( 'Server architecture', 'health-check' ),
613
- 'value' => ( 'unknown' !== $server_architecture ? $server_architecture : __( 'Unable to determine server architecture', 'health-check' ) ),
614
- 'debug' => $server_architecture,
615
- );
616
- $info['wp-server']['fields']['php-uid'] = array(
617
- 'label' => __( 'Website server user', 'health-check' ),
618
- 'value' => ( 'unknown' !== $php_getuid ? $php_getuid : __( 'Unable to determine the websites server user', 'health-check' ) ),
619
- 'debug' => $php_getuid,
620
- 'private' => true,
621
- );
622
- $info['wp-server']['fields']['httpd_software'] = array(
623
- 'label' => __( 'Web server', 'health-check' ),
624
- 'value' => ( isset( $_SERVER['SERVER_SOFTWARE'] ) ? $_SERVER['SERVER_SOFTWARE'] : __( 'Unable to determine what web server software is used', 'health-check' ) ),
625
- 'debug' => ( isset( $_SERVER['SERVER_SOFTWARE'] ) ? $_SERVER['SERVER_SOFTWARE'] : 'unknown' ),
626
- );
627
- $info['wp-server']['fields']['php_version'] = array(
628
- 'label' => __( 'PHP version', 'health-check' ),
629
- 'value' => $php_version,
630
- 'debug' => $php_version_debug,
631
- );
632
- $info['wp-server']['fields']['php_sapi'] = array(
633
- 'label' => __( 'PHP SAPI', 'health-check' ),
634
- 'value' => ( 'unknown' !== $php_sapi ? $php_sapi : __( 'Unable to determine PHP SAPI', 'health-check' ) ),
635
- 'debug' => $php_sapi,
636
- );
637
-
638
- // Some servers disable `ini_set()` and `ini_get()`, we check this before trying to get configuration values.
639
- if ( ! function_exists( 'ini_get' ) ) {
640
- $info['wp-server']['fields']['ini_get'] = array(
641
- 'label' => __( 'Server settings', 'health-check' ),
642
- 'value' => __( 'Unable to determine some settings, as the ini_get() function has been disabled.', 'health-check' ),
643
- 'debug' => 'ini_get() is disabled',
644
- );
645
- } else {
646
- $info['wp-server']['fields']['max_input_variables'] = array(
647
- 'label' => __( 'PHP max input variables', 'health-check' ),
648
- 'value' => ini_get( 'max_input_vars' ),
649
- );
650
- $info['wp-server']['fields']['time_limit'] = array(
651
- 'label' => __( 'PHP time limit', 'health-check' ),
652
- 'value' => ini_get( 'max_execution_time' ),
653
- );
654
- $info['wp-server']['fields']['memory_limit'] = array(
655
- 'label' => __( 'PHP memory limit', 'health-check' ),
656
- 'value' => ini_get( 'memory_limit' ),
657
- );
658
- $info['wp-server']['fields']['max_input_time'] = array(
659
- 'label' => __( 'Max input time', 'health-check' ),
660
- 'value' => ini_get( 'max_input_time' ),
661
- );
662
- $info['wp-server']['fields']['upload_max_size'] = array(
663
- 'label' => __( 'Upload max filesize', 'health-check' ),
664
- 'value' => ini_get( 'upload_max_filesize' ),
665
- );
666
- $info['wp-server']['fields']['php_post_max_size'] = array(
667
- 'label' => __( 'PHP post max size', 'health-check' ),
668
- 'value' => ini_get( 'post_max_size' ),
669
- );
670
- }
671
-
672
- if ( function_exists( 'curl_version' ) ) {
673
- $curl = curl_version();
674
-
675
- $info['wp-server']['fields']['curl_version'] = array(
676
- 'label' => __( 'cURL version', 'health-check' ),
677
- 'value' => sprintf( '%s %s', $curl['version'], $curl['ssl_version'] ),
678
- );
679
- } else {
680
- $info['wp-server']['fields']['curl_version'] = array(
681
- 'label' => __( 'cURL version', 'health-check' ),
682
- 'value' => $not_available,
683
- 'debug' => 'not available',
684
- );
685
- }
686
-
687
- // SUHOSIN
688
- $suhosin_loaded = ( extension_loaded( 'suhosin' ) || ( defined( 'SUHOSIN_PATCH' ) && constant( 'SUHOSIN_PATCH' ) ) );
689
-
690
- $info['wp-server']['fields']['suhosin'] = array(
691
- 'label' => __( 'Is SUHOSIN installed?', 'health-check' ),
692
- 'value' => ( $suhosin_loaded ? __( 'Yes', 'health-check' ) : __( 'No', 'health-check' ) ),
693
- 'debug' => $suhosin_loaded,
694
- );
695
-
696
- // Imagick
697
- $imagick_loaded = extension_loaded( 'imagick' );
698
-
699
- $info['wp-server']['fields']['imagick_availability'] = array(
700
- 'label' => __( 'Is the Imagick library available?', 'health-check' ),
701
- 'value' => ( $imagick_loaded ? __( 'Yes', 'health-check' ) : __( 'No', 'health-check' ) ),
702
- 'debug' => $imagick_loaded,
703
- );
704
-
705
- $server_request = wp_remote_get( site_url(), compact( 'cookies', 'headers', 'timeout' ) );
706
- if ( is_wp_error( $server_request ) ) {
707
- $info['wp-server']['fields']['server-headers'] = array(
708
- 'label' => __( 'Server headers', 'health-check' ),
709
- 'value' => __( 'Could not retrieve server headers', 'health-check' ),
710
- 'debug' => 'unknown',
711
- );
712
- } else {
713
- $server_headers = wp_remote_retrieve_headers( $server_request );
714
-
715
- $info['wp-server']['fields']['server-headers'] = array(
716
- 'label' => __( 'Server headers', 'health-check' ),
717
- 'value' => ( $server_headers instanceof \Requests_Utility_CaseInsensitiveDictionary ? $server_headers->getAll() : $server_headers ),
718
- 'debug' => ( $server_headers instanceof \Requests_Utility_CaseInsensitiveDictionary ? $server_headers->getAll() : $server_headers ),
719
- );
720
- }
721
-
722
- // Check if a .htaccess file exists.
723
- if ( $is_apache && is_file( ABSPATH . '.htaccess' ) ) {
724
- // If the file exists, grab the content of it.
725
- $htaccess_content = file_get_contents( ABSPATH . '.htaccess' );
726
-
727
- // Filter away the core WordPress rules.
728
- $filtered_htaccess_content = trim( preg_replace( '/\# BEGIN WordPress[\s\S]+?# END WordPress/si', '', $htaccess_content ) );
729
- $filtered_htaccess_content = ! empty( $filtered_htaccess_content );
730
-
731
- $info['wp-server']['fields']['htaccess_extra_rules'] = array(
732
- 'label' => __( '.htaccess rules', 'health-check' ),
733
- 'value' => ( $filtered_htaccess_content ? __( 'Custom rules have been added to your .htaccess file.', 'health-check' ) : __( 'Your .htaccess file contains only core WordPress features.', 'health-check' ) ),
734
- 'debug' => $filtered_htaccess_content,
735
- );
736
- }
737
-
738
- // Populate the database debug fields.
739
- if ( is_resource( $wpdb->dbh ) ) {
740
- // Old mysql extension.
741
- $extension = 'mysql';
742
- } elseif ( is_object( $wpdb->dbh ) ) {
743
- // mysqli or PDO.
744
- $extension = get_class( $wpdb->dbh );
745
- } else {
746
- // Unknown sql extension.
747
- $extension = null;
748
- }
749
-
750
- $server = $wpdb->get_var( 'SELECT VERSION()' );
751
-
752
- if ( isset( $wpdb->use_mysqli ) && $wpdb->use_mysqli ) {
753
- $client_version = $wpdb->dbh->client_info;
754
- } else {
755
- // phpcs:ignore WordPress.DB.RestrictedFunctions.mysql_mysql_get_client_info
756
- if ( preg_match( '|[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}|', mysql_get_client_info(), $matches ) ) {
757
- $client_version = $matches[0];
758
- } else {
759
- $client_version = null;
760
- }
761
- }
762
-
763
- $info['wp-database']['fields']['extension'] = array(
764
- 'label' => __( 'Extension', 'health-check' ),
765
- 'value' => $extension,
766
- );
767
-
768
- $info['wp-database']['fields']['server_version'] = array(
769
- 'label' => __( 'Server version', 'health-check' ),
770
- 'value' => $server,
771
- );
772
-
773
- $info['wp-database']['fields']['client_version'] = array(
774
- 'label' => __( 'Client version', 'health-check' ),
775
- 'value' => $client_version,
776
- );
777
-
778
- $info['wp-database']['fields']['database_user'] = array(
779
- 'label' => __( 'Database user', 'health-check' ),
780
- 'value' => $wpdb->dbuser,
781
- 'private' => true,
782
- );
783
-
784
- $info['wp-database']['fields']['database_host'] = array(
785
- 'label' => __( 'Database host', 'health-check' ),
786
- 'value' => $wpdb->dbhost,
787
- 'private' => true,
788
- );
789
-
790
- $info['wp-database']['fields']['database_name'] = array(
791
- 'label' => __( 'Database name', 'health-check' ),
792
- 'value' => $wpdb->dbname,
793
- 'private' => true,
794
- );
795
-
796
- $info['wp-database']['fields']['database_prefix'] = array(
797
- 'label' => __( 'Database prefix', 'health-check' ),
798
- 'value' => $wpdb->prefix,
799
- 'private' => true,
800
- );
801
-
802
- // List must use plugins if there are any.
803
- $mu_plugins = get_mu_plugins();
804
-
805
- foreach ( $mu_plugins as $plugin_path => $plugin ) {
806
- $plugin_version = $plugin['Version'];
807
- $plugin_author = $plugin['Author'];
808
-
809
- $plugin_version_string = __( 'No version or author information is available.', 'health-check' );
810
- $plugin_version_string_debug = 'author: (undefined), version: (undefined)';
811
-
812
- if ( ! empty( $plugin_version ) && ! empty( $plugin_author ) ) {
813
- // translators: 1: Plugin version number. 2: Plugin author name.
814
- $plugin_version_string = sprintf( __( 'Version %1$s by %2$s', 'health-check' ), $plugin_version, $plugin_author );
815
- $plugin_version_string_debug = sprintf( 'version: %s, author: %s', $plugin_version, $plugin_author );
816
- } else {
817
- if ( ! empty( $plugin_author ) ) {
818
- // translators: %s: Plugin author name.
819
- $plugin_version_string = sprintf( __( 'By %s', 'health-check' ), $plugin_author );
820
- $plugin_version_string_debug = sprintf( 'author: %s, version: (undefined)', $plugin_author );
821
- }
822
-
823
- if ( ! empty( $plugin_version ) ) {
824
- // translators: %s: Plugin version number.
825
- $plugin_version_string = sprintf( __( 'Version %s', 'health-check' ), $plugin_version );
826
- $plugin_version_string_debug = sprintf( 'author: (undefined), version: %s', $plugin_version );
827
- }
828
- }
829
-
830
- $info['wp-mu-plugins']['fields'][ sanitize_text_field( $plugin['Name'] ) ] = array(
831
- 'label' => $plugin['Name'],
832
- 'value' => $plugin_version_string,
833
- 'debug' => $plugin_version_string_debug,
834
- );
835
- }
836
-
837
- // List all available plugins.
838
- $plugins = get_plugins();
839
- $plugin_updates = get_plugin_updates();
840
-
841
- foreach ( $plugins as $plugin_path => $plugin ) {
842
- $plugin_part = ( is_plugin_active( $plugin_path ) ) ? 'wp-plugins-active' : 'wp-plugins-inactive';
843
-
844
- $plugin_version = $plugin['Version'];
845
- $plugin_author = $plugin['Author'];
846
-
847
- $plugin_version_string = __( 'No version or author information is available.', 'health-check' );
848
- $plugin_version_string_debug = 'author: (undefined), version: (undefined)';
849
-
850
- if ( ! empty( $plugin_version ) && ! empty( $plugin_author ) ) {
851
- // translators: 1: Plugin version number. 2: Plugin author name.
852
- $plugin_version_string = sprintf( __( 'Version %1$s by %2$s', 'health-check' ), $plugin_version, $plugin_author );
853
- $plugin_version_string_debug = sprintf( 'version: %s, author: %s', $plugin_version, $plugin_author );
854
- } else {
855
- if ( ! empty( $plugin_author ) ) {
856
- // translators: %s: Plugin author name.
857
- $plugin_version_string = sprintf( __( 'By %s', 'health-check' ), $plugin_author );
858
- $plugin_version_string_debug = sprintf( 'author: %s, version: (undefined)', $plugin_author );
859
- }
860
-
861
- if ( ! empty( $plugin_version ) ) {
862
- // translators: %s: Plugin version number.
863
- $plugin_version_string = sprintf( __( 'Version %s', 'health-check' ), $plugin_version );
864
- $plugin_version_string_debug = sprintf( 'author: (undefined), version: %s', $plugin_version );
865
- }
866
- }
867
-
868
- if ( array_key_exists( $plugin_path, $plugin_updates ) ) {
869
- // translators: %s: Latest plugin version number.
870
- $plugin_version_string .= ' ' . sprintf( __( '(Latest version: %s)', 'health-check' ), $plugin_updates[ $plugin_path ]->update->new_version );
871
- $plugin_version_string_debug .= sprintf( ' (latest version: %s)', $plugin_updates[ $plugin_path ]->update->new_version );
872
- }
873
-
874
- $info[ $plugin_part ]['fields'][ sanitize_text_field( $plugin['Name'] ) ] = array(
875
- 'label' => $plugin['Name'],
876
- 'value' => $plugin_version_string,
877
- 'debug' => $plugin_version_string_debug,
878
- );
879
- }
880
-
881
- // Populate the section for the currently active theme.
882
- global $_wp_theme_features;
883
- $theme_features = array();
884
-
885
- if ( ! empty( $_wp_theme_features ) ) {
886
- foreach ( $_wp_theme_features as $feature => $options ) {
887
- $theme_features[] = $feature;
888
- }
889
- }
890
-
891
- $active_theme = wp_get_theme();
892
- $theme_updates = get_theme_updates();
893
-
894
- // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
895
- $active_theme_version = $active_theme->Version;
896
- $active_theme_version_debug = $active_theme_version;
897
-
898
- if ( array_key_exists( $active_theme->stylesheet, $theme_updates ) ) {
899
- $theme_update_new_version = $theme_updates[ $active_theme->stylesheet ]->update['new_version'];
900
-
901
- // translators: %s: Latest theme version number.
902
- $active_theme_version .= ' ' . sprintf( __( '(Latest version: %s)', 'health-check' ), $theme_update_new_version );
903
- $active_theme_version_debug .= sprintf( ' (latest version: %s)', $theme_update_new_version );
904
- }
905
-
906
- $active_theme_author_uri = $active_theme->offsetGet( 'Author URI' );
907
-
908
- $info['wp-active-theme']['fields'] = array(
909
- 'name' => array(
910
- 'label' => __( 'Name', 'health-check' ),
911
- 'value' => sprintf(
912
- // translators: 1: Parent theme name. 2: Parent theme slug.
913
- __( '%1$s (%2$s)', 'health-check' ),
914
- // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
915
- $active_theme->Name,
916
- $active_theme->stylesheet
917
- ),
918
- ),
919
- 'version' => array(
920
- 'label' => __( 'Version', 'health-check' ),
921
- 'value' => $active_theme_version,
922
- 'debug' => $active_theme_version_debug,
923
- ),
924
- 'author' => array(
925
- 'label' => __( 'Author', 'health-check' ),
926
- // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
927
- 'value' => wp_kses( $active_theme->Author, array() ),
928
- ),
929
- 'author_website' => array(
930
- 'label' => __( 'Author website', 'health-check' ),
931
- 'value' => ( $active_theme_author_uri ? $active_theme_author_uri : __( 'Undefined', 'health-check' ) ),
932
- 'debug' => ( $active_theme_author_uri ? $active_theme_author_uri : '(undefined)' ),
933
- ),
934
- 'parent_theme' => array(
935
- 'label' => __( 'Parent theme', 'health-check' ),
936
- 'value' => ( $active_theme->parent_theme ? $active_theme->parent_theme . ' (' . $active_theme->template . ')' : __( 'None', 'health-check' ) ),
937
- 'debug' => ( $active_theme->parent_theme ? $active_theme->parent_theme . ' (' . $active_theme->template . ')' : 'none' ),
938
- ),
939
- 'theme_features' => array(
940
- 'label' => __( 'Theme features', 'health-check' ),
941
- 'value' => implode( ', ', $theme_features ),
942
- ),
943
- 'theme_path' => array(
944
- 'label' => __( 'Theme directory location', 'health-check' ),
945
- 'value' => get_stylesheet_directory(),
946
- ),
947
- );
948
-
949
- $parent_theme = $active_theme->parent();
950
-
951
- if ( $parent_theme ) {
952
- // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
953
- $parent_theme_version = $parent_theme->Version;
954
- $parent_theme_version_debug = $parent_theme_version;
955
-
956
- if ( array_key_exists( $parent_theme->stylesheet, $theme_updates ) ) {
957
- $parent_theme_update_new_version = $theme_updates[ $parent_theme->stylesheet ]->update['new_version'];
958
-
959
- // translators: %s: Latest theme version number.
960
- $parent_theme_version .= ' ' . sprintf( __( '(Latest version: %s)', 'health-check' ), $parent_theme_update_new_version );
961
- $parent_theme_version_debug .= sprintf( ' (latest version: %s)', $parent_theme_update_new_version );
962
- }
963
-
964
- $parent_theme_author_uri = $parent_theme->offsetGet( 'Author URI' );
965
-
966
- $info['wp-parent-theme']['fields'] = array(
967
- 'name' => array(
968
- 'label' => __( 'Name', 'health-check' ),
969
- 'value' => sprintf(
970
- // translators: 1: Parent theme name. 2: Parent theme slug.
971
- __( '%1$s (%2$s)', 'health-check' ),
972
- // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
973
- $parent_theme->Name,
974
- $parent_theme->stylesheet
975
- ),
976
- ),
977
- 'version' => array(
978
- 'label' => __( 'Version', 'health-check' ),
979
- 'value' => $parent_theme_version,
980
- 'debug' => $parent_theme_version_debug,
981
- ),
982
- 'author' => array(
983
- 'label' => __( 'Author', 'health-check' ),
984
- // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
985
- 'value' => wp_kses( $parent_theme->Author, array() ),
986
- ),
987
- 'author_website' => array(
988
- 'label' => __( 'Author website', 'health-check' ),
989
- 'value' => ( $parent_theme_author_uri ? $parent_theme_author_uri : __( 'Undefined', 'health-check' ) ),
990
- 'debug' => ( $parent_theme_author_uri ? $parent_theme_author_uri : '(undefined)' ),
991
- ),
992
- 'theme_path' => array(
993
- 'label' => __( 'Theme directory location', 'health-check' ),
994
- 'value' => get_template_directory(),
995
- ),
996
- );
997
- }
998
-
999
- // Populate a list of all themes available in the install.
1000
- $all_themes = wp_get_themes();
1001
-
1002
- foreach ( $all_themes as $theme_slug => $theme ) {
1003
- // Ignore the currently active theme from the list of all themes.
1004
- if ( $active_theme->stylesheet === $theme_slug ) {
1005
- continue;
1006
- }
1007
-
1008
- // Ignore the currently active parent theme from the list of all themes.
1009
- if ( ! empty( $parent_theme ) && $parent_theme->stylesheet === $theme_slug ) {
1010
- continue;
1011
- }
1012
-
1013
- // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
1014
- $theme_version = $theme->Version;
1015
- // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
1016
- $theme_author = $theme->Author;
1017
-
1018
- // Sanitize
1019
- $theme_author = wp_kses( $theme_author, array() );
1020
-
1021
- $theme_version_string = __( 'No version or author information is available.', 'health-check' );
1022
- $theme_version_string_debug = 'undefined';
1023
-
1024
- if ( ! empty( $theme_version ) && ! empty( $theme_author ) ) {
1025
- // translators: 1: Theme version number. 2: Theme author name.
1026
- $theme_version_string = sprintf( __( 'Version %1$s by %2$s', 'health-check' ), $theme_version, $theme_author );
1027
- $theme_version_string_debug = sprintf( 'version: %s, author: %s', $theme_version, $theme_author );
1028
- } else {
1029
- if ( ! empty( $theme_author ) ) {
1030
- // translators: %s: Theme author name.
1031
- $theme_version_string = sprintf( __( 'By %s', 'health-check' ), $theme_author );
1032
- $theme_version_string_debug = sprintf( 'author: %s, version: (undefined)', $theme_author );
1033
- }
1034
-
1035
- if ( ! empty( $theme_version ) ) {
1036
- // translators: %s: Theme version number.
1037
- $theme_version_string = sprintf( __( 'Version %s', 'health-check' ), $theme_version );
1038
- $theme_version_string_debug = sprintf( 'author: (undefined), version: %s', $theme_version );
1039
- }
1040
- }
1041
-
1042
- if ( array_key_exists( $theme_slug, $theme_updates ) ) {
1043
- // translators: %s: Latest theme version number.
1044
- $theme_version_string .= ' ' . sprintf( __( '(Latest version: %s)', 'health-check' ), $theme_updates[ $theme_slug ]->update['new_version'] );
1045
- $theme_version_string_debug .= sprintf( ' (latest version: %s)', $theme_updates[ $theme_slug ]->update['new_version'] );
1046
- }
1047
-
1048
- // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
1049
- $info['wp-themes-inactive']['fields'][ sanitize_text_field( $theme->Name ) ] = array(
1050
- 'label' => sprintf(
1051
- // translators: 1: Theme name. 2: Theme slug.
1052
- __( '%1$s (%2$s)', 'health-check' ),
1053
- // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
1054
- $theme->Name,
1055
- $theme_slug
1056
- ),
1057
- 'value' => $theme_version_string,
1058
- 'debug' => $theme_version_string_debug,
1059
- );
1060
- }
1061
-
1062
- // Add more filesystem checks
1063
- if ( defined( 'WPMU_PLUGIN_DIR' ) && is_dir( WPMU_PLUGIN_DIR ) ) {
1064
- $is_writable_wpmu_plugin_dir = wp_is_writable( WPMU_PLUGIN_DIR );
1065
-
1066
- $info['wp-filesystem']['fields']['mu-plugins'] = array(
1067
- 'label' => __( 'The must use plugins directory', 'health-check' ),
1068
- 'value' => ( $is_writable_wpmu_plugin_dir ? __( 'Writable', 'health-check' ) : __( 'Not writable', 'health-check' ) ),
1069
- 'debug' => ( $is_writable_wpmu_plugin_dir ? 'writable' : 'not writable' ),
1070
- );
1071
- }
1072
-
1073
- /**
1074
- * Add or modify the debug information.
1075
- *
1076
- * Plugin or themes may wish to introduce their own debug information without creating additional admin pages
1077
- * they can utilize this filter to introduce their own sections or add more data to existing sections.
1078
- *
1079
- * Array keys for sections added by core are all prefixed with `wp-`, plugins and themes should use their own slug as
1080
- * a prefix, both for consistency as well as avoiding key collisions. Note that the array keys are used as labels
1081
- * for the copied data.
1082
- *
1083
- * All strings are expected to be plain text except $description that can contain inline HTML tags (see below).
1084
- *
1085
- * @since 5.2.0
1086
- *
1087
- * @param array $args {
1088
- * The debug information to be added to the core information page.
1089
- *
1090
- * This is an associative multi-dimensional array, up to three levels deep. The topmost array holds the sections.
1091
- * Each section has a `$fields` associative array (see below), and each `$value` in `$fields` can be
1092
- * another associative array of name/value pairs when there is more structured data to display.
1093
- *
1094
- * @type string $label The title for this section of the debug output.
1095
- * @type string $description Optional. A description for your information section which may contain basic HTML
1096
- * markup, inline tags only as it is outputted in a paragraph.
1097
- * @type boolean $show_count Optional. If set to `true` the amount of fields will be included in the title for
1098
- * this section.
1099
- * @type boolean $private Optional. If set to `true` the section and all associated fields will be excluded
1100
- * from the copied data.
1101
- * @type array $fields {
1102
- * An associative array containing the data to be displayed.
1103
- *
1104
- * @type string $label The label for this piece of information.
1105
- * @type string $value The output that is displayed for this field. Text should be translated. Can be
1106
- * an associative array that is displayed as name/value pairs.
1107
- * @type string $debug Optional. The output that is used for this field when the user copies the data.
1108
- * It should be more concise and not translated. If not set, the content of `$value` is used.
1109
- * Note that the array keys are used as labels for the copied data.
1110
- * @type boolean $private Optional. If set to `true` the field will not be included in the copied data
1111
- * allowing you to show, for example, API keys here.
1112
- * }
1113
- * }
1114
- */
1115
- $info = apply_filters( 'debug_information', $info );
1116
-
1117
- return $info;
1118
- }
1119
-
1120
- /**
1121
- * Format the information gathered for debugging, in a manner suitable for copying to a forum or support ticket.
1122
- *
1123
- * @since 5.2.0
1124
- *
1125
- * @param array $info_array Information gathered from the `WP_Debug_Data::debug_data` function.
1126
- * @param string $type The data type to return, either 'info' or 'debug'.
1127
- * @return string The formatted data.
1128
- */
1129
- public static function format( $info_array, $type ) {
1130
- $return = "`\n";
1131
-
1132
- foreach ( $info_array as $section => $details ) {
1133
- // Skip this section if there are no fields, or the section has been declared as private.
1134
- if ( empty( $details['fields'] ) || ( isset( $details['private'] ) && $details['private'] ) ) {
1135
- continue;
1136
- }
1137
-
1138
- $section_label = 'debug' === $type ? $section : $details['label'];
1139
-
1140
- $return .= sprintf(
1141
- "### %s%s ###\n\n",
1142
- $section_label,
1143
- ( isset( $details['show_count'] ) && $details['show_count'] ? sprintf( ' (%d)', count( $details['fields'] ) ) : '' )
1144
- );
1145
-
1146
- foreach ( $details['fields'] as $field_name => $field ) {
1147
- if ( isset( $field['private'] ) && true === $field['private'] ) {
1148
- continue;
1149
- }
1150
-
1151
- if ( 'debug' === $type && isset( $field['debug'] ) ) {
1152
- $debug_data = $field['debug'];
1153
- } else {
1154
- $debug_data = $field['value'];
1155
- }
1156
-
1157
- // Can be array, one level deep only.
1158
- if ( is_array( $debug_data ) ) {
1159
- $value = '';
1160
-
1161
- foreach ( $debug_data as $sub_field_name => $sub_field_value ) {
1162
- $value .= sprintf( "\n\t%s: %s", $sub_field_name, $sub_field_value );
1163
- }
1164
- } elseif ( is_bool( $debug_data ) ) {
1165
- $value = $debug_data ? 'true' : 'false';
1166
- } elseif ( empty( $debug_data ) && '0' !== $debug_data ) {
1167
- $value = 'undefined';
1168
- } else {
1169
- $value = $debug_data;
1170
- }
1171
-
1172
- if ( 'debug' === $type ) {
1173
- $label = $field_name;
1174
- } else {
1175
- $label = $field['label'];
1176
- }
1177
-
1178
- $return .= sprintf( "%s: %s\n", $label, $value );
1179
- }
1180
-
1181
- $return .= "\n";
1182
- }
1183
-
1184
- $return .= '`';
1185
-
1186
- return $return;
1187
- }
1188
-
1189
- /**
1190
- * Fetch the total size of all the database tables for the active database user.
1191
- *
1192
- * @since 5.2.0
1193
- *
1194
- * @return int The size of the database, in bytes.
1195
- */
1196
- public static function get_database_size() {
1197
- global $wpdb;
1198
- $size = 0;
1199
- $rows = $wpdb->get_results( 'SHOW TABLE STATUS', ARRAY_A );
1200
-
1201
- if ( $wpdb->num_rows > 0 ) {
1202
- foreach ( $rows as $row ) {
1203
- $size += $row['Data_length'] + $row['Index_length'];
1204
- }
1205
- }
1206
-
1207
- return (int) $size;
1208
- }
1209
-
1210
- public static function ajax_get_sizes() {
1211
- check_ajax_referer( 'health-check-site-status-result' );
1212
-
1213
- if ( ! current_user_can( 'view_site_health_checks' ) || is_multisite() ) {
1214
- wp_send_json_error();
1215
- }
1216
-
1217
- $sizes_data = Health_Check_Debug_Data::get_sizes();
1218
- $all_sizes = array( 'raw' => 0 );
1219
-
1220
- foreach ( $sizes_data as $name => $value ) {
1221
- $name = sanitize_text_field( $name );
1222
- $data = array();
1223
-
1224
- if ( isset( $value['size'] ) ) {
1225
- if ( is_string( $value['size'] ) ) {
1226
- $data['size'] = sanitize_text_field( $value['size'] );
1227
- } else {
1228
- $data['size'] = (int) $value['size'];
1229
- }
1230
- }
1231
-
1232
- if ( isset( $value['debug'] ) ) {
1233
- if ( is_string( $value['debug'] ) ) {
1234
- $data['debug'] = sanitize_text_field( $value['debug'] );
1235
- } else {
1236
- $data['debug'] = (int) $value['debug'];
1237
- }
1238
- }
1239
-
1240
- if ( ! empty( $value['raw'] ) ) {
1241
- $data['raw'] = (int) $value['raw'];
1242
- }
1243
-
1244
- $all_sizes[ $name ] = $data;
1245
- }
1246
-
1247
- if ( isset( $all_sizes['total_size']['debug'] ) && 'not available' === $all_sizes['total_size']['debug'] ) {
1248
- wp_send_json_error( $all_sizes );
1249
- }
1250
-
1251
- wp_send_json_success( $all_sizes );
1252
- }
1253
-
1254
- /**
1255
- * Fetch the sizes of the WordPress directories: `wordpress` (ABSPATH), `plugins`, `themes`, and `uploads`.
1256
- * Intended to supplement the array returned by `WP_Debug_Data::debug_data()`.
1257
- *
1258
- * @since 5.2.0
1259
- *
1260
- * @return array The sizes of the directories, also the database size and total installation size.
1261
- */
1262
- public static function get_sizes() {
1263
- $size_db = self::get_database_size();
1264
- $upload_dir = wp_get_upload_dir();
1265
-
1266
- /*
1267
- * We will be using the PHP max execution time to prevent the size calculations
1268
- * from causing a timeout. The default value is 30 seconds, and some
1269
- * hosts do not allow you to read configuration values.
1270
- */
1271
- if ( function_exists( 'ini_get' ) ) {
1272
- $max_execution_time = ini_get( 'max_execution_time' );
1273
- }
1274
-
1275
- // The max_execution_time defaults to 0 when PHP runs from cli.
1276
- // We still want to limit it below.
1277
- if ( empty( $max_execution_time ) ) {
1278
- $max_execution_time = 30;
1279
- }
1280
-
1281
- if ( $max_execution_time > 20 ) {
1282
- // If the max_execution_time is set to lower than 20 seconds, reduce it a bit to prevent
1283
- // edge-case timeouts that may happen after the size loop has finished running.
1284
- $max_execution_time -= 2;
1285
- }
1286
-
1287
- if ( ! defined( 'WP_START_TIMESTAMP' ) ) {
1288
- global $timestart;
1289
- if ( version_compare( phpversion(), '5.4.0', '>=' ) && isset( $_SERVER['REQUEST_TIME_FLOAT'] ) ) {
1290
- define( 'WP_START_TIMESTAMP', $_SERVER['REQUEST_TIME_FLOAT'] );
1291
- } else {
1292
- define( 'WP_START_TIMESTAMP', $timestart );
1293
- }
1294
- }
1295
-
1296
- // Go through the various installation directories and calculate their sizes.
1297
- // No trailing slashes.
1298
- $paths = array(
1299
- 'wordpress_size' => untrailingslashit( ABSPATH ),
1300
- 'themes_size' => get_theme_root(),
1301
- 'plugins_size' => WP_PLUGIN_DIR,
1302
- 'uploads_size' => $upload_dir['basedir'],
1303
- );
1304
-
1305
- $exclude = $paths;
1306
- unset( $exclude['wordpress_size'] );
1307
- $exclude = array_values( $exclude );
1308
-
1309
- $size_total = 0;
1310
- $all_sizes = array();
1311
-
1312
- // Loop over all the directories we want to gather the sizes for.
1313
- foreach ( $paths as $name => $path ) {
1314
- $dir_size = null; // Default to timeout.
1315
- $results = array(
1316
- 'path' => $path,
1317
- 'raw' => 0,
1318
- );
1319
-
1320
- if ( microtime( true ) - WP_START_TIMESTAMP < $max_execution_time ) {
1321
- if ( 'wordpress_size' === $name ) {
1322
- if ( version_compare( get_bloginfo( 'version' ), '5.2.0', '<' ) ) {
1323
- $dir_size = Health_Check_Debug_Data::recurse_dirsize( $path, $exclude, $max_execution_time );
1324
- } else {
1325
- $dir_size = recurse_dirsize( $path, $exclude, $max_execution_time );
1326
- }
1327
- } else {
1328
- if ( version_compare( get_bloginfo( 'version' ), '5.2.0', '<' ) ) {
1329
- $dir_size = Health_Check_Debug_Data::recurse_dirsize( $path, null, $max_execution_time );
1330
- } else {
1331
- $dir_size = recurse_dirsize( $path, null, $max_execution_time );
1332
- }
1333
- }
1334
- }
1335
-
1336
- if ( false === $dir_size ) {
1337
- // Error reading.
1338
- $results['size'] = __( 'The size cannot be calculated. The directory is not accessible. Usually caused by invalid permissions.', 'health-check' );
1339
- $results['debug'] = 'not accessible';
1340
-
1341
- // Stop total size calculation.
1342
- $size_total = null;
1343
- } elseif ( null === $dir_size ) {
1344
- // Timeout.
1345
- $results['size'] = __( 'The directory size calculation has timed out. Usually caused by a very large number of sub-directories and files.', 'health-check' );
1346
- $results['debug'] = 'timeout while calculating size';
1347
-
1348
- // Stop total size calculation.
1349
- $size_total = null;
1350
- } else {
1351
- if ( null !== $size_total ) {
1352
- $size_total += $dir_size;
1353
- }
1354
-
1355
- $results['raw'] = $dir_size;
1356
- $results['size'] = size_format( $dir_size, 2 );
1357
- $results['debug'] = $results['size'] . " ({$dir_size} bytes)";
1358
- }
1359
-
1360
- $all_sizes[ $name ] = $results;
1361
- }
1362
-
1363
- if ( $size_db > 0 ) {
1364
- $database_size = size_format( $size_db, 2 );
1365
-
1366
- $all_sizes['database_size'] = array(
1367
- 'raw' => $size_db,
1368
- 'size' => $database_size,
1369
- 'debug' => $database_size . " ({$size_db} bytes)",
1370
- );
1371
- } else {
1372
- $all_sizes['database_size'] = array(
1373
- 'size' => __( 'Not available', 'health-check' ),
1374
- 'debug' => 'not available',
1375
- );
1376
- }
1377
-
1378
- if ( null !== $size_total && $size_db > 0 ) {
1379
- $total_size = $size_total + $size_db;
1380
- $total_size_mb = size_format( $total_size, 2 );
1381
-
1382
- $all_sizes['total_size'] = array(
1383
- 'raw' => $total_size,
1384
- 'size' => $total_size_mb,
1385
- 'debug' => $total_size_mb . " ({$total_size} bytes)",
1386
- );
1387
- } else {
1388
- $all_sizes['total_size'] = array(
1389
- 'size' => __( 'Total size is not available. Some errors were encountered when determining the size of your installation.', 'health-check' ),
1390
- 'debug' => 'not available',
1391
- );
1392
- }
1393
-
1394
- return $all_sizes;
1395
- }
1396
-
1397
- /**
1398
- * Fallback function for directory size calculation on sites running WordPress <5.2
1399
- *
1400
- * @param string $directory Full path of a directory.
1401
- * @param string|array $exclude Optional. Full path of a subdirectory to exclude from the total, or array of paths.
1402
- * Expected without trailing slash(es).
1403
- * @param int $max_execution_time Maximum time to run before giving up. In seconds.
1404
- * The timeout is global and is measured from the moment WordPress started to load.
1405
- * @return int|false|null Size in bytes if a valid directory. False if not. Null if timeout.
1406
- */
1407
- static function recurse_dirsize( $directory, $exclude = null, $max_execution_time = null ) {
1408
- $size = 0;
1409
-
1410
- $directory = untrailingslashit( $directory );
1411
-
1412
- if ( ! file_exists( $directory ) || ! is_dir( $directory ) || ! is_readable( $directory ) ) {
1413
- return false;
1414
- }
1415
-
1416
- if (
1417
- ( is_string( $exclude ) && $directory === $exclude ) ||
1418
- ( is_array( $exclude ) && in_array( $directory, $exclude, true ) )
1419
- ) {
1420
- return false;
1421
- }
1422
-
1423
- if ( null === $max_execution_time ) {
1424
- // Keep the previous behavior but attempt to prevent fatal errors from timeout if possible.
1425
- if ( function_exists( 'ini_get' ) ) {
1426
- $max_execution_time = ini_get( 'max_execution_time' );
1427
- } else {
1428
- // Disable...
1429
- $max_execution_time = 0;
1430
- }
1431
-
1432
- // Leave 1 second "buffer" for other operations if $max_execution_time has reasonable value.
1433
- if ( $max_execution_time > 10 ) {
1434
- $max_execution_time -= 1;
1435
- }
1436
- }
1437
-
1438
- $handle = opendir( $directory );
1439
- if ( $handle ) {
1440
- while ( ( $file = readdir( $handle ) ) !== false ) {
1441
- $path = $directory . '/' . $file;
1442
- if ( '.' != $file && '..' != $file ) {
1443
- if ( is_file( $path ) ) {
1444
- $size += filesize( $path );
1445
- } elseif ( is_dir( $path ) ) {
1446
- $handlesize = Health_Check_Debug_Data::recurse_dirsize( $path, $exclude, $max_execution_time );
1447
- if ( $handlesize > 0 ) {
1448
- $size += $handlesize;
1449
- }
1450
- }
1451
-
1452
- if ( $max_execution_time > 0 && microtime( true ) - WP_START_TIMESTAMP > $max_execution_time ) {
1453
- // Time exceeded. Give up instead of risking a fatal timeout.
1454
- $size = null;
1455
- break;
1456
- }
1457
- }
1458
- }
1459
- closedir( $handle );
1460
- }
1461
- return $size;
1462
- }
1463
- }
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Class for providing debug data based on a users WordPress environment.
4
+ *
5
+ * @package Health Check
6
+ */
7
+
8
+ // Make sure the file is not directly accessible.
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ die( 'We\'re sorry, but you can not directly access this file.' );
11
+ }
12
+
13
+ /**
14
+ * Class Health_Check_Debug_Data
15
+ */
16
+ class Health_Check_Debug_Data {
17
+
18
+ /**
19
+ * Calls all core functions to check for updates
20
+ *
21
+ * @uses wp_version_check()
22
+ * @uses wp_update_plugins()
23
+ * @uses wp_update_themes()
24
+ *
25
+ * @return void
26
+ */
27
+ static function check_for_updates() {
28
+
29
+ wp_version_check();
30
+ wp_update_plugins();
31
+ wp_update_themes();
32
+
33
+ }
34
+
35
+ /**
36
+ * Static function for generating site debug data when required.
37
+ *
38
+ * @since 5.2.0
39
+ *
40
+ * @throws ImagickException
41
+ * @global wpdb $wpdb WordPress database abstraction object.
42
+ *
43
+ * @return array The debug data for the site.
44
+ */
45
+ static function debug_data() {
46
+ global $wpdb, $is_apache;
47
+
48
+ // Save few function calls.
49
+ $upload_dir = wp_get_upload_dir();
50
+ $permalink_structure = get_option( 'permalink_structure' );
51
+ $is_ssl = is_ssl();
52
+ $users_can_register = get_option( 'users_can_register' );
53
+ $default_comment_status = get_option( 'default_comment_status' );
54
+ $is_multisite = is_multisite();
55
+ $core_version = get_bloginfo( 'version' );
56
+ $core_updates = get_core_updates();
57
+ $core_update_needed = '';
58
+
59
+ foreach ( $core_updates as $core => $update ) {
60
+ if ( 'upgrade' === $update->response ) {
61
+ // translators: %s: Latest WordPress version number.
62
+ $core_update_needed = ' ' . sprintf( __( '(Latest version: %s)', 'health-check' ), $update->version );
63
+ } else {
64
+ $core_update_needed = '';
65
+ }
66
+ }
67
+
68
+ // Set up the array that holds all debug information.
69
+ $info = array();
70
+
71
+ $info['wp-core'] = array(
72
+ 'label' => __( 'WordPress', 'health-check' ),
73
+ 'fields' => array(
74
+ 'version' => array(
75
+ 'label' => __( 'Version', 'health-check' ),
76
+ 'value' => $core_version . $core_update_needed,
77
+ 'debug' => $core_version,
78
+ ),
79
+ 'site_language' => array(
80
+ 'label' => __( 'Site Language', 'health-check' ),
81
+ 'value' => get_locale(),
82
+ ),
83
+ 'user_language' => array(
84
+ 'label' => __( 'User Language', 'health-check' ),
85
+ 'value' => get_user_locale(),
86
+ ),
87
+ 'home_url' => array(
88
+ 'label' => __( 'Home URL', 'health-check' ),
89
+ 'value' => get_bloginfo( 'url' ),
90
+ 'private' => true,
91
+ ),
92
+ 'site_url' => array(
93
+ 'label' => __( 'Site URL', 'health-check' ),
94
+ 'value' => get_bloginfo( 'wpurl' ),
95
+ 'private' => true,
96
+ ),
97
+ 'permalink' => array(
98
+ 'label' => __( 'Permalink structure', 'health-check' ),
99
+ 'value' => $permalink_structure ? $permalink_structure : __( 'No permalink structure set', 'health-check' ),
100
+ 'debug' => $permalink_structure,
101
+ ),
102
+ 'https_status' => array(
103
+ 'label' => __( 'Is this site using HTTPS?', 'health-check' ),
104
+ 'value' => $is_ssl ? __( 'Yes', 'health-check' ) : __( 'No', 'health-check' ),
105
+ 'debug' => $is_ssl,
106
+ ),
107
+ 'user_registration' => array(
108
+ 'label' => __( 'Can anyone register on this site?', 'health-check' ),
109
+ 'value' => $users_can_register ? __( 'Yes', 'health-check' ) : __( 'No', 'health-check' ),
110
+ 'debug' => $users_can_register,
111
+ ),
112
+ 'default_comment_status' => array(
113
+ 'label' => __( 'Default comment status', 'health-check' ),
114
+ 'value' => 'open' === $default_comment_status ? _x( 'Open', 'comment status', 'health-check' ) : _x( 'Closed', 'comment status', 'health-check' ),
115
+ 'debug' => $default_comment_status,
116
+ ),
117
+ 'multisite' => array(
118
+ 'label' => __( 'Is this a multisite?', 'health-check' ),
119
+ 'value' => $is_multisite ? __( 'Yes', 'health-check' ) : __( 'No', 'health-check' ),
120
+ 'debug' => $is_multisite,
121
+ ),
122
+ ),
123
+ );
124
+
125
+ if ( ! $is_multisite ) {
126
+ $info['wp-paths-sizes'] = array(
127
+ 'label' => __( 'Directories and Sizes', 'health-check' ),
128
+ 'fields' => array(),
129
+ );
130
+ }
131
+
132
+ $info['wp-dropins'] = array(
133
+ 'label' => __( 'Drop-ins', 'health-check' ),
134
+ 'show_count' => true,
135
+ 'description' => __( 'Drop-ins are single files that replace or enhance WordPress features in ways that are not possible for traditional plugins.', 'health-check' ),
136
+ 'fields' => array(),
137
+ );
138
+
139
+ $info['wp-active-theme'] = array(
140
+ 'label' => __( 'Active Theme', 'health-check' ),
141
+ 'fields' => array(),
142
+ );
143
+
144
+ $info['wp-parent-theme'] = array(
145
+ 'label' => __( 'Parent Theme', 'health-check' ),
146
+ 'fields' => array(),
147
+ );
148
+
149
+ $info['wp-themes-inactive'] = array(
150
+ 'label' => __( 'Inactive Themes', 'health-check' ),
151
+ 'show_count' => true,
152
+ 'fields' => array(),
153
+ );
154
+
155
+ $info['wp-mu-plugins'] = array(
156
+ 'label' => __( 'Must Use Plugins', 'health-check' ),
157
+ 'show_count' => true,
158
+ 'fields' => array(),
159
+ );
160
+
161
+ $info['wp-plugins-active'] = array(
162
+ 'label' => __( 'Active Plugins', 'health-check' ),
163
+ 'show_count' => true,
164
+ 'fields' => array(),
165
+ );
166
+
167
+ $info['wp-plugins-inactive'] = array(
168
+ 'label' => __( 'Inactive Plugins', 'health-check' ),
169
+ 'show_count' => true,
170
+ 'fields' => array(),
171
+ );
172
+
173
+ $info['wp-media'] = array(
174
+ 'label' => __( 'Media Handling', 'health-check' ),
175
+ 'fields' => array(),
176
+ );
177
+
178
+ $info['wp-server'] = array(
179
+ 'label' => __( 'Server', 'health-check' ),
180
+ 'description' => __( 'The options shown below relate to your server setup. If changes are required, you may need your web host&#8217;s assistance.', 'health-check' ),
181
+ 'fields' => array(),
182
+ );
183
+
184
+ $info['wp-database'] = array(
185
+ 'label' => __( 'Database', 'health-check' ),
186
+ 'fields' => array(),
187
+ );
188
+
189
+ // Check if WP_DEBUG_LOG is set.
190
+ $wp_debug_log_value = __( 'Disabled', 'health-check' );
191
+
192
+ if ( is_string( WP_DEBUG_LOG ) ) {
193
+ $wp_debug_log_value = WP_DEBUG_LOG;
194
+ } elseif ( WP_DEBUG_LOG ) {
195
+ $wp_debug_log_value = __( 'Enabled', 'health-check' );
196
+ }
197
+
198
+ // Check CONCATENATE_SCRIPTS.
199
+ if ( defined( 'CONCATENATE_SCRIPTS' ) ) {
200
+ $concatenate_scripts = CONCATENATE_SCRIPTS ? __( 'Enabled', 'health-check' ) : __( 'Disabled', 'health-check' );
201
+ $concatenate_scripts_debug = CONCATENATE_SCRIPTS ? 'true' : 'false';
202
+ } else {
203
+ $concatenate_scripts = __( 'Undefined', 'health-check' );
204
+ $concatenate_scripts_debug = 'undefined';
205
+ }
206
+
207
+ // Check COMPRESS_SCRIPTS.
208
+ if ( defined( 'COMPRESS_SCRIPTS' ) ) {
209
+ $compress_scripts = COMPRESS_SCRIPTS ? __( 'Enabled', 'health-check' ) : __( 'Disabled', 'health-check' );
210
+ $compress_scripts_debug = COMPRESS_SCRIPTS ? 'true' : 'false';
211
+ } else {
212
+ $compress_scripts = __( 'Undefined', 'health-check' );
213
+ $compress_scripts_debug = 'undefined';
214
+ }
215
+
216
+ // Check COMPRESS_CSS.
217
+ if ( defined( 'COMPRESS_CSS' ) ) {
218
+ $compress_css = COMPRESS_CSS ? __( 'Enabled', 'health-check' ) : __( 'Disabled', 'health-check' );
219
+ $compress_css_debug = COMPRESS_CSS ? 'true' : 'false';
220
+ } else {
221
+ $compress_css = __( 'Undefined', 'health-check' );
222
+ $compress_css_debug = 'undefined';
223
+ }
224
+
225
+ // Check WP_LOCAL_DEV.
226
+ if ( defined( 'WP_LOCAL_DEV' ) ) {
227
+ $wp_local_dev = WP_LOCAL_DEV ? __( 'Enabled', 'health-check' ) : __( 'Disabled', 'health-check' );
228
+ $wp_local_dev_debug = WP_LOCAL_DEV ? 'true' : 'false';
229
+ } else {
230
+ $wp_local_dev = __( 'Undefined', 'health-check' );
231
+ $wp_local_dev_debug = 'undefined';
232
+ }
233
+
234
+ $info['wp-constants'] = array(
235
+ 'label' => __( 'WordPress Constants', 'health-check' ),
236
+ 'description' => __( 'These settings alter where and how parts of WordPress are loaded.', 'health-check' ),
237
+ 'fields' => array(
238
+ 'ABSPATH' => array(
239
+ 'label' => 'ABSPATH',
240
+ 'value' => ABSPATH,
241
+ 'private' => true,
242
+ ),
243
+ 'WP_HOME' => array(
244
+ 'label' => 'WP_HOME',
245
+ 'value' => ( defined( 'WP_HOME' ) ? WP_HOME : __( 'Undefined', 'health-check' ) ),
246
+ 'debug' => ( defined( 'WP_HOME' ) ? WP_HOME : 'undefined' ),
247
+ ),
248
+ 'WP_SITEURL' => array(
249
+ 'label' => 'WP_SITEURL',
250
+ 'value' => ( defined( 'WP_SITEURL' ) ? WP_SITEURL : __( 'Undefined', 'health-check' ) ),
251
+ 'debug' => ( defined( 'WP_SITEURL' ) ? WP_SITEURL : 'undefined' ),
252
+ ),
253
+ 'WP_CONTENT_DIR' => array(
254
+ 'label' => 'WP_CONTENT_DIR',
255
+ 'value' => WP_CONTENT_DIR,
256
+ ),
257
+ 'WP_PLUGIN_DIR' => array(
258
+ 'label' => 'WP_PLUGIN_DIR',
259
+ 'value' => WP_PLUGIN_DIR,
260
+ ),
261
+ 'WP_MAX_MEMORY_LIMIT' => array(
262
+ 'label' => 'WP_MAX_MEMORY_LIMIT',
263
+ 'value' => WP_MAX_MEMORY_LIMIT,
264
+ ),
265
+ 'WP_DEBUG' => array(
266
+ 'label' => 'WP_DEBUG',
267
+ 'value' => WP_DEBUG ? __( 'Enabled', 'health-check' ) : __( 'Disabled', 'health-check' ),
268
+ 'debug' => WP_DEBUG,
269
+ ),
270
+ 'WP_DEBUG_DISPLAY' => array(
271
+ 'label' => 'WP_DEBUG_DISPLAY',
272
+ 'value' => WP_DEBUG_DISPLAY ? __( 'Enabled', 'health-check' ) : __( 'Disabled', 'health-check' ),
273
+ 'debug' => WP_DEBUG_DISPLAY,
274
+ ),
275
+ 'WP_DEBUG_LOG' => array(
276
+ 'label' => 'WP_DEBUG_LOG',
277
+ 'value' => $wp_debug_log_value,
278
+ 'debug' => WP_DEBUG_LOG,
279
+ ),
280
+ 'SCRIPT_DEBUG' => array(
281
+ 'label' => 'SCRIPT_DEBUG',
282
+ 'value' => SCRIPT_DEBUG ? __( 'Enabled', 'health-check' ) : __( 'Disabled', 'health-check' ),
283
+ 'debug' => SCRIPT_DEBUG,
284
+ ),
285
+ 'WP_CACHE' => array(
286
+ 'label' => 'WP_CACHE',
287
+ 'value' => WP_CACHE ? __( 'Enabled', 'health-check' ) : __( 'Disabled', 'health-check' ),
288
+ 'debug' => WP_CACHE,
289
+ ),
290
+ 'CONCATENATE_SCRIPTS' => array(
291
+ 'label' => 'CONCATENATE_SCRIPTS',
292
+ 'value' => $concatenate_scripts,
293
+ 'debug' => $concatenate_scripts_debug,
294
+ ),
295
+ 'COMPRESS_SCRIPTS' => array(
296
+ 'label' => 'COMPRESS_SCRIPTS',
297
+ 'value' => $compress_scripts,
298
+ 'debug' => $compress_scripts_debug,
299
+ ),
300
+ 'COMPRESS_CSS' => array(
301
+ 'label' => 'COMPRESS_CSS',
302
+ 'value' => $compress_css,
303
+ 'debug' => $compress_css_debug,
304
+ ),
305
+ 'WP_LOCAL_DEV' => array(
306
+ 'label' => 'WP_LOCAL_DEV',
307
+ 'value' => $wp_local_dev,
308
+ 'debug' => $wp_local_dev_debug,
309
+ ),
310
+ ),
311
+ );
312
+
313
+ $is_writable_abspath = wp_is_writable( ABSPATH );
314
+ $is_writable_wp_content_dir = wp_is_writable( WP_CONTENT_DIR );
315
+ $is_writable_upload_dir = wp_is_writable( $upload_dir['basedir'] );
316
+ $is_writable_wp_plugin_dir = wp_is_writable( WP_PLUGIN_DIR );
317
+ $is_writable_template_directory = wp_is_writable( get_template_directory() . '/..' );
318
+
319
+ $info['wp-filesystem'] = array(
320
+ 'label' => __( 'Filesystem Permissions', 'health-check' ),
321
+ 'description' => __( 'Shows whether WordPress is able to write to the directories it needs access to.', 'health-check' ),
322
+ 'fields' => array(
323
+ 'wordpress' => array(
324
+ 'label' => __( 'The main WordPress directory', 'health-check' ),
325
+ 'value' => ( $is_writable_abspath ? __( 'Writable', 'health-check' ) : __( 'Not writable', 'health-check' ) ),
326
+ 'debug' => ( $is_writable_abspath ? 'writable' : 'not writable' ),
327
+ ),
328
+ 'wp-content' => array(
329
+ 'label' => __( 'The wp-content directory', 'health-check' ),
330
+ 'value' => ( $is_writable_wp_content_dir ? __( 'Writable', 'health-check' ) : __( 'Not writable', 'health-check' ) ),
331
+ 'debug' => ( $is_writable_wp_content_dir ? 'writable' : 'not writable' ),
332
+ ),
333
+ 'uploads' => array(
334
+ 'label' => __( 'The uploads directory', 'health-check' ),
335
+ 'value' => ( $is_writable_upload_dir ? __( 'Writable', 'health-check' ) : __( 'Not writable', 'health-check' ) ),
336
+ 'debug' => ( $is_writable_upload_dir ? 'writable' : 'not writable' ),
337
+ ),
338
+ 'plugins' => array(
339
+ 'label' => __( 'The plugins directory', 'health-check' ),
340
+ 'value' => ( $is_writable_wp_plugin_dir ? __( 'Writable', 'health-check' ) : __( 'Not writable', 'health-check' ) ),
341
+ 'debug' => ( $is_writable_wp_plugin_dir ? 'writable' : 'not writable' ),
342
+ ),
343
+ 'themes' => array(
344
+ 'label' => __( 'The themes directory', 'health-check' ),
345
+ 'value' => ( $is_writable_template_directory ? __( 'Writable', 'health-check' ) : __( 'Not writable', 'health-check' ) ),
346
+ 'debug' => ( $is_writable_template_directory ? 'writable' : 'not writable' ),
347
+ ),
348
+ ),
349
+ );
350
+
351
+ // Conditionally add debug information for multisite setups.
352
+ if ( is_multisite() ) {
353
+ $network_query = new WP_Network_Query();
354
+ $network_ids = $network_query->query(
355
+ array(
356
+ 'fields' => 'ids',
357
+ 'number' => 100,
358
+ 'no_found_rows' => false,
359
+ )
360
+ );
361
+
362
+ $site_count = 0;
363
+ foreach ( $network_ids as $network_id ) {
364
+ $site_count += get_blog_count( $network_id );
365
+ }
366
+
367
+ $info['wp-core']['fields']['user_count'] = array(
368
+ 'label' => __( 'User count', 'health-check' ),
369
+ 'value' => get_user_count(),
370
+ );
371
+
372
+ $info['wp-core']['fields']['site_count'] = array(
373
+ 'label' => __( 'Site count', 'health-check' ),
374
+ 'value' => $site_count,
375
+ );
376
+
377
+ $info['wp-core']['fields']['network_count'] = array(
378
+ 'label' => __( 'Network count', 'health-check' ),
379
+ 'value' => $network_query->found_networks,
380
+ );
381
+ } else {
382
+ $user_count = count_users();
383
+
384
+ $info['wp-core']['fields']['user_count'] = array(
385
+ 'label' => __( 'User count', 'health-check' ),
386
+ 'value' => $user_count['total_users'],
387
+ );
388
+ }
389
+
390
+ // WordPress features requiring processing.
391
+ $wp_dotorg = wp_remote_get( 'https://api.wordpress.org', array( 'timeout' => 10 ) );
392
+
393
+ if ( ! is_wp_error( $wp_dotorg ) ) {
394
+ $info['wp-core']['fields']['dotorg_communication'] = array(
395
+ 'label' => __( 'Communication with WordPress.org', 'health-check' ),
396
+ 'value' => __( 'WordPress.org is reachable', 'health-check' ),
397
+ 'debug' => 'true',
398
+ );
399
+ } else {
400
+ $info['wp-core']['fields']['dotorg_communication'] = array(
401
+ 'label' => __( 'Communication with WordPress.org', 'health-check' ),
402
+ 'value' => sprintf(
403
+ // translators: 1: The IP address WordPress.org resolves to. 2: The error returned by the lookup.
404
+ __( 'Unable to reach WordPress.org at %1$s: %2$s', 'health-check' ),
405
+ gethostbyname( 'api.wordpress.org' ),
406
+ $wp_dotorg->get_error_message()
407
+ ),
408
+ 'debug' => $wp_dotorg->get_error_message(),
409
+ );
410
+ }
411
+
412
+ // Remove accordion for Directories and Sizes if in Multisite.
413
+ if ( ! $is_multisite ) {
414
+ $loading = __( 'Loading&hellip;', 'health-check' );
415
+
416
+ $info['wp-paths-sizes']['fields'] = array(
417
+ 'wordpress_path' => array(
418
+ 'label' => __( 'WordPress directory location', 'health-check' ),
419
+ 'value' => untrailingslashit( ABSPATH ),
420
+ ),
421
+ 'wordpress_size' => array(
422
+ 'label' => __( 'WordPress directory size', 'health-check' ),
423
+ 'value' => $loading,
424
+ 'debug' => 'loading...',
425
+ ),
426
+ 'uploads_path' => array(
427
+ 'label' => __( 'Uploads directory location', 'health-check' ),
428
+ 'value' => $upload_dir['basedir'],
429
+ ),
430
+ 'uploads_size' => array(
431
+ 'label' => __( 'Uploads directory size', 'health-check' ),
432
+ 'value' => $loading,
433
+ 'debug' => 'loading...',
434
+ ),
435
+ 'themes_path' => array(
436
+ 'label' => __( 'Themes directory location', 'health-check' ),
437
+ 'value' => get_theme_root(),
438
+ ),
439
+ 'themes_size' => array(
440
+ 'label' => __( 'Themes directory size', 'health-check' ),
441
+ 'value' => $loading,
442
+ 'debug' => 'loading...',
443
+ ),
444
+ 'plugins_path' => array(
445
+ 'label' => __( 'Plugins directory location', 'health-check' ),
446
+ 'value' => WP_PLUGIN_DIR,
447
+ ),
448
+ 'plugins_size' => array(
449
+ 'label' => __( 'Plugins directory size', 'health-check' ),
450
+ 'value' => $loading,
451
+ 'debug' => 'loading...',
452
+ ),
453
+ 'database_size' => array(
454
+ 'label' => __( 'Database size', 'health-check' ),
455
+ 'value' => $loading,
456
+ 'debug' => 'loading...',
457
+ ),
458
+ 'total_size' => array(
459
+ 'label' => __( 'Total installation size', 'health-check' ),
460
+ 'value' => $loading,
461
+ 'debug' => 'loading...',
462
+ ),
463
+ );
464
+ }
465
+
466
+ // Get a list of all drop-in replacements.
467
+ $dropins = get_dropins();
468
+
469
+ // Get dropins descriptions.
470
+ $dropin_descriptions = _get_dropins();
471
+
472
+ // Spare few function calls.
473
+ $not_available = __( 'Not available', 'health-check' );
474
+
475
+ foreach ( $dropins as $dropin_key => $dropin ) {
476
+ $info['wp-dropins']['fields'][ sanitize_text_field( $dropin_key ) ] = array(
477
+ 'label' => $dropin_key,
478
+ 'value' => $dropin_descriptions[ $dropin_key ][0],
479
+ 'debug' => 'true',
480
+ );
481
+ }
482
+
483
+ // Populate the media fields.
484
+ $info['wp-media']['fields']['image_editor'] = array(
485
+ 'label' => __( 'Active editor', 'health-check' ),
486
+ 'value' => _wp_image_editor_choose(),
487
+ );
488
+
489
+ // Get ImageMagic information, if available.
490
+ if ( class_exists( 'Imagick' ) ) {
491
+ // Save the Imagick instance for later use.
492
+ $imagick = new Imagick();
493
+ $imagick_version = $imagick->getVersion();
494
+ } else {
495
+ $imagick_version = __( 'Not available', 'health-check' );
496
+ }
497
+
498
+ $info['wp-media']['fields']['imagick_module_version'] = array(
499
+ 'label' => __( 'ImageMagick version number', 'health-check' ),
500
+ 'value' => ( is_array( $imagick_version ) ? $imagick_version['versionNumber'] : $imagick_version ),
501
+ );
502
+
503
+ $info['wp-media']['fields']['imagemagick_version'] = array(
504
+ 'label' => __( 'ImageMagick version string', 'health-check' ),
505
+ 'value' => ( is_array( $imagick_version ) ? $imagick_version['versionString'] : $imagick_version ),
506
+ );
507
+
508
+ // If Imagick is used as our editor, provide some more information about its limitations.
509
+ if ( 'WP_Image_Editor_Imagick' === _wp_image_editor_choose() && isset( $imagick ) && $imagick instanceof Imagick ) {
510
+ $limits = array(
511
+ 'area' => ( defined( 'imagick::RESOURCETYPE_AREA' ) ? size_format( $imagick->getResourceLimit( imagick::RESOURCETYPE_AREA ) ) : $not_available ),
512
+ 'disk' => ( defined( 'imagick::RESOURCETYPE_DISK' ) ? $imagick->getResourceLimit( imagick::RESOURCETYPE_DISK ) : $not_available ),
513
+ 'file' => ( defined( 'imagick::RESOURCETYPE_FILE' ) ? $imagick->getResourceLimit( imagick::RESOURCETYPE_FILE ) : $not_available ),
514
+ 'map' => ( defined( 'imagick::RESOURCETYPE_MAP' ) ? size_format( $imagick->getResourceLimit( imagick::RESOURCETYPE_MAP ) ) : $not_available ),
515
+ 'memory' => ( defined( 'imagick::RESOURCETYPE_MEMORY' ) ? size_format( $imagick->getResourceLimit( imagick::RESOURCETYPE_MEMORY ) ) : $not_available ),
516
+ 'thread' => ( defined( 'imagick::RESOURCETYPE_THREAD' ) ? $imagick->getResourceLimit( imagick::RESOURCETYPE_THREAD ) : $not_available ),
517
+ );
518
+
519
+ $limits_debug = array(
520
+ 'imagick::RESOURCETYPE_AREA' => ( defined( 'imagick::RESOURCETYPE_AREA' ) ? size_format( $imagick->getResourceLimit( imagick::RESOURCETYPE_AREA ) ) : 'not available' ),
521
+ 'imagick::RESOURCETYPE_DISK' => ( defined( 'imagick::RESOURCETYPE_DISK' ) ? $imagick->getResourceLimit( imagick::RESOURCETYPE_DISK ) : 'not available' ),
522
+ 'imagick::RESOURCETYPE_FILE' => ( defined( 'imagick::RESOURCETYPE_FILE' ) ? $imagick->getResourceLimit( imagick::RESOURCETYPE_FILE ) : 'not available' ),
523
+ 'imagick::RESOURCETYPE_MAP' => ( defined( 'imagick::RESOURCETYPE_MAP' ) ? size_format( $imagick->getResourceLimit( imagick::RESOURCETYPE_MAP ) ) : 'not available' ),
524
+ 'imagick::RESOURCETYPE_MEMORY' => ( defined( 'imagick::RESOURCETYPE_MEMORY' ) ? size_format( $imagick->getResourceLimit( imagick::RESOURCETYPE_MEMORY ) ) : 'not available' ),
525
+ 'imagick::RESOURCETYPE_THREAD' => ( defined( 'imagick::RESOURCETYPE_THREAD' ) ? $imagick->getResourceLimit( imagick::RESOURCETYPE_THREAD ) : 'not available' ),
526
+ );
527
+
528
+ $info['wp-media']['fields']['imagick_limits'] = array(
529
+ 'label' => __( 'Imagick Resource Limits', 'health-check' ),
530
+ 'value' => $limits,
531
+ 'debug' => $limits_debug,
532
+ );
533
+ }
534
+
535
+ // Get GD information, if available.
536
+ if ( function_exists( 'gd_info' ) ) {
537
+ $gd = gd_info();
538
+ } else {
539
+ $gd = false;
540
+ }
541
+
542
+ $info['wp-media']['fields']['gd_version'] = array(
543
+ 'label' => __( 'GD version', 'health-check' ),
544
+ 'value' => ( is_array( $gd ) ? $gd['GD Version'] : $not_available ),
545
+ 'debug' => ( is_array( $gd ) ? $gd['GD Version'] : 'not available' ),
546
+ );
547
+
548
+ // Get Ghostscript information, if available.
549
+ if ( function_exists( 'exec' ) ) {
550
+ $gs = exec( 'gs --version' );
551
+
552
+ if ( empty( $gs ) ) {
553
+ $gs = $not_available;
554
+ $gs_debug = 'not available';
555
+ } else {
556
+ $gs_debug = $gs;
557
+ }
558
+ } else {
559
+ $gs = __( 'Unable to determine if Ghostscript is installed', 'health-check' );
560
+ $gs_debug = 'unknown';
561
+ }
562
+
563
+ $info['wp-media']['fields']['ghostscript_version'] = array(
564
+ 'label' => __( 'Ghostscript version', 'health-check' ),
565
+ 'value' => $gs,
566
+ 'debug' => $gs_debug,
567
+ );
568
+
569
+ // Populate the server debug fields.
570
+ if ( function_exists( 'php_uname' ) ) {
571
+ $server_architecture = sprintf( '%s %s %s', php_uname( 's' ), php_uname( 'r' ), php_uname( 'm' ) );
572
+ } else {
573
+ $server_architecture = 'unknown';
574
+ }
575
+
576
+ if ( function_exists( 'phpversion' ) ) {
577
+ $php_version_debug = phpversion();
578
+ // Whether PHP supports 64bit
579
+ $php64bit = ( PHP_INT_SIZE * 8 === 64 );
580
+
581
+ $php_version = sprintf(
582
+ '%s %s',
583
+ $php_version_debug,
584
+ ( $php64bit ? __( '(Supports 64bit values)', 'health-check' ) : __( '(Does not support 64bit values)', 'health-check' ) )
585
+ );
586
+
587
+ if ( $php64bit ) {
588
+ $php_version_debug .= ' 64bit';
589
+ }
590
+ } else {
591
+ $php_version = __( 'Unable to determine PHP version', 'health-check' );
592
+ $php_version_debug = 'unknown';
593
+ }
594
+
595
+ if ( function_exists( 'php_sapi_name' ) ) {
596
+ $php_sapi = php_sapi_name();
597
+ } else {
598
+ $php_sapi = 'unknown';
599
+ }
600
+
601
+ if ( function_exists( 'get_current_user' ) && function_exists( 'getmyuid' ) ) {
602
+ $php_getuid = sprintf(
603
+ '%s (%s)',
604
+ get_current_user(),
605
+ getmyuid()
606
+ );
607
+ } else {
608
+ $php_getuid = 'unknown';
609
+ }
610
+
611
+ $info['wp-server']['fields']['server_architecture'] = array(
612
+ 'label' => __( 'Server architecture', 'health-check' ),
613
+ 'value' => ( 'unknown' !== $server_architecture ? $server_architecture : __( 'Unable to determine server architecture', 'health-check' ) ),
614
+ 'debug' => $server_architecture,
615
+ );
616
+ $info['wp-server']['fields']['php-uid'] = array(
617
+ 'label' => __( 'Website server user', 'health-check' ),
618
+ 'value' => ( 'unknown' !== $php_getuid ? $php_getuid : __( 'Unable to determine the websites server user', 'health-check' ) ),
619
+ 'debug' => $php_getuid,
620
+ 'private' => true,
621
+ );
622
+ $info['wp-server']['fields']['httpd_software'] = array(
623
+ 'label' => __( 'Web server', 'health-check' ),
624
+ 'value' => ( isset( $_SERVER['SERVER_SOFTWARE'] ) ? $_SERVER['SERVER_SOFTWARE'] : __( 'Unable to determine what web server software is used', 'health-check' ) ),
625
+ 'debug' => ( isset( $_SERVER['SERVER_SOFTWARE'] ) ? $_SERVER['SERVER_SOFTWARE'] : 'unknown' ),
626
+ );
627
+ $info['wp-server']['fields']['php_version'] = array(
628
+ 'label' => __( 'PHP version', 'health-check' ),
629
+ 'value' => $php_version,
630
+ 'debug' => $php_version_debug,
631
+ );
632
+ $info['wp-server']['fields']['php_sapi'] = array(
633
+ 'label' => __( 'PHP SAPI', 'health-check' ),
634
+ 'value' => ( 'unknown' !== $php_sapi ? $php_sapi : __( 'Unable to determine PHP SAPI', 'health-check' ) ),
635
+ 'debug' => $php_sapi,
636
+ );
637
+
638
+ // Some servers disable `ini_set()` and `ini_get()`, we check this before trying to get configuration values.
639
+ if ( ! function_exists( 'ini_get' ) ) {
640
+ $info['wp-server']['fields']['ini_get'] = array(
641
+ 'label' => __( 'Server settings', 'health-check' ),
642
+ 'value' => __( 'Unable to determine some settings, as the ini_get() function has been disabled.', 'health-check' ),
643
+ 'debug' => 'ini_get() is disabled',
644
+ );
645
+ } else {
646
+ $info['wp-server']['fields']['max_input_variables'] = array(
647
+ 'label' => __( 'PHP max input variables', 'health-check' ),
648
+ 'value' => ini_get( 'max_input_vars' ),
649
+ );
650
+ $info['wp-server']['fields']['time_limit'] = array(
651
+ 'label' => __( 'PHP time limit', 'health-check' ),
652
+ 'value' => ini_get( 'max_execution_time' ),
653
+ );
654
+ $info['wp-server']['fields']['memory_limit'] = array(
655
+ 'label' => __( 'PHP memory limit', 'health-check' ),
656
+ 'value' => ini_get( 'memory_limit' ),
657
+ );
658
+ $info['wp-server']['fields']['max_input_time'] = array(
659
+ 'label' => __( 'Max input time', 'health-check' ),
660
+ 'value' => ini_get( 'max_input_time' ),
661
+ );
662
+ $info['wp-server']['fields']['upload_max_size'] = array(
663
+ 'label' => __( 'Upload max filesize', 'health-check' ),
664
+ 'value' => ini_get( 'upload_max_filesize' ),
665
+ );
666
+ $info['wp-server']['fields']['php_post_max_size'] = array(
667
+ 'label' => __( 'PHP post max size', 'health-check' ),
668
+ 'value' => ini_get( 'post_max_size' ),
669
+ );
670
+ }
671
+
672
+ if ( function_exists( 'curl_version' ) ) {
673
+ $curl = curl_version();
674
+
675
+ $info['wp-server']['fields']['curl_version'] = array(
676
+ 'label' => __( 'cURL version', 'health-check' ),
677
+ 'value' => sprintf( '%s %s', $curl['version'], $curl['ssl_version'] ),
678
+ );
679
+ } else {
680
+ $info['wp-server']['fields']['curl_version'] = array(
681
+ 'label' => __( 'cURL version', 'health-check' ),
682
+ 'value' => $not_available,
683
+ 'debug' => 'not available',
684
+ );
685
+ }
686
+
687
+ // SUHOSIN
688
+ $suhosin_loaded = ( extension_loaded( 'suhosin' ) || ( defined( 'SUHOSIN_PATCH' ) && constant( 'SUHOSIN_PATCH' ) ) );
689
+
690
+ $info['wp-server']['fields']['suhosin'] = array(
691
+ 'label' => __( 'Is SUHOSIN installed?', 'health-check' ),
692
+ 'value' => ( $suhosin_loaded ? __( 'Yes', 'health-check' ) : __( 'No', 'health-check' ) ),
693
+ 'debug' => $suhosin_loaded,
694
+ );
695
+
696
+ // Imagick
697
+ $imagick_loaded = extension_loaded( 'imagick' );
698
+
699
+ $info['wp-server']['fields']['imagick_availability'] = array(
700
+ 'label' => __( 'Is the Imagick library available?', 'health-check' ),
701
+ 'value' => ( $imagick_loaded ? __( 'Yes', 'health-check' ) : __( 'No', 'health-check' ) ),
702
+ 'debug' => $imagick_loaded,
703
+ );
704
+
705
+ $cookies = wp_unslash( $_COOKIE );
706
+ $timeout = 10;
707
+ $headers = array(
708
+ 'Cache-Control' => 'no-cache',
709
+ 'X-WP-Nonce' => wp_create_nonce( 'wp_rest' ),
710
+ );
711
+ if ( isset( $_SERVER['PHP_AUTH_USER'] ) && isset( $_SERVER['PHP_AUTH_PW'] ) ) {
712
+ $headers['Authorization'] = 'Basic ' . base64_encode( wp_unslash( $_SERVER['PHP_AUTH_USER'] ) . ':' . wp_unslash( $_SERVER['PHP_AUTH_PW'] ) );
713
+ }
714
+
715
+ $server_request = wp_remote_get( site_url(), compact( 'cookies', 'headers', 'timeout' ) );
716
+ if ( is_wp_error( $server_request ) ) {
717
+ $info['wp-server']['fields']['server-headers'] = array(
718
+ 'label' => __( 'Server headers', 'health-check' ),
719
+ 'value' => __( 'Could not retrieve server headers', 'health-check' ),
720
+ 'debug' => 'unknown',
721
+ );
722
+ } else {
723
+ $server_headers = wp_remote_retrieve_headers( $server_request );
724
+
725
+ $info['wp-server']['fields']['server-headers'] = array(
726
+ 'label' => __( 'Server headers', 'health-check' ),
727
+ 'value' => ( $server_headers instanceof \Requests_Utility_CaseInsensitiveDictionary ? $server_headers->getAll() : $server_headers ),
728
+ 'debug' => ( $server_headers instanceof \Requests_Utility_CaseInsensitiveDictionary ? $server_headers->getAll() : $server_headers ),
729
+ );
730
+ }
731
+
732
+ // Check if a .htaccess file exists.
733
+ if ( $is_apache && is_file( ABSPATH . '.htaccess' ) ) {
734
+ // If the file exists, grab the content of it.
735
+ $htaccess_content = file_get_contents( ABSPATH . '.htaccess' );
736
+
737
+ // Filter away the core WordPress rules.
738
+ $filtered_htaccess_content = trim( preg_replace( '/\# BEGIN WordPress[\s\S]+?# END WordPress/si', '', $htaccess_content ) );
739
+ $filtered_htaccess_content = ! empty( $filtered_htaccess_content );
740
+
741
+ $info['wp-server']['fields']['htaccess_extra_rules'] = array(
742
+ 'label' => __( '.htaccess rules', 'health-check' ),
743
+ 'value' => ( $filtered_htaccess_content ? __( 'Custom rules have been added to your .htaccess file.', 'health-check' ) : __( 'Your .htaccess file contains only core WordPress features.', 'health-check' ) ),
744
+ 'debug' => $filtered_htaccess_content,
745
+ );
746
+ }
747
+
748
+ // Populate the database debug fields.
749
+ if ( is_resource( $wpdb->dbh ) ) {
750
+ // Old mysql extension.
751
+ $extension = 'mysql';
752
+ } elseif ( is_object( $wpdb->dbh ) ) {
753
+ // mysqli or PDO.
754
+ $extension = get_class( $wpdb->dbh );
755
+ } else {
756
+ // Unknown sql extension.
757
+ $extension = null;
758
+ }
759
+
760
+ $server = $wpdb->get_var( 'SELECT VERSION()' );
761
+
762
+ if ( isset( $wpdb->use_mysqli ) && $wpdb->use_mysqli ) {
763
+ $client_version = $wpdb->dbh->client_info;
764
+ } else {
765
+ // phpcs:ignore WordPress.DB.RestrictedFunctions.mysql_mysql_get_client_info
766
+ if ( preg_match( '|[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}|', mysql_get_client_info(), $matches ) ) {
767
+ $client_version = $matches[0];
768
+ } else {
769
+ $client_version = null;
770
+ }
771
+ }
772
+
773
+ $info['wp-database']['fields']['extension'] = array(
774
+ 'label' => __( 'Extension', 'health-check' ),
775
+ 'value' => $extension,
776
+ );
777
+
778
+ $info['wp-database']['fields']['server_version'] = array(
779
+ 'label' => __( 'Server version', 'health-check' ),
780
+ 'value' => $server,
781
+ );
782
+
783
+ $info['wp-database']['fields']['client_version'] = array(
784
+ 'label' => __( 'Client version', 'health-check' ),
785
+ 'value' => $client_version,
786
+ );
787
+
788
+ $info['wp-database']['fields']['database_user'] = array(
789
+ 'label' => __( 'Database user', 'health-check' ),
790
+ 'value' => $wpdb->dbuser,
791
+ 'private' => true,
792
+ );
793
+
794
+ $info['wp-database']['fields']['database_host'] = array(
795
+ 'label' => __( 'Database host', 'health-check' ),
796
+ 'value' => $wpdb->dbhost,
797
+ 'private' => true,
798
+ );
799
+
800
+ $info['wp-database']['fields']['database_name'] = array(
801
+ 'label' => __( 'Database name', 'health-check' ),
802
+ 'value' => $wpdb->dbname,
803
+ 'private' => true,
804
+ );
805
+
806
+ $info['wp-database']['fields']['database_prefix'] = array(
807
+ 'label' => __( 'Database prefix', 'health-check' ),
808
+ 'value' => $wpdb->prefix,
809
+ 'private' => true,
810
+ );
811
+
812
+ // List must use plugins if there are any.
813
+ $mu_plugins = get_mu_plugins();
814
+
815
+ foreach ( $mu_plugins as $plugin_path => $plugin ) {
816
+ $plugin_version = $plugin['Version'];
817
+ $plugin_author = $plugin['Author'];
818
+
819
+ $plugin_version_string = __( 'No version or author information is available.', 'health-check' );
820
+ $plugin_version_string_debug = 'author: (undefined), version: (undefined)';
821
+
822
+ if ( ! empty( $plugin_version ) && ! empty( $plugin_author ) ) {
823
+ // translators: 1: Plugin version number. 2: Plugin author name.
824
+ $plugin_version_string = sprintf( __( 'Version %1$s by %2$s', 'health-check' ), $plugin_version, $plugin_author );
825
+ $plugin_version_string_debug = sprintf( 'version: %s, author: %s', $plugin_version, $plugin_author );
826
+ } else {
827
+ if ( ! empty( $plugin_author ) ) {
828
+ // translators: %s: Plugin author name.
829
+ $plugin_version_string = sprintf( __( 'By %s', 'health-check' ), $plugin_author );
830
+ $plugin_version_string_debug = sprintf( 'author: %s, version: (undefined)', $plugin_author );
831
+ }
832
+
833
+ if ( ! empty( $plugin_version ) ) {
834
+ // translators: %s: Plugin version number.
835
+ $plugin_version_string = sprintf( __( 'Version %s', 'health-check' ), $plugin_version );
836
+ $plugin_version_string_debug = sprintf( 'author: (undefined), version: %s', $plugin_version );
837
+ }
838
+ }
839
+
840
+ $info['wp-mu-plugins']['fields'][ sanitize_text_field( $plugin['Name'] ) ] = array(
841
+ 'label' => $plugin['Name'],
842
+ 'value' => $plugin_version_string,
843
+ 'debug' => $plugin_version_string_debug,
844
+ );
845
+ }
846
+
847
+ // List all available plugins.
848
+ $plugins = get_plugins();
849
+ $plugin_updates = get_plugin_updates();
850
+
851
+ foreach ( $plugins as $plugin_path => $plugin ) {
852
+ $plugin_part = ( is_plugin_active( $plugin_path ) ) ? 'wp-plugins-active' : 'wp-plugins-inactive';
853
+
854
+ $plugin_version = $plugin['Version'];
855
+ $plugin_author = $plugin['Author'];
856
+
857
+ $plugin_version_string = __( 'No version or author information is available.', 'health-check' );
858
+ $plugin_version_string_debug = 'author: (undefined), version: (undefined)';
859
+
860
+ if ( ! empty( $plugin_version ) && ! empty( $plugin_author ) ) {
861
+ // translators: 1: Plugin version number. 2: Plugin author name.
862
+ $plugin_version_string = sprintf( __( 'Version %1$s by %2$s', 'health-check' ), $plugin_version, $plugin_author );
863
+ $plugin_version_string_debug = sprintf( 'version: %s, author: %s', $plugin_version, $plugin_author );
864
+ } else {
865
+ if ( ! empty( $plugin_author ) ) {
866
+ // translators: %s: Plugin author name.
867
+ $plugin_version_string = sprintf( __( 'By %s', 'health-check' ), $plugin_author );
868
+ $plugin_version_string_debug = sprintf( 'author: %s, version: (undefined)', $plugin_author );
869
+ }
870
+
871
+ if ( ! empty( $plugin_version ) ) {
872
+ // translators: %s: Plugin version number.
873
+ $plugin_version_string = sprintf( __( 'Version %s', 'health-check' ), $plugin_version );
874
+ $plugin_version_string_debug = sprintf( 'author: (undefined), version: %s', $plugin_version );
875
+ }
876
+ }
877
+
878
+ if ( array_key_exists( $plugin_path, $plugin_updates ) ) {
879
+ // translators: %s: Latest plugin version number.
880
+ $plugin_version_string .= ' ' . sprintf( __( '(Latest version: %s)', 'health-check' ), $plugin_updates[ $plugin_path ]->update->new_version );
881
+ $plugin_version_string_debug .= sprintf( ' (latest version: %s)', $plugin_updates[ $plugin_path ]->update->new_version );
882
+ }
883
+
884
+ $info[ $plugin_part ]['fields'][ sanitize_text_field( $plugin['Name'] ) ] = array(
885
+ 'label' => $plugin['Name'],
886
+ 'value' => $plugin_version_string,
887
+ 'debug' => $plugin_version_string_debug,
888
+ );
889
+ }
890
+
891
+ // Populate the section for the currently active theme.
892
+ global $_wp_theme_features;
893
+ $theme_features = array();
894
+
895
+ if ( ! empty( $_wp_theme_features ) ) {
896
+ foreach ( $_wp_theme_features as $feature => $options ) {
897
+ $theme_features[] = $feature;
898
+ }
899
+ }
900
+
901
+ $active_theme = wp_get_theme();
902
+ $theme_updates = get_theme_updates();
903
+
904
+ // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
905
+ $active_theme_version = $active_theme->Version;
906
+ $active_theme_version_debug = $active_theme_version;
907
+
908
+ if ( array_key_exists( $active_theme->stylesheet, $theme_updates ) ) {
909
+ $theme_update_new_version = $theme_updates[ $active_theme->stylesheet ]->update['new_version'];
910
+
911
+ // translators: %s: Latest theme version number.
912
+ $active_theme_version .= ' ' . sprintf( __( '(Latest version: %s)', 'health-check' ), $theme_update_new_version );
913
+ $active_theme_version_debug .= sprintf( ' (latest version: %s)', $theme_update_new_version );
914
+ }
915
+
916
+ $active_theme_author_uri = $active_theme->offsetGet( 'Author URI' );
917
+
918
+ $info['wp-active-theme']['fields'] = array(
919
+ 'name' => array(
920
+ 'label' => __( 'Name', 'health-check' ),
921
+ 'value' => sprintf(
922
+ // translators: 1: Parent theme name. 2: Parent theme slug.
923
+ __( '%1$s (%2$s)', 'health-check' ),
924
+ // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
925
+ $active_theme->Name,
926
+ $active_theme->stylesheet
927
+ ),
928
+ ),
929
+ 'version' => array(
930
+ 'label' => __( 'Version', 'health-check' ),
931
+ 'value' => $active_theme_version,
932
+ 'debug' => $active_theme_version_debug,
933
+ ),
934
+ 'author' => array(
935
+ 'label' => __( 'Author', 'health-check' ),
936
+ // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
937
+ 'value' => wp_kses( $active_theme->Author, array() ),
938
+ ),
939
+ 'author_website' => array(
940
+ 'label' => __( 'Author website', 'health-check' ),
941
+ 'value' => ( $active_theme_author_uri ? $active_theme_author_uri : __( 'Undefined', 'health-check' ) ),
942
+ 'debug' => ( $active_theme_author_uri ? $active_theme_author_uri : '(undefined)' ),
943
+ ),
944
+ 'parent_theme' => array(
945
+ 'label' => __( 'Parent theme', 'health-check' ),
946
+ 'value' => ( $active_theme->parent_theme ? $active_theme->parent_theme . ' (' . $active_theme->template . ')' : __( 'None', 'health-check' ) ),
947
+ 'debug' => ( $active_theme->parent_theme ? $active_theme->parent_theme . ' (' . $active_theme->template . ')' : 'none' ),
948
+ ),
949
+ 'theme_features' => array(
950
+ 'label' => __( 'Theme features', 'health-check' ),
951
+ 'value' => implode( ', ', $theme_features ),
952
+ ),
953
+ 'theme_path' => array(
954
+ 'label' => __( 'Theme directory location', 'health-check' ),
955
+ 'value' => get_stylesheet_directory(),
956
+ ),
957
+ );
958
+
959
+ $parent_theme = $active_theme->parent();
960
+
961
+ if ( $parent_theme ) {
962
+ // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
963
+ $parent_theme_version = $parent_theme->Version;
964
+ $parent_theme_version_debug = $parent_theme_version;
965
+
966
+ if ( array_key_exists( $parent_theme->stylesheet, $theme_updates ) ) {
967
+ $parent_theme_update_new_version = $theme_updates[ $parent_theme->stylesheet ]->update['new_version'];
968
+
969
+ // translators: %s: Latest theme version number.
970
+ $parent_theme_version .= ' ' . sprintf( __( '(Latest version: %s)', 'health-check' ), $parent_theme_update_new_version );
971
+ $parent_theme_version_debug .= sprintf( ' (latest version: %s)', $parent_theme_update_new_version );
972
+ }
973
+
974
+ $parent_theme_author_uri = $parent_theme->offsetGet( 'Author URI' );
975
+
976
+ $info['wp-parent-theme']['fields'] = array(
977
+ 'name' => array(
978
+ 'label' => __( 'Name', 'health-check' ),
979
+ 'value' => sprintf(
980
+ // translators: 1: Parent theme name. 2: Parent theme slug.
981
+ __( '%1$s (%2$s)', 'health-check' ),
982
+ // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
983
+ $parent_theme->Name,
984
+ $parent_theme->stylesheet
985
+ ),
986
+ ),
987
+ 'version' => array(
988
+ 'label' => __( 'Version', 'health-check' ),
989
+ 'value' => $parent_theme_version,
990
+ 'debug' => $parent_theme_version_debug,
991
+ ),
992
+ 'author' => array(
993
+ 'label' => __( 'Author', 'health-check' ),
994
+ // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
995
+ 'value' => wp_kses( $parent_theme->Author, array() ),
996
+ ),
997
+ 'author_website' => array(
998
+ 'label' => __( 'Author website', 'health-check' ),
999
+ 'value' => ( $parent_theme_author_uri ? $parent_theme_author_uri : __( 'Undefined', 'health-check' ) ),
1000
+ 'debug' => ( $parent_theme_author_uri ? $parent_theme_author_uri : '(undefined)' ),
1001
+ ),
1002
+ 'theme_path' => array(
1003
+ 'label' => __( 'Theme directory location', 'health-check' ),
1004
+ 'value' => get_template_directory(),
1005
+ ),
1006
+ );
1007
+ }
1008
+
1009
+ // Populate a list of all themes available in the install.
1010
+ $all_themes = wp_get_themes();
1011
+
1012
+ foreach ( $all_themes as $theme_slug => $theme ) {
1013
+ // Ignore the currently active theme from the list of all themes.
1014
+ if ( $active_theme->stylesheet === $theme_slug ) {
1015
+ continue;
1016
+ }
1017
+
1018
+ // Ignore the currently active parent theme from the list of all themes.
1019
+ if ( ! empty( $parent_theme ) && $parent_theme->stylesheet === $theme_slug ) {
1020
+ continue;
1021
+ }
1022
+
1023
+ // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
1024
+ $theme_version = $theme->Version;
1025
+ // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
1026
+ $theme_author = $theme->Author;
1027
+
1028
+ // Sanitize
1029
+ $theme_author = wp_kses( $theme_author, array() );
1030
+
1031
+ $theme_version_string = __( 'No version or author information is available.', 'health-check' );
1032
+ $theme_version_string_debug = 'undefined';
1033
+
1034
+ if ( ! empty( $theme_version ) && ! empty( $theme_author ) ) {
1035
+ // translators: 1: Theme version number. 2: Theme author name.
1036
+ $theme_version_string = sprintf( __( 'Version %1$s by %2$s', 'health-check' ), $theme_version, $theme_author );
1037
+ $theme_version_string_debug = sprintf( 'version: %s, author: %s', $theme_version, $theme_author );
1038
+ } else {
1039
+ if ( ! empty( $theme_author ) ) {
1040
+ // translators: %s: Theme author name.
1041
+ $theme_version_string = sprintf( __( 'By %s', 'health-check' ), $theme_author );
1042
+ $theme_version_string_debug = sprintf( 'author: %s, version: (undefined)', $theme_author );
1043
+ }
1044
+
1045
+ if ( ! empty( $theme_version ) ) {
1046
+ // translators: %s: Theme version number.
1047
+ $theme_version_string = sprintf( __( 'Version %s', 'health-check' ), $theme_version );
1048
+ $theme_version_string_debug = sprintf( 'author: (undefined), version: %s', $theme_version );
1049
+ }
1050
+ }
1051
+
1052
+ if ( array_key_exists( $theme_slug, $theme_updates ) ) {
1053
+ // translators: %s: Latest theme version number.
1054
+ $theme_version_string .= ' ' . sprintf( __( '(Latest version: %s)', 'health-check' ), $theme_updates[ $theme_slug ]->update['new_version'] );
1055
+ $theme_version_string_debug .= sprintf( ' (latest version: %s)', $theme_updates[ $theme_slug ]->update['new_version'] );
1056
+ }
1057
+
1058
+ // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
1059
+ $info['wp-themes-inactive']['fields'][ sanitize_text_field( $theme->Name ) ] = array(
1060
+ 'label' => sprintf(
1061
+ // translators: 1: Theme name. 2: Theme slug.
1062
+ __( '%1$s (%2$s)', 'health-check' ),
1063
+ // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
1064
+ $theme->Name,
1065
+ $theme_slug
1066
+ ),
1067
+ 'value' => $theme_version_string,
1068
+ 'debug' => $theme_version_string_debug,
1069
+ );
1070
+ }
1071
+
1072
+ // Add more filesystem checks
1073
+ if ( defined( 'WPMU_PLUGIN_DIR' ) && is_dir( WPMU_PLUGIN_DIR ) ) {
1074
+ $is_writable_wpmu_plugin_dir = wp_is_writable( WPMU_PLUGIN_DIR );
1075
+
1076
+ $info['wp-filesystem']['fields']['mu-plugins'] = array(
1077
+ 'label' => __( 'The must use plugins directory', 'health-check' ),
1078
+ 'value' => ( $is_writable_wpmu_plugin_dir ? __( 'Writable', 'health-check' ) : __( 'Not writable', 'health-check' ) ),
1079
+ 'debug' => ( $is_writable_wpmu_plugin_dir ? 'writable' : 'not writable' ),
1080
+ );
1081
+ }
1082
+
1083
+ /**
1084
+ * Add or modify the debug information.
1085
+ *
1086
+ * Plugin or themes may wish to introduce their own debug information without creating additional admin pages
1087
+ * they can utilize this filter to introduce their own sections or add more data to existing sections.
1088
+ *
1089
+ * Array keys for sections added by core are all prefixed with `wp-`, plugins and themes should use their own slug as
1090
+ * a prefix, both for consistency as well as avoiding key collisions. Note that the array keys are used as labels
1091
+ * for the copied data.
1092
+ *
1093
+ * All strings are expected to be plain text except $description that can contain inline HTML tags (see below).
1094
+ *
1095
+ * @since 5.2.0
1096
+ *
1097
+ * @param array $args {
1098
+ * The debug information to be added to the core information page.
1099
+ *
1100
+ * This is an associative multi-dimensional array, up to three levels deep. The topmost array holds the sections.
1101
+ * Each section has a `$fields` associative array (see below), and each `$value` in `$fields` can be
1102
+ * another associative array of name/value pairs when there is more structured data to display.
1103
+ *
1104
+ * @type string $label The title for this section of the debug output.
1105
+ * @type string $description Optional. A description for your information section which may contain basic HTML
1106
+ * markup, inline tags only as it is outputted in a paragraph.
1107
+ * @type boolean $show_count Optional. If set to `true` the amount of fields will be included in the title for
1108
+ * this section.
1109
+ * @type boolean $private Optional. If set to `true` the section and all associated fields will be excluded
1110
+ * from the copied data.
1111
+ * @type array $fields {
1112
+ * An associative array containing the data to be displayed.
1113
+ *
1114
+ * @type string $label The label for this piece of information.
1115
+ * @type string $value The output that is displayed for this field. Text should be translated. Can be
1116
+ * an associative array that is displayed as name/value pairs.
1117
+ * @type string $debug Optional. The output that is used for this field when the user copies the data.
1118
+ * It should be more concise and not translated. If not set, the content of `$value` is used.
1119
+ * Note that the array keys are used as labels for the copied data.
1120
+ * @type boolean $private Optional. If set to `true` the field will not be included in the copied data
1121
+ * allowing you to show, for example, API keys here.
1122
+ * }
1123
+ * }
1124
+ */
1125
+ $info = apply_filters( 'debug_information', $info );
1126
+
1127
+ return $info;
1128
+ }
1129
+
1130
+ /**
1131
+ * Format the information gathered for debugging, in a manner suitable for copying to a forum or support ticket.
1132
+ *
1133
+ * @since 5.2.0
1134
+ *
1135
+ * @param array $info_array Information gathered from the `WP_Debug_Data::debug_data` function.
1136
+ * @param string $type The data type to return, either 'info' or 'debug'.
1137
+ * @return string The formatted data.
1138
+ */
1139
+ public static function format( $info_array, $type ) {
1140
+ $return = "`\n";
1141
+
1142
+ foreach ( $info_array as $section => $details ) {
1143
+ // Skip this section if there are no fields, or the section has been declared as private.
1144
+ if ( empty( $details['fields'] ) || ( isset( $details['private'] ) && $details['private'] ) ) {
1145
+ continue;
1146
+ }
1147
+
1148
+ $section_label = 'debug' === $type ? $section : $details['label'];
1149
+
1150
+ $return .= sprintf(
1151
+ "### %s%s ###\n\n",
1152
+ $section_label,
1153
+ ( isset( $details['show_count'] ) && $details['show_count'] ? sprintf( ' (%d)', count( $details['fields'] ) ) : '' )
1154
+ );
1155
+
1156
+ foreach ( $details['fields'] as $field_name => $field ) {
1157
+ if ( isset( $field['private'] ) && true === $field['private'] ) {
1158
+ continue;
1159
+ }
1160
+
1161
+ if ( 'debug' === $type && isset( $field['debug'] ) ) {
1162
+ $debug_data = $field['debug'];
1163
+ } else {
1164
+ $debug_data = $field['value'];
1165
+ }
1166
+
1167
+ // Can be array, one level deep only.
1168
+ if ( is_array( $debug_data ) ) {
1169
+ $value = '';
1170
+
1171
+ foreach ( $debug_data as $sub_field_name => $sub_field_value ) {
1172
+ $value .= sprintf( "\n\t%s: %s", $sub_field_name, $sub_field_value );
1173
+ }
1174
+ } elseif ( is_bool( $debug_data ) ) {
1175
+ $value = $debug_data ? 'true' : 'false';
1176
+ } elseif ( empty( $debug_data ) && '0' !== $debug_data ) {
1177
+ $value = 'undefined';
1178
+ } else {
1179
+ $value = $debug_data;
1180
+ }
1181
+
1182
+ if ( 'debug' === $type ) {
1183
+ $label = $field_name;
1184
+ } else {
1185
+ $label = $field['label'];
1186
+ }
1187
+
1188
+ $return .= sprintf( "%s: %s\n", $label, $value );
1189
+ }
1190
+
1191
+ $return .= "\n";
1192
+ }
1193
+
1194
+ $return .= '`';
1195
+
1196
+ return $return;
1197
+ }
1198
+
1199
+ /**
1200
+ * Fetch the total size of all the database tables for the active database user.
1201
+ *
1202
+ * @since 5.2.0
1203
+ *
1204
+ * @return int The size of the database, in bytes.
1205
+ */
1206
+ public static function get_database_size() {
1207
+ global $wpdb;
1208
+ $size = 0;
1209
+ $rows = $wpdb->get_results( 'SHOW TABLE STATUS', ARRAY_A );
1210
+
1211
+ if ( $wpdb->num_rows > 0 ) {
1212
+ foreach ( $rows as $row ) {
1213
+ $size += $row['Data_length'] + $row['Index_length'];
1214
+ }
1215
+ }
1216
+
1217
+ return (int) $size;
1218
+ }
1219
+
1220
+ public static function ajax_get_sizes() {
1221
+ check_ajax_referer( 'health-check-site-status-result' );
1222
+
1223
+ if ( ! current_user_can( 'view_site_health_checks' ) || is_multisite() ) {
1224
+ wp_send_json_error();
1225
+ }
1226
+
1227
+ $sizes_data = Health_Check_Debug_Data::get_sizes();
1228
+ $all_sizes = array( 'raw' => 0 );
1229
+
1230
+ foreach ( $sizes_data as $name => $value ) {
1231
+ $name = sanitize_text_field( $name );
1232
+ $data = array();
1233
+
1234
+ if ( isset( $value['size'] ) ) {
1235
+ if ( is_string( $value['size'] ) ) {
1236
+ $data['size'] = sanitize_text_field( $value['size'] );
1237
+ } else {
1238
+ $data['size'] = (int) $value['size'];
1239
+ }
1240
+ }
1241
+
1242
+ if ( isset( $value['debug'] ) ) {
1243
+ if ( is_string( $value['debug'] ) ) {
1244
+ $data['debug'] = sanitize_text_field( $value['debug'] );
1245
+ } else {
1246
+ $data['debug'] = (int) $value['debug'];
1247
+ }
1248
+ }
1249
+
1250
+ if ( ! empty( $value['raw'] ) ) {
1251
+ $data['raw'] = (int) $value['raw'];
1252
+ }
1253
+
1254
+ $all_sizes[ $name ] = $data;
1255
+ }
1256
+
1257
+ if ( isset( $all_sizes['total_size']['debug'] ) && 'not available' === $all_sizes['total_size']['debug'] ) {
1258
+ wp_send_json_error( $all_sizes );
1259
+ }
1260
+
1261
+ wp_send_json_success( $all_sizes );
1262
+ }
1263
+
1264
+ /**
1265
+ * Fetch the sizes of the WordPress directories: `wordpress` (ABSPATH), `plugins`, `themes`, and `uploads`.
1266
+ * Intended to supplement the array returned by `WP_Debug_Data::debug_data()`.
1267
+ *
1268
+ * @since 5.2.0
1269
+ *
1270
+ * @return array The sizes of the directories, also the database size and total installation size.
1271
+ */
1272
+ public static function get_sizes() {
1273
+ $size_db = self::get_database_size();
1274
+ $upload_dir = wp_get_upload_dir();
1275
+
1276
+ /*
1277
+ * We will be using the PHP max execution time to prevent the size calculations
1278
+ * from causing a timeout. The default value is 30 seconds, and some
1279
+ * hosts do not allow you to read configuration values.
1280
+ */
1281
+ if ( function_exists( 'ini_get' ) ) {
1282
+ $max_execution_time = ini_get( 'max_execution_time' );
1283
+ }
1284
+
1285
+ // The max_execution_time defaults to 0 when PHP runs from cli.
1286
+ // We still want to limit it below.
1287
+ if ( empty( $max_execution_time ) ) {
1288
+ $max_execution_time = 30;
1289
+ }
1290
+
1291
+ if ( $max_execution_time > 20 ) {
1292
+ // If the max_execution_time is set to lower than 20 seconds, reduce it a bit to prevent
1293
+ // edge-case timeouts that may happen after the size loop has finished running.
1294
+ $max_execution_time -= 2;
1295
+ }
1296
+
1297
+ if ( ! defined( 'WP_START_TIMESTAMP' ) ) {
1298
+ global $timestart;
1299
+ if ( version_compare( phpversion(), '5.4.0', '>=' ) && isset( $_SERVER['REQUEST_TIME_FLOAT'] ) ) {
1300
+ define( 'WP_START_TIMESTAMP', $_SERVER['REQUEST_TIME_FLOAT'] );
1301
+ } else {
1302
+ define( 'WP_START_TIMESTAMP', $timestart );
1303
+ }
1304
+ }
1305
+
1306
+ // Go through the various installation directories and calculate their sizes.
1307
+ // No trailing slashes.
1308
+ $paths = array(
1309
+ 'wordpress_size' => untrailingslashit( ABSPATH ),
1310
+ 'themes_size' => get_theme_root(),
1311
+ 'plugins_size' => WP_PLUGIN_DIR,
1312
+ 'uploads_size' => $upload_dir['basedir'],
1313
+ );
1314
+
1315
+ $exclude = $paths;
1316
+ unset( $exclude['wordpress_size'] );
1317
+ $exclude = array_values( $exclude );
1318
+
1319
+ $size_total = 0;
1320
+ $all_sizes = array();
1321
+
1322
+ // Loop over all the directories we want to gather the sizes for.
1323
+ foreach ( $paths as $name => $path ) {
1324
+ $dir_size = null; // Default to timeout.
1325
+ $results = array(
1326
+ 'path' => $path,
1327
+ 'raw' => 0,
1328
+ );
1329
+
1330
+ if ( microtime( true ) - WP_START_TIMESTAMP < $max_execution_time ) {
1331
+ if ( 'wordpress_size' === $name ) {
1332
+ if ( version_compare( get_bloginfo( 'version' ), '5.2.0', '<' ) ) {
1333
+ $dir_size = Health_Check_Debug_Data::recurse_dirsize( $path, $exclude, $max_execution_time );
1334
+ } else {
1335
+ $dir_size = recurse_dirsize( $path, $exclude, $max_execution_time );
1336
+ }
1337
+ } else {
1338
+ if ( version_compare( get_bloginfo( 'version' ), '5.2.0', '<' ) ) {
1339
+ $dir_size = Health_Check_Debug_Data::recurse_dirsize( $path, null, $max_execution_time );
1340
+ } else {
1341
+ $dir_size = recurse_dirsize( $path, null, $max_execution_time );
1342
+ }
1343
+ }
1344
+ }
1345
+
1346
+ if ( false === $dir_size ) {
1347
+ // Error reading.
1348
+ $results['size'] = __( 'The size cannot be calculated. The directory is not accessible. Usually caused by invalid permissions.', 'health-check' );
1349
+ $results['debug'] = 'not accessible';
1350
+
1351
+ // Stop total size calculation.
1352
+ $size_total = null;
1353
+ } elseif ( null === $dir_size ) {
1354
+ // Timeout.
1355
+ $results['size'] = __( 'The directory size calculation has timed out. Usually caused by a very large number of sub-directories and files.', 'health-check' );
1356
+ $results['debug'] = 'timeout while calculating size';
1357
+
1358
+ // Stop total size calculation.
1359
+ $size_total = null;
1360
+ } else {
1361
+ if ( null !== $size_total ) {
1362
+ $size_total += $dir_size;
1363
+ }
1364
+
1365
+ $results['raw'] = $dir_size;
1366
+ $results['size'] = size_format( $dir_size, 2 );
1367
+ $results['debug'] = $results['size'] . " ({$dir_size} bytes)";
1368
+ }
1369
+
1370
+ $all_sizes[ $name ] = $results;
1371
+ }
1372
+
1373
+ if ( $size_db > 0 ) {
1374
+ $database_size = size_format( $size_db, 2 );
1375
+
1376
+ $all_sizes['database_size'] = array(
1377
+ 'raw' => $size_db,
1378
+ 'size' => $database_size,
1379
+ 'debug' => $database_size . " ({$size_db} bytes)",
1380
+ );
1381
+ } else {
1382
+ $all_sizes['database_size'] = array(
1383
+ 'size' => __( 'Not available', 'health-check' ),
1384
+ 'debug' => 'not available',
1385
+ );
1386
+ }
1387
+
1388
+ if ( null !== $size_total && $size_db > 0 ) {
1389
+ $total_size = $size_total + $size_db;
1390
+ $total_size_mb = size_format( $total_size, 2 );
1391
+
1392
+ $all_sizes['total_size'] = array(
1393
+ 'raw' => $total_size,
1394
+ 'size' => $total_size_mb,
1395
+ 'debug' => $total_size_mb . " ({$total_size} bytes)",
1396
+ );
1397
+ } else {
1398
+ $all_sizes['total_size'] = array(
1399
+ 'size' => __( 'Total size is not available. Some errors were encountered when determining the size of your installation.', 'health-check' ),
1400
+ 'debug' => 'not available',
1401
+ );
1402
+ }
1403
+
1404
+ return $all_sizes;
1405
+ }
1406
+
1407
+ /**
1408
+ * Fallback function for directory size calculation on sites running WordPress <5.2
1409
+ *
1410
+ * @param string $directory Full path of a directory.
1411
+ * @param string|array $exclude Optional. Full path of a subdirectory to exclude from the total, or array of paths.
1412
+ * Expected without trailing slash(es).
1413
+ * @param int $max_execution_time Maximum time to run before giving up. In seconds.
1414
+ * The timeout is global and is measured from the moment WordPress started to load.
1415
+ * @return int|false|null Size in bytes if a valid directory. False if not. Null if timeout.
1416
+ */
1417
+ static function recurse_dirsize( $directory, $exclude = null, $max_execution_time = null ) {
1418
+ $size = 0;
1419
+
1420
+ $directory = untrailingslashit( $directory );
1421
+
1422
+ if ( ! file_exists( $directory ) || ! is_dir( $directory ) || ! is_readable( $directory ) ) {
1423
+ return false;
1424
+ }
1425
+
1426
+ if (
1427
+ ( is_string( $exclude ) && $directory === $exclude ) ||
1428
+ ( is_array( $exclude ) && in_array( $directory, $exclude, true ) )
1429
+ ) {
1430
+ return false;
1431
+ }
1432
+
1433
+ if ( null === $max_execution_time ) {
1434
+ // Keep the previous behavior but attempt to prevent fatal errors from timeout if possible.
1435
+ if ( function_exists( 'ini_get' ) ) {
1436
+ $max_execution_time = ini_get( 'max_execution_time' );
1437
+ } else {
1438
+ // Disable...
1439
+ $max_execution_time = 0;
1440
+ }
1441
+
1442
+ // Leave 1 second "buffer" for other operations if $max_execution_time has reasonable value.
1443
+ if ( $max_execution_time > 10 ) {
1444
+ $max_execution_time -= 1;
1445
+ }
1446
+ }
1447
+
1448
+ $handle = opendir( $directory );
1449
+ if ( $handle ) {
1450
+ while ( ( $file = readdir( $handle ) ) !== false ) {
1451
+ $path = $directory . '/' . $file;
1452
+ if ( '.' != $file && '..' != $file ) {
1453
+ if ( is_file( $path ) ) {
1454
+ $size += filesize( $path );
1455
+ } elseif ( is_dir( $path ) ) {
1456
+ $handlesize = Health_Check_Debug_Data::recurse_dirsize( $path, $exclude, $max_execution_time );
1457
+ if ( $handlesize > 0 ) {
1458
+ $size += $handlesize;
1459
+ }
1460
+ }
1461
+
1462
+ if ( $max_execution_time > 0 && microtime( true ) - WP_START_TIMESTAMP > $max_execution_time ) {
1463
+ // Time exceeded. Give up instead of risking a fatal timeout.
1464
+ $size = null;
1465
+ break;
1466
+ }
1467
+ }
1468
+ }
1469
+ closedir( $handle );
1470
+ }
1471
+ return $size;
1472
+ }
1473
+ }
readme.txt CHANGED
@@ -4,7 +4,7 @@ Contributors: wordpressdotorg, westi, pento, Clorith
4
  Requires at least: 4.0
5
  Requires PHP: 5.2
6
  Tested up to: 5.2
7
- Stable tag: 1.4.1
8
  License: GPLv2
9
  License URI: https://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -49,6 +49,9 @@ At this time, the plugin has been tested with every version of PHP from 5.2 thro
49
 
50
  == Changelog ==
51
 
 
 
 
52
  = v1.4.1 =
53
  * Fixed SQL version checks for various MariaDB installs.
54
  * Fixed a warning being generated in logfiles for first-time users with no existing Site Health history.
4
  Requires at least: 4.0
5
  Requires PHP: 5.2
6
  Tested up to: 5.2
7
+ Stable tag: 1.4.2
8
  License: GPLv2
9
  License URI: https://www.gnu.org/licenses/gpl-2.0.html
10
 
49
 
50
  == Changelog ==
51
 
52
+ = v1.4.2 =
53
+ * Fix missing headers for a loopback request in the debug section
54
+
55
  = v1.4.1 =
56
  * Fixed SQL version checks for various MariaDB installs.
57
  * Fixed a warning being generated in logfiles for first-time users with no existing Site Health history.