class-wp-debug-data.php 47 KB

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