class-wp-debug-data.php 59 KB

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