Нет описания

class-wp-debug-data.php 59KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707
  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. public 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. public 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_ENVIRONMENT_TYPE.
  215. if ( defined( 'WP_ENVIRONMENT_TYPE' ) ) {
  216. $wp_environment_type = WP_ENVIRONMENT_TYPE;
  217. } else {
  218. $wp_environment_type = __( 'Undefined' );
  219. }
  220. $info['wp-constants'] = array(
  221. 'label' => __( 'WordPress Constants' ),
  222. 'description' => __( 'These settings alter where and how parts of WordPress are loaded.' ),
  223. 'fields' => array(
  224. 'ABSPATH' => array(
  225. 'label' => 'ABSPATH',
  226. 'value' => ABSPATH,
  227. 'private' => true,
  228. ),
  229. 'WP_HOME' => array(
  230. 'label' => 'WP_HOME',
  231. 'value' => ( defined( 'WP_HOME' ) ? WP_HOME : __( 'Undefined' ) ),
  232. 'debug' => ( defined( 'WP_HOME' ) ? WP_HOME : 'undefined' ),
  233. ),
  234. 'WP_SITEURL' => array(
  235. 'label' => 'WP_SITEURL',
  236. 'value' => ( defined( 'WP_SITEURL' ) ? WP_SITEURL : __( 'Undefined' ) ),
  237. 'debug' => ( defined( 'WP_SITEURL' ) ? WP_SITEURL : 'undefined' ),
  238. ),
  239. 'WP_CONTENT_DIR' => array(
  240. 'label' => 'WP_CONTENT_DIR',
  241. 'value' => WP_CONTENT_DIR,
  242. ),
  243. 'WP_PLUGIN_DIR' => array(
  244. 'label' => 'WP_PLUGIN_DIR',
  245. 'value' => WP_PLUGIN_DIR,
  246. ),
  247. 'WP_MEMORY_LIMIT' => array(
  248. 'label' => 'WP_MEMORY_LIMIT',
  249. 'value' => WP_MEMORY_LIMIT,
  250. ),
  251. 'WP_MAX_MEMORY_LIMIT' => array(
  252. 'label' => 'WP_MAX_MEMORY_LIMIT',
  253. 'value' => WP_MAX_MEMORY_LIMIT,
  254. ),
  255. 'WP_DEBUG' => array(
  256. 'label' => 'WP_DEBUG',
  257. 'value' => WP_DEBUG ? __( 'Enabled' ) : __( 'Disabled' ),
  258. 'debug' => WP_DEBUG,
  259. ),
  260. 'WP_DEBUG_DISPLAY' => array(
  261. 'label' => 'WP_DEBUG_DISPLAY',
  262. 'value' => WP_DEBUG_DISPLAY ? __( 'Enabled' ) : __( 'Disabled' ),
  263. 'debug' => WP_DEBUG_DISPLAY,
  264. ),
  265. 'WP_DEBUG_LOG' => array(
  266. 'label' => 'WP_DEBUG_LOG',
  267. 'value' => $wp_debug_log_value,
  268. 'debug' => WP_DEBUG_LOG,
  269. ),
  270. 'SCRIPT_DEBUG' => array(
  271. 'label' => 'SCRIPT_DEBUG',
  272. 'value' => SCRIPT_DEBUG ? __( 'Enabled' ) : __( 'Disabled' ),
  273. 'debug' => SCRIPT_DEBUG,
  274. ),
  275. 'WP_CACHE' => array(
  276. 'label' => 'WP_CACHE',
  277. 'value' => WP_CACHE ? __( 'Enabled' ) : __( 'Disabled' ),
  278. 'debug' => WP_CACHE,
  279. ),
  280. 'CONCATENATE_SCRIPTS' => array(
  281. 'label' => 'CONCATENATE_SCRIPTS',
  282. 'value' => $concatenate_scripts,
  283. 'debug' => $concatenate_scripts_debug,
  284. ),
  285. 'COMPRESS_SCRIPTS' => array(
  286. 'label' => 'COMPRESS_SCRIPTS',
  287. 'value' => $compress_scripts,
  288. 'debug' => $compress_scripts_debug,
  289. ),
  290. 'COMPRESS_CSS' => array(
  291. 'label' => 'COMPRESS_CSS',
  292. 'value' => $compress_css,
  293. 'debug' => $compress_css_debug,
  294. ),
  295. 'WP_ENVIRONMENT_TYPE' => array(
  296. 'label' => 'WP_ENVIRONMENT_TYPE',
  297. 'value' => $wp_environment_type,
  298. 'debug' => $wp_environment_type,
  299. ),
  300. 'DB_CHARSET' => array(
  301. 'label' => 'DB_CHARSET',
  302. 'value' => ( defined( 'DB_CHARSET' ) ? DB_CHARSET : __( 'Undefined' ) ),
  303. 'debug' => ( defined( 'DB_CHARSET' ) ? DB_CHARSET : 'undefined' ),
  304. ),
  305. 'DB_COLLATE' => array(
  306. 'label' => 'DB_COLLATE',
  307. 'value' => ( defined( 'DB_COLLATE' ) ? DB_COLLATE : __( 'Undefined' ) ),
  308. 'debug' => ( defined( 'DB_COLLATE' ) ? DB_COLLATE : 'undefined' ),
  309. ),
  310. ),
  311. );
  312. $is_writable_abspath = wp_is_writable( ABSPATH );
  313. $is_writable_wp_content_dir = wp_is_writable( WP_CONTENT_DIR );
  314. $is_writable_upload_dir = wp_is_writable( $upload_dir['basedir'] );
  315. $is_writable_wp_plugin_dir = wp_is_writable( WP_PLUGIN_DIR );
  316. $is_writable_template_directory = wp_is_writable( get_theme_root( get_template() ) );
  317. $info['wp-filesystem'] = array(
  318. 'label' => __( 'Filesystem Permissions' ),
  319. 'description' => __( 'Shows whether WordPress is able to write to the directories it needs access to.' ),
  320. 'fields' => array(
  321. 'wordpress' => array(
  322. 'label' => __( 'The main WordPress directory' ),
  323. 'value' => ( $is_writable_abspath ? __( 'Writable' ) : __( 'Not writable' ) ),
  324. 'debug' => ( $is_writable_abspath ? 'writable' : 'not writable' ),
  325. ),
  326. 'wp-content' => array(
  327. 'label' => __( 'The wp-content directory' ),
  328. 'value' => ( $is_writable_wp_content_dir ? __( 'Writable' ) : __( 'Not writable' ) ),
  329. 'debug' => ( $is_writable_wp_content_dir ? 'writable' : 'not writable' ),
  330. ),
  331. 'uploads' => array(
  332. 'label' => __( 'The uploads directory' ),
  333. 'value' => ( $is_writable_upload_dir ? __( 'Writable' ) : __( 'Not writable' ) ),
  334. 'debug' => ( $is_writable_upload_dir ? 'writable' : 'not writable' ),
  335. ),
  336. 'plugins' => array(
  337. 'label' => __( 'The plugins directory' ),
  338. 'value' => ( $is_writable_wp_plugin_dir ? __( 'Writable' ) : __( 'Not writable' ) ),
  339. 'debug' => ( $is_writable_wp_plugin_dir ? 'writable' : 'not writable' ),
  340. ),
  341. 'themes' => array(
  342. 'label' => __( 'The themes directory' ),
  343. 'value' => ( $is_writable_template_directory ? __( 'Writable' ) : __( 'Not writable' ) ),
  344. 'debug' => ( $is_writable_template_directory ? 'writable' : 'not writable' ),
  345. ),
  346. ),
  347. );
  348. // Conditionally add debug information for multisite setups.
  349. if ( is_multisite() ) {
  350. $network_query = new WP_Network_Query();
  351. $network_ids = $network_query->query(
  352. array(
  353. 'fields' => 'ids',
  354. 'number' => 100,
  355. 'no_found_rows' => false,
  356. )
  357. );
  358. $site_count = 0;
  359. foreach ( $network_ids as $network_id ) {
  360. $site_count += get_blog_count( $network_id );
  361. }
  362. $info['wp-core']['fields']['site_count'] = array(
  363. 'label' => __( 'Site count' ),
  364. 'value' => $site_count,
  365. );
  366. $info['wp-core']['fields']['network_count'] = array(
  367. 'label' => __( 'Network count' ),
  368. 'value' => $network_query->found_networks,
  369. );
  370. }
  371. $info['wp-core']['fields']['user_count'] = array(
  372. 'label' => __( 'User count' ),
  373. 'value' => get_user_count(),
  374. );
  375. // WordPress features requiring processing.
  376. $wp_dotorg = wp_remote_get( 'https://wordpress.org', array( 'timeout' => 10 ) );
  377. if ( ! is_wp_error( $wp_dotorg ) ) {
  378. $info['wp-core']['fields']['dotorg_communication'] = array(
  379. 'label' => __( 'Communication with WordPress.org' ),
  380. 'value' => __( 'WordPress.org is reachable' ),
  381. 'debug' => 'true',
  382. );
  383. } else {
  384. $info['wp-core']['fields']['dotorg_communication'] = array(
  385. 'label' => __( 'Communication with WordPress.org' ),
  386. 'value' => sprintf(
  387. /* translators: 1: The IP address WordPress.org resolves to. 2: The error returned by the lookup. */
  388. __( 'Unable to reach WordPress.org at %1$s: %2$s' ),
  389. gethostbyname( 'wordpress.org' ),
  390. $wp_dotorg->get_error_message()
  391. ),
  392. 'debug' => $wp_dotorg->get_error_message(),
  393. );
  394. }
  395. // Remove accordion for Directories and Sizes if in Multisite.
  396. if ( ! $is_multisite ) {
  397. $loading = __( 'Loading&hellip;' );
  398. $info['wp-paths-sizes']['fields'] = array(
  399. 'wordpress_path' => array(
  400. 'label' => __( 'WordPress directory location' ),
  401. 'value' => untrailingslashit( ABSPATH ),
  402. ),
  403. 'wordpress_size' => array(
  404. 'label' => __( 'WordPress directory size' ),
  405. 'value' => $loading,
  406. 'debug' => 'loading...',
  407. ),
  408. 'uploads_path' => array(
  409. 'label' => __( 'Uploads directory location' ),
  410. 'value' => $upload_dir['basedir'],
  411. ),
  412. 'uploads_size' => array(
  413. 'label' => __( 'Uploads directory size' ),
  414. 'value' => $loading,
  415. 'debug' => 'loading...',
  416. ),
  417. 'themes_path' => array(
  418. 'label' => __( 'Themes directory location' ),
  419. 'value' => get_theme_root(),
  420. ),
  421. 'themes_size' => array(
  422. 'label' => __( 'Themes directory size' ),
  423. 'value' => $loading,
  424. 'debug' => 'loading...',
  425. ),
  426. 'plugins_path' => array(
  427. 'label' => __( 'Plugins directory location' ),
  428. 'value' => WP_PLUGIN_DIR,
  429. ),
  430. 'plugins_size' => array(
  431. 'label' => __( 'Plugins directory size' ),
  432. 'value' => $loading,
  433. 'debug' => 'loading...',
  434. ),
  435. 'database_size' => array(
  436. 'label' => __( 'Database size' ),
  437. 'value' => $loading,
  438. 'debug' => 'loading...',
  439. ),
  440. 'total_size' => array(
  441. 'label' => __( 'Total installation size' ),
  442. 'value' => $loading,
  443. 'debug' => 'loading...',
  444. ),
  445. );
  446. }
  447. // Get a list of all drop-in replacements.
  448. $dropins = get_dropins();
  449. // Get dropins descriptions.
  450. $dropin_descriptions = _get_dropins();
  451. // Spare few function calls.
  452. $not_available = __( 'Not available' );
  453. foreach ( $dropins as $dropin_key => $dropin ) {
  454. $info['wp-dropins']['fields'][ sanitize_text_field( $dropin_key ) ] = array(
  455. 'label' => $dropin_key,
  456. 'value' => $dropin_descriptions[ $dropin_key ][0],
  457. 'debug' => 'true',
  458. );
  459. }
  460. // Populate the media fields.
  461. $info['wp-media']['fields']['image_editor'] = array(
  462. 'label' => __( 'Active editor' ),
  463. 'value' => _wp_image_editor_choose(),
  464. );
  465. // Get ImageMagic information, if available.
  466. if ( class_exists( 'Imagick' ) ) {
  467. // Save the Imagick instance for later use.
  468. $imagick = new Imagick();
  469. $imagemagick_version = $imagick->getVersion();
  470. } else {
  471. $imagemagick_version = __( 'Not available' );
  472. }
  473. $info['wp-media']['fields']['imagick_module_version'] = array(
  474. 'label' => __( 'ImageMagick version number' ),
  475. 'value' => ( is_array( $imagemagick_version ) ? $imagemagick_version['versionNumber'] : $imagemagick_version ),
  476. );
  477. $info['wp-media']['fields']['imagemagick_version'] = array(
  478. 'label' => __( 'ImageMagick version string' ),
  479. 'value' => ( is_array( $imagemagick_version ) ? $imagemagick_version['versionString'] : $imagemagick_version ),
  480. );
  481. $imagick_version = phpversion( 'imagick' );
  482. $info['wp-media']['fields']['imagick_version'] = array(
  483. 'label' => __( 'Imagick version' ),
  484. 'value' => ( $imagick_version ) ? $imagick_version : __( 'Not available' ),
  485. );
  486. if ( ! function_exists( 'ini_get' ) ) {
  487. $info['wp-media']['fields']['ini_get'] = array(
  488. 'label' => __( 'File upload settings' ),
  489. 'value' => sprintf(
  490. /* translators: %s: ini_get() */
  491. __( 'Unable to determine some settings, as the %s function has been disabled.' ),
  492. 'ini_get()'
  493. ),
  494. 'debug' => 'ini_get() is disabled',
  495. );
  496. } else {
  497. // Get the PHP ini directive values.
  498. $post_max_size = ini_get( 'post_max_size' );
  499. $upload_max_filesize = ini_get( 'upload_max_filesize' );
  500. $max_file_uploads = ini_get( 'max_file_uploads' );
  501. $effective = min( wp_convert_hr_to_bytes( $post_max_size ), wp_convert_hr_to_bytes( $upload_max_filesize ) );
  502. // Add info in Media section.
  503. $info['wp-media']['fields']['file_uploads'] = array(
  504. 'label' => __( 'File uploads' ),
  505. 'value' => empty( ini_get( 'file_uploads' ) ) ? __( 'Disabled' ) : __( 'Enabled' ),
  506. 'debug' => 'File uploads is turned off',
  507. );
  508. $info['wp-media']['fields']['post_max_size'] = array(
  509. 'label' => __( 'Max size of post data allowed' ),
  510. 'value' => $post_max_size,
  511. );
  512. $info['wp-media']['fields']['upload_max_filesize'] = array(
  513. 'label' => __( 'Max size of an uploaded file' ),
  514. 'value' => $upload_max_filesize,
  515. );
  516. $info['wp-media']['fields']['max_effective_size'] = array(
  517. 'label' => __( 'Max effective file size' ),
  518. 'value' => size_format( $effective ),
  519. );
  520. $info['wp-media']['fields']['max_file_uploads'] = array(
  521. 'label' => __( 'Max number of files allowed' ),
  522. 'value' => number_format( $max_file_uploads ),
  523. );
  524. }
  525. // If Imagick is used as our editor, provide some more information about its limitations.
  526. if ( 'WP_Image_Editor_Imagick' === _wp_image_editor_choose() && isset( $imagick ) && $imagick instanceof Imagick ) {
  527. $limits = array(
  528. 'area' => ( defined( 'imagick::RESOURCETYPE_AREA' ) ? size_format( $imagick->getResourceLimit( imagick::RESOURCETYPE_AREA ) ) : $not_available ),
  529. 'disk' => ( defined( 'imagick::RESOURCETYPE_DISK' ) ? $imagick->getResourceLimit( imagick::RESOURCETYPE_DISK ) : $not_available ),
  530. 'file' => ( defined( 'imagick::RESOURCETYPE_FILE' ) ? $imagick->getResourceLimit( imagick::RESOURCETYPE_FILE ) : $not_available ),
  531. 'map' => ( defined( 'imagick::RESOURCETYPE_MAP' ) ? size_format( $imagick->getResourceLimit( imagick::RESOURCETYPE_MAP ) ) : $not_available ),
  532. 'memory' => ( defined( 'imagick::RESOURCETYPE_MEMORY' ) ? size_format( $imagick->getResourceLimit( imagick::RESOURCETYPE_MEMORY ) ) : $not_available ),
  533. 'thread' => ( defined( 'imagick::RESOURCETYPE_THREAD' ) ? $imagick->getResourceLimit( imagick::RESOURCETYPE_THREAD ) : $not_available ),
  534. );
  535. $limits_debug = array(
  536. 'imagick::RESOURCETYPE_AREA' => ( defined( 'imagick::RESOURCETYPE_AREA' ) ? size_format( $imagick->getResourceLimit( imagick::RESOURCETYPE_AREA ) ) : 'not available' ),
  537. 'imagick::RESOURCETYPE_DISK' => ( defined( 'imagick::RESOURCETYPE_DISK' ) ? $imagick->getResourceLimit( imagick::RESOURCETYPE_DISK ) : 'not available' ),
  538. 'imagick::RESOURCETYPE_FILE' => ( defined( 'imagick::RESOURCETYPE_FILE' ) ? $imagick->getResourceLimit( imagick::RESOURCETYPE_FILE ) : 'not available' ),
  539. 'imagick::RESOURCETYPE_MAP' => ( defined( 'imagick::RESOURCETYPE_MAP' ) ? size_format( $imagick->getResourceLimit( imagick::RESOURCETYPE_MAP ) ) : 'not available' ),
  540. 'imagick::RESOURCETYPE_MEMORY' => ( defined( 'imagick::RESOURCETYPE_MEMORY' ) ? size_format( $imagick->getResourceLimit( imagick::RESOURCETYPE_MEMORY ) ) : 'not available' ),
  541. 'imagick::RESOURCETYPE_THREAD' => ( defined( 'imagick::RESOURCETYPE_THREAD' ) ? $imagick->getResourceLimit( imagick::RESOURCETYPE_THREAD ) : 'not available' ),
  542. );
  543. $info['wp-media']['fields']['imagick_limits'] = array(
  544. 'label' => __( 'Imagick Resource Limits' ),
  545. 'value' => $limits,
  546. 'debug' => $limits_debug,
  547. );
  548. try {
  549. $formats = Imagick::queryFormats( '*' );
  550. } catch ( Exception $e ) {
  551. $formats = array();
  552. }
  553. $info['wp-media']['fields']['imagemagick_file_formats'] = array(
  554. 'label' => __( 'ImageMagick supported file formats' ),
  555. 'value' => ( empty( $formats ) ) ? __( 'Unable to determine' ) : implode( ', ', $formats ),
  556. 'debug' => ( empty( $formats ) ) ? 'Unable to determine' : implode( ', ', $formats ),
  557. );
  558. }
  559. // Get GD information, if available.
  560. if ( function_exists( 'gd_info' ) ) {
  561. $gd = gd_info();
  562. } else {
  563. $gd = false;
  564. }
  565. $info['wp-media']['fields']['gd_version'] = array(
  566. 'label' => __( 'GD version' ),
  567. 'value' => ( is_array( $gd ) ? $gd['GD Version'] : $not_available ),
  568. 'debug' => ( is_array( $gd ) ? $gd['GD Version'] : 'not available' ),
  569. );
  570. $gd_image_formats = array();
  571. $gd_supported_formats = array(
  572. 'GIF Create' => 'GIF',
  573. 'JPEG' => 'JPEG',
  574. 'PNG' => 'PNG',
  575. 'WebP' => 'WebP',
  576. 'BMP' => 'BMP',
  577. 'AVIF' => 'AVIF',
  578. 'HEIF' => 'HEIF',
  579. 'TIFF' => 'TIFF',
  580. 'XPM' => 'XPM',
  581. );
  582. foreach ( $gd_supported_formats as $format_key => $format ) {
  583. $index = $format_key . ' Support';
  584. if ( isset( $gd[ $index ] ) && $gd[ $index ] ) {
  585. array_push( $gd_image_formats, $format );
  586. }
  587. }
  588. if ( ! empty( $gd_image_formats ) ) {
  589. $info['wp-media']['fields']['gd_formats'] = array(
  590. 'label' => __( 'GD supported file formats' ),
  591. 'value' => implode( ', ', $gd_image_formats ),
  592. );
  593. }
  594. // Get Ghostscript information, if available.
  595. if ( function_exists( 'exec' ) ) {
  596. $gs = exec( 'gs --version' );
  597. if ( empty( $gs ) ) {
  598. $gs = $not_available;
  599. $gs_debug = 'not available';
  600. } else {
  601. $gs_debug = $gs;
  602. }
  603. } else {
  604. $gs = __( 'Unable to determine if Ghostscript is installed' );
  605. $gs_debug = 'unknown';
  606. }
  607. $info['wp-media']['fields']['ghostscript_version'] = array(
  608. 'label' => __( 'Ghostscript version' ),
  609. 'value' => $gs,
  610. 'debug' => $gs_debug,
  611. );
  612. // Populate the server debug fields.
  613. if ( function_exists( 'php_uname' ) ) {
  614. $server_architecture = sprintf( '%s %s %s', php_uname( 's' ), php_uname( 'r' ), php_uname( 'm' ) );
  615. } else {
  616. $server_architecture = 'unknown';
  617. }
  618. if ( function_exists( 'phpversion' ) ) {
  619. $php_version_debug = phpversion();
  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. } else {
  631. $php_version = __( 'Unable to determine PHP version' );
  632. $php_version_debug = 'unknown';
  633. }
  634. if ( function_exists( 'php_sapi_name' ) ) {
  635. $php_sapi = php_sapi_name();
  636. } else {
  637. $php_sapi = 'unknown';
  638. }
  639. $info['wp-server']['fields']['server_architecture'] = array(
  640. 'label' => __( 'Server architecture' ),
  641. 'value' => ( 'unknown' !== $server_architecture ? $server_architecture : __( 'Unable to determine server architecture' ) ),
  642. 'debug' => $server_architecture,
  643. );
  644. $info['wp-server']['fields']['httpd_software'] = array(
  645. 'label' => __( 'Web server' ),
  646. 'value' => ( isset( $_SERVER['SERVER_SOFTWARE'] ) ? $_SERVER['SERVER_SOFTWARE'] : __( 'Unable to determine what web server software is used' ) ),
  647. 'debug' => ( isset( $_SERVER['SERVER_SOFTWARE'] ) ? $_SERVER['SERVER_SOFTWARE'] : 'unknown' ),
  648. );
  649. $info['wp-server']['fields']['php_version'] = array(
  650. 'label' => __( 'PHP version' ),
  651. 'value' => $php_version,
  652. 'debug' => $php_version_debug,
  653. );
  654. $info['wp-server']['fields']['php_sapi'] = array(
  655. 'label' => __( 'PHP SAPI' ),
  656. 'value' => ( 'unknown' !== $php_sapi ? $php_sapi : __( 'Unable to determine PHP SAPI' ) ),
  657. 'debug' => $php_sapi,
  658. );
  659. // Some servers disable `ini_set()` and `ini_get()`, we check this before trying to get configuration values.
  660. if ( ! function_exists( 'ini_get' ) ) {
  661. $info['wp-server']['fields']['ini_get'] = array(
  662. 'label' => __( 'Server settings' ),
  663. 'value' => sprintf(
  664. /* translators: %s: ini_get() */
  665. __( 'Unable to determine some settings, as the %s function has been disabled.' ),
  666. 'ini_get()'
  667. ),
  668. 'debug' => 'ini_get() is disabled',
  669. );
  670. } else {
  671. $info['wp-server']['fields']['max_input_variables'] = array(
  672. 'label' => __( 'PHP max input variables' ),
  673. 'value' => ini_get( 'max_input_vars' ),
  674. );
  675. $info['wp-server']['fields']['time_limit'] = array(
  676. 'label' => __( 'PHP time limit' ),
  677. 'value' => ini_get( 'max_execution_time' ),
  678. );
  679. if ( WP_Site_Health::get_instance()->php_memory_limit !== ini_get( 'memory_limit' ) ) {
  680. $info['wp-server']['fields']['memory_limit'] = array(
  681. 'label' => __( 'PHP memory limit' ),
  682. 'value' => WP_Site_Health::get_instance()->php_memory_limit,
  683. );
  684. $info['wp-server']['fields']['admin_memory_limit'] = array(
  685. 'label' => __( 'PHP memory limit (only for admin screens)' ),
  686. 'value' => ini_get( 'memory_limit' ),
  687. );
  688. } else {
  689. $info['wp-server']['fields']['memory_limit'] = array(
  690. 'label' => __( 'PHP memory limit' ),
  691. 'value' => ini_get( 'memory_limit' ),
  692. );
  693. }
  694. $info['wp-server']['fields']['max_input_time'] = array(
  695. 'label' => __( 'Max input time' ),
  696. 'value' => ini_get( 'max_input_time' ),
  697. );
  698. $info['wp-server']['fields']['upload_max_filesize'] = array(
  699. 'label' => __( 'Upload max filesize' ),
  700. 'value' => ini_get( 'upload_max_filesize' ),
  701. );
  702. $info['wp-server']['fields']['php_post_max_size'] = array(
  703. 'label' => __( 'PHP post max size' ),
  704. 'value' => ini_get( 'post_max_size' ),
  705. );
  706. }
  707. if ( function_exists( 'curl_version' ) ) {
  708. $curl = curl_version();
  709. $info['wp-server']['fields']['curl_version'] = array(
  710. 'label' => __( 'cURL version' ),
  711. 'value' => sprintf( '%s %s', $curl['version'], $curl['ssl_version'] ),
  712. );
  713. } else {
  714. $info['wp-server']['fields']['curl_version'] = array(
  715. 'label' => __( 'cURL version' ),
  716. 'value' => $not_available,
  717. 'debug' => 'not available',
  718. );
  719. }
  720. // SUHOSIN.
  721. $suhosin_loaded = ( extension_loaded( 'suhosin' ) || ( defined( 'SUHOSIN_PATCH' ) && constant( 'SUHOSIN_PATCH' ) ) );
  722. $info['wp-server']['fields']['suhosin'] = array(
  723. 'label' => __( 'Is SUHOSIN installed?' ),
  724. 'value' => ( $suhosin_loaded ? __( 'Yes' ) : __( 'No' ) ),
  725. 'debug' => $suhosin_loaded,
  726. );
  727. // Imagick.
  728. $imagick_loaded = extension_loaded( 'imagick' );
  729. $info['wp-server']['fields']['imagick_availability'] = array(
  730. 'label' => __( 'Is the Imagick library available?' ),
  731. 'value' => ( $imagick_loaded ? __( 'Yes' ) : __( 'No' ) ),
  732. 'debug' => $imagick_loaded,
  733. );
  734. // Pretty permalinks.
  735. $pretty_permalinks_supported = got_url_rewrite();
  736. $info['wp-server']['fields']['pretty_permalinks'] = array(
  737. 'label' => __( 'Are pretty permalinks supported?' ),
  738. 'value' => ( $pretty_permalinks_supported ? __( 'Yes' ) : __( 'No' ) ),
  739. 'debug' => $pretty_permalinks_supported,
  740. );
  741. // Check if a .htaccess file exists.
  742. if ( is_file( ABSPATH . '.htaccess' ) ) {
  743. // If the file exists, grab the content of it.
  744. $htaccess_content = file_get_contents( ABSPATH . '.htaccess' );
  745. // Filter away the core WordPress rules.
  746. $filtered_htaccess_content = trim( preg_replace( '/\# BEGIN WordPress[\s\S]+?# END WordPress/si', '', $htaccess_content ) );
  747. $filtered_htaccess_content = ! empty( $filtered_htaccess_content );
  748. if ( $filtered_htaccess_content ) {
  749. /* translators: %s: .htaccess */
  750. $htaccess_rules_string = sprintf( __( 'Custom rules have been added to your %s file.' ), '.htaccess' );
  751. } else {
  752. /* translators: %s: .htaccess */
  753. $htaccess_rules_string = sprintf( __( 'Your %s file contains only core WordPress features.' ), '.htaccess' );
  754. }
  755. $info['wp-server']['fields']['htaccess_extra_rules'] = array(
  756. 'label' => __( '.htaccess rules' ),
  757. 'value' => $htaccess_rules_string,
  758. 'debug' => $filtered_htaccess_content,
  759. );
  760. }
  761. // Populate the database debug fields.
  762. if ( is_resource( $wpdb->dbh ) ) {
  763. // Old mysql extension.
  764. $extension = 'mysql';
  765. } elseif ( is_object( $wpdb->dbh ) ) {
  766. // mysqli or PDO.
  767. $extension = get_class( $wpdb->dbh );
  768. } else {
  769. // Unknown sql extension.
  770. $extension = null;
  771. }
  772. $server = $wpdb->get_var( 'SELECT VERSION()' );
  773. if ( isset( $wpdb->use_mysqli ) && $wpdb->use_mysqli ) {
  774. $client_version = $wpdb->dbh->client_info;
  775. } else {
  776. // phpcs:ignore WordPress.DB.RestrictedFunctions.mysql_mysql_get_client_info,PHPCompatibility.Extensions.RemovedExtensions.mysql_DeprecatedRemoved
  777. if ( preg_match( '|[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}|', mysql_get_client_info(), $matches ) ) {
  778. $client_version = $matches[0];
  779. } else {
  780. $client_version = null;
  781. }
  782. }
  783. $info['wp-database']['fields']['extension'] = array(
  784. 'label' => __( 'Extension' ),
  785. 'value' => $extension,
  786. );
  787. $info['wp-database']['fields']['server_version'] = array(
  788. 'label' => __( 'Server version' ),
  789. 'value' => $server,
  790. );
  791. $info['wp-database']['fields']['client_version'] = array(
  792. 'label' => __( 'Client version' ),
  793. 'value' => $client_version,
  794. );
  795. $info['wp-database']['fields']['database_user'] = array(
  796. 'label' => __( 'Database username' ),
  797. 'value' => $wpdb->dbuser,
  798. 'private' => true,
  799. );
  800. $info['wp-database']['fields']['database_host'] = array(
  801. 'label' => __( 'Database host' ),
  802. 'value' => $wpdb->dbhost,
  803. 'private' => true,
  804. );
  805. $info['wp-database']['fields']['database_name'] = array(
  806. 'label' => __( 'Database name' ),
  807. 'value' => $wpdb->dbname,
  808. 'private' => true,
  809. );
  810. $info['wp-database']['fields']['database_prefix'] = array(
  811. 'label' => __( 'Table prefix' ),
  812. 'value' => $wpdb->prefix,
  813. 'private' => true,
  814. );
  815. $info['wp-database']['fields']['database_charset'] = array(
  816. 'label' => __( 'Database charset' ),
  817. 'value' => $wpdb->charset,
  818. 'private' => true,
  819. );
  820. $info['wp-database']['fields']['database_collate'] = array(
  821. 'label' => __( 'Database collation' ),
  822. 'value' => $wpdb->collate,
  823. 'private' => true,
  824. );
  825. $info['wp-database']['fields']['max_allowed_packet'] = array(
  826. 'label' => __( 'Max allowed packet size' ),
  827. 'value' => self::get_mysql_var( 'max_allowed_packet' ),
  828. );
  829. $info['wp-database']['fields']['max_connections'] = array(
  830. 'label' => __( 'Max connections number' ),
  831. 'value' => self::get_mysql_var( 'max_connections' ),
  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 to or modify the debug information shown on the Tools -> Site Health -> Info screen.
  1238. *
  1239. * Plugin or themes may wish to introduce their own debug information without creating
  1240. * additional admin pages. They can utilize this filter to introduce their own sections
  1241. * or add more data to existing sections.
  1242. *
  1243. * Array keys for sections added by core are all prefixed with `wp-`. Plugins and themes
  1244. * should use their own slug as a prefix, both for consistency as well as avoiding
  1245. * key collisions. Note that the array keys are used as labels for the copied data.
  1246. *
  1247. * All strings are expected to be plain text except `$description` that can contain
  1248. * inline HTML tags (see below).
  1249. *
  1250. * @since 5.2.0
  1251. *
  1252. * @param array $args {
  1253. * The debug information to be added to the core information page.
  1254. *
  1255. * This is an associative multi-dimensional array, up to three levels deep.
  1256. * The topmost array holds the sections, keyed by section ID.
  1257. *
  1258. * @type array ...$0 {
  1259. * Each section has a `$fields` associative array (see below), and each `$value` in `$fields`
  1260. * can be another associative array of name/value pairs when there is more structured data
  1261. * to display.
  1262. *
  1263. * @type string $label Required. The title for this section of the debug output.
  1264. * @type string $description Optional. A description for your information section which
  1265. * may contain basic HTML markup, inline tags only as it is
  1266. * outputted in a paragraph.
  1267. * @type bool $show_count Optional. If set to `true`, the amount of fields will be included
  1268. * in the title for this section. Default false.
  1269. * @type bool $private Optional. If set to `true`, the section and all associated fields
  1270. * will be excluded from the copied data. Default false.
  1271. * @type array $fields {
  1272. * Required. An associative array containing the fields to be displayed in the section,
  1273. * keyed by field ID.
  1274. *
  1275. * @type array ...$0 {
  1276. * An associative array containing the data to be displayed for the field.
  1277. *
  1278. * @type string $label Required. The label for this piece of information.
  1279. * @type mixed $value Required. The output that is displayed for this field.
  1280. * Text should be translated. Can be an associative array
  1281. * that is displayed as name/value pairs.
  1282. * Accepted types: `string|int|float|(string|int|float)[]`.
  1283. * @type string $debug Optional. The output that is used for this field when
  1284. * the user copies the data. It should be more concise and
  1285. * not translated. If not set, the content of `$value`
  1286. * is used. Note that the array keys are used as labels
  1287. * for the copied data.
  1288. * @type bool $private Optional. If set to `true`, the field will be excluded
  1289. * from the copied data, allowing you to show, for example,
  1290. * API keys here. Default false.
  1291. * }
  1292. * }
  1293. * }
  1294. * }
  1295. */
  1296. $info = apply_filters( 'debug_information', $info );
  1297. return $info;
  1298. }
  1299. /**
  1300. * Returns the value of a MySQL system variable.
  1301. *
  1302. * @since 5.9.0
  1303. *
  1304. * @global wpdb $wpdb WordPress database abstraction object.
  1305. *
  1306. * @param string $mysql_var Name of the MySQL system variable.
  1307. * @return string|null The variable value on success. Null if the variable does not exist.
  1308. */
  1309. public static function get_mysql_var( $mysql_var ) {
  1310. global $wpdb;
  1311. $result = $wpdb->get_row(
  1312. $wpdb->prepare( 'SHOW VARIABLES LIKE %s', $mysql_var ),
  1313. ARRAY_A
  1314. );
  1315. if ( ! empty( $result ) && array_key_exists( 'Value', $result ) ) {
  1316. return $result['Value'];
  1317. }
  1318. return null;
  1319. }
  1320. /**
  1321. * Format the information gathered for debugging, in a manner suitable for copying to a forum or support ticket.
  1322. *
  1323. * @since 5.2.0
  1324. *
  1325. * @param array $info_array Information gathered from the `WP_Debug_Data::debug_data()` function.
  1326. * @param string $data_type The data type to return, either 'info' or 'debug'.
  1327. * @return string The formatted data.
  1328. */
  1329. public static function format( $info_array, $data_type ) {
  1330. $return = "`\n";
  1331. foreach ( $info_array as $section => $details ) {
  1332. // Skip this section if there are no fields, or the section has been declared as private.
  1333. if ( empty( $details['fields'] ) || ( isset( $details['private'] ) && $details['private'] ) ) {
  1334. continue;
  1335. }
  1336. $section_label = 'debug' === $data_type ? $section : $details['label'];
  1337. $return .= sprintf(
  1338. "### %s%s ###\n\n",
  1339. $section_label,
  1340. ( isset( $details['show_count'] ) && $details['show_count'] ? sprintf( ' (%d)', count( $details['fields'] ) ) : '' )
  1341. );
  1342. foreach ( $details['fields'] as $field_name => $field ) {
  1343. if ( isset( $field['private'] ) && true === $field['private'] ) {
  1344. continue;
  1345. }
  1346. if ( 'debug' === $data_type && isset( $field['debug'] ) ) {
  1347. $debug_data = $field['debug'];
  1348. } else {
  1349. $debug_data = $field['value'];
  1350. }
  1351. // Can be array, one level deep only.
  1352. if ( is_array( $debug_data ) ) {
  1353. $value = '';
  1354. foreach ( $debug_data as $sub_field_name => $sub_field_value ) {
  1355. $value .= sprintf( "\n\t%s: %s", $sub_field_name, $sub_field_value );
  1356. }
  1357. } elseif ( is_bool( $debug_data ) ) {
  1358. $value = $debug_data ? 'true' : 'false';
  1359. } elseif ( empty( $debug_data ) && '0' !== $debug_data ) {
  1360. $value = 'undefined';
  1361. } else {
  1362. $value = $debug_data;
  1363. }
  1364. if ( 'debug' === $data_type ) {
  1365. $label = $field_name;
  1366. } else {
  1367. $label = $field['label'];
  1368. }
  1369. $return .= sprintf( "%s: %s\n", $label, $value );
  1370. }
  1371. $return .= "\n";
  1372. }
  1373. $return .= '`';
  1374. return $return;
  1375. }
  1376. /**
  1377. * Fetch the total size of all the database tables for the active database user.
  1378. *
  1379. * @since 5.2.0
  1380. *
  1381. * @return int The size of the database, in bytes.
  1382. */
  1383. public static function get_database_size() {
  1384. global $wpdb;
  1385. $size = 0;
  1386. $rows = $wpdb->get_results( 'SHOW TABLE STATUS', ARRAY_A );
  1387. if ( $wpdb->num_rows > 0 ) {
  1388. foreach ( $rows as $row ) {
  1389. $size += $row['Data_length'] + $row['Index_length'];
  1390. }
  1391. }
  1392. return (int) $size;
  1393. }
  1394. /**
  1395. * Fetch the sizes of the WordPress directories: `wordpress` (ABSPATH), `plugins`, `themes`, and `uploads`.
  1396. * Intended to supplement the array returned by `WP_Debug_Data::debug_data()`.
  1397. *
  1398. * @since 5.2.0
  1399. *
  1400. * @return array The sizes of the directories, also the database size and total installation size.
  1401. */
  1402. public static function get_sizes() {
  1403. $size_db = self::get_database_size();
  1404. $upload_dir = wp_get_upload_dir();
  1405. /*
  1406. * We will be using the PHP max execution time to prevent the size calculations
  1407. * from causing a timeout. The default value is 30 seconds, and some
  1408. * hosts do not allow you to read configuration values.
  1409. */
  1410. if ( function_exists( 'ini_get' ) ) {
  1411. $max_execution_time = ini_get( 'max_execution_time' );
  1412. }
  1413. // The max_execution_time defaults to 0 when PHP runs from cli.
  1414. // We still want to limit it below.
  1415. if ( empty( $max_execution_time ) ) {
  1416. $max_execution_time = 30;
  1417. }
  1418. if ( $max_execution_time > 20 ) {
  1419. // If the max_execution_time is set to lower than 20 seconds, reduce it a bit to prevent
  1420. // edge-case timeouts that may happen after the size loop has finished running.
  1421. $max_execution_time -= 2;
  1422. }
  1423. // Go through the various installation directories and calculate their sizes.
  1424. // No trailing slashes.
  1425. $paths = array(
  1426. 'wordpress_size' => untrailingslashit( ABSPATH ),
  1427. 'themes_size' => get_theme_root(),
  1428. 'plugins_size' => WP_PLUGIN_DIR,
  1429. 'uploads_size' => $upload_dir['basedir'],
  1430. );
  1431. $exclude = $paths;
  1432. unset( $exclude['wordpress_size'] );
  1433. $exclude = array_values( $exclude );
  1434. $size_total = 0;
  1435. $all_sizes = array();
  1436. // Loop over all the directories we want to gather the sizes for.
  1437. foreach ( $paths as $name => $path ) {
  1438. $dir_size = null; // Default to timeout.
  1439. $results = array(
  1440. 'path' => $path,
  1441. 'raw' => 0,
  1442. );
  1443. if ( microtime( true ) - WP_START_TIMESTAMP < $max_execution_time ) {
  1444. if ( 'wordpress_size' === $name ) {
  1445. $dir_size = recurse_dirsize( $path, $exclude, $max_execution_time );
  1446. } else {
  1447. $dir_size = recurse_dirsize( $path, null, $max_execution_time );
  1448. }
  1449. }
  1450. if ( false === $dir_size ) {
  1451. // Error reading.
  1452. $results['size'] = __( 'The size cannot be calculated. The directory is not accessible. Usually caused by invalid permissions.' );
  1453. $results['debug'] = 'not accessible';
  1454. // Stop total size calculation.
  1455. $size_total = null;
  1456. } elseif ( null === $dir_size ) {
  1457. // Timeout.
  1458. $results['size'] = __( 'The directory size calculation has timed out. Usually caused by a very large number of sub-directories and files.' );
  1459. $results['debug'] = 'timeout while calculating size';
  1460. // Stop total size calculation.
  1461. $size_total = null;
  1462. } else {
  1463. if ( null !== $size_total ) {
  1464. $size_total += $dir_size;
  1465. }
  1466. $results['raw'] = $dir_size;
  1467. $results['size'] = size_format( $dir_size, 2 );
  1468. $results['debug'] = $results['size'] . " ({$dir_size} bytes)";
  1469. }
  1470. $all_sizes[ $name ] = $results;
  1471. }
  1472. if ( $size_db > 0 ) {
  1473. $database_size = size_format( $size_db, 2 );
  1474. $all_sizes['database_size'] = array(
  1475. 'raw' => $size_db,
  1476. 'size' => $database_size,
  1477. 'debug' => $database_size . " ({$size_db} bytes)",
  1478. );
  1479. } else {
  1480. $all_sizes['database_size'] = array(
  1481. 'size' => __( 'Not available' ),
  1482. 'debug' => 'not available',
  1483. );
  1484. }
  1485. if ( null !== $size_total && $size_db > 0 ) {
  1486. $total_size = $size_total + $size_db;
  1487. $total_size_mb = size_format( $total_size, 2 );
  1488. $all_sizes['total_size'] = array(
  1489. 'raw' => $total_size,
  1490. 'size' => $total_size_mb,
  1491. 'debug' => $total_size_mb . " ({$total_size} bytes)",
  1492. );
  1493. } else {
  1494. $all_sizes['total_size'] = array(
  1495. 'size' => __( 'Total size is not available. Some errors were encountered when determining the size of your installation.' ),
  1496. 'debug' => 'not available',
  1497. );
  1498. }
  1499. return $all_sizes;
  1500. }
  1501. }