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