Ei kuvausta

class-wp-debug-data.php 57KB

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