<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[45176] trunk/src: Site health: Load the "Info" tab immediately and notify the user while gathering site data.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/45176">45176</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/45176","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>azaozz</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2019-04-12 19:23:13 +0000 (Fri, 12 Apr 2019)</dd>
</dl>

<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Site health: Load the "Info" tab immediately and notify the user while gathering site data. Changes the Info tab to work similarly to the Status tab: it does separate request to fetch the directories sizes and doesn't "block" the loading of the page.

Props xkon, afercia, Clorith, azaozz.
See <a href="https://core.trac.wordpress.org/ticket/46707">#46707</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcjs_enqueuesadminsitehealthjs">trunk/src/js/_enqueues/admin/site-health.js</a></li>
<li><a href="#trunksrcwpadminadminajaxphp">trunk/src/wp-admin/admin-ajax.php</a></li>
<li><a href="#trunksrcwpadmincsssitehealthcss">trunk/src/wp-admin/css/site-health.css</a></li>
<li><a href="#trunksrcwpadminincludesajaxactionsphp">trunk/src/wp-admin/includes/ajax-actions.php</a></li>
<li><a href="#trunksrcwpadminincludesclasswpdebugdataphp">trunk/src/wp-admin/includes/class-wp-debug-data.php</a></li>
<li><a href="#trunksrcwpadminsitehealthinfophp">trunk/src/wp-admin/site-health-info.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcjs_enqueuesadminsitehealthjs"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/js/_enqueues/admin/site-health.js</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/js/_enqueues/admin/site-health.js       2019-04-12 19:04:13 UTC (rev 45175)
+++ trunk/src/js/_enqueues/admin/site-health.js 2019-04-12 19:23:13 UTC (rev 45176)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -9,8 +9,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> jQuery( document ).ready( function( $ ) {
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        var data;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
</del><span class="cx" style="display: block; padding: 0 10px">         var clipboard = new ClipboardJS( '.site-health-copy-buttons .copy-button' );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        var isDebugTab = $( '.health-check-body.health-check-debug-tab' ).length;
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        // Debug information copy section.
</span><span class="cx" style="display: block; padding: 0 10px">        clipboard.on( 'success', function( e ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -118,16 +118,18 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $progressCount.text( val + '%' );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $.post(
-                       ajaxurl,
-                       {
-                               'action': 'health-check-site-status-result',
-                               '_wpnonce': SiteHealth.nonce.site_status_result,
-                               'counts': SiteHealth.site_status.issues
-                       }
-               );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( ! isDebugTab ) {
+                       $.post(
+                               ajaxurl,
+                               {
+                                       'action': 'health-check-site-status-result',
+                                       '_wpnonce': SiteHealth.nonce.site_status_result,
+                                       'counts': SiteHealth.site_status.issues
+                               }
+                       );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                wp.a11y.speak( SiteHealth.string.site_health_complete_screen_reader.replace( '%s', val + '%' ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 wp.a11y.speak( SiteHealth.string.site_health_complete_screen_reader.replace( '%s', val + '%' ) );
+               }
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -171,7 +173,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        if ( 'undefined' !== typeof SiteHealth ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( 'undefined' !== typeof SiteHealth && ! isDebugTab ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                 if ( 0 === SiteHealth.site_status.direct.length && 0 === SiteHealth.site_status.async.length ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        RecalculateProgression();
</span><span class="cx" style="display: block; padding: 0 10px">                } else {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -209,4 +211,77 @@
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        function getDirectorySizes() {
+               var data = {
+                       action: 'health-check-get-sizes',
+                       _wpnonce: SiteHealth.nonce.site_status_result
+               };
+
+               var timestamp = ( new Date().getTime() );
+
+               // After 3 seconds announce that we're still waiting for directory sizes.
+               var timeout = window.setTimeout( function() {
+                       wp.a11y.speak( SiteHealth.string.please_wait );
+               }, 3000 );
+
+               $.post( {
+                       type: 'POST',
+                       url: ajaxurl,
+                       data: data,
+                       dataType: 'json'
+               } ).done( function( response ) {
+                       updateDirSizes( response.data || {} );
+               } ).always( function() {
+                       var delay = ( new Date().getTime() ) - timestamp;
+
+                       $( '.health-check-wp-paths-sizes.spinner' ).css( 'visibility', 'hidden' );
+                       RecalculateProgression();
+
+                       if ( delay > 3000  ) {
+                               // We have announced that we're waiting.
+                               // Announce that we're ready after giving at least 3 seconds for the first announcement
+                               // to be read out, or the two may collide.
+                               if ( delay > 6000 ) {
+                                       delay = 0;
+                               } else {
+                                       delay = 6500 - delay;
+                               }
+
+                               window.setTimeout( function() {
+                                       wp.a11y.speak( SiteHealth.string.site_health_complete );
+                               }, delay );
+                       } else {
+                               // Cancel the announcement.
+                               window.clearTimeout( timeout );
+                       }
+               } );
+       }
+
+       function updateDirSizes( data ) {
+               var copyButton = $( 'button.button.copy-button' );
+               var clipdoardText = copyButton.attr( 'data-clipboard-text' );
+
+               $.each( data, function( name, value ) {
+                       var text = value.debug || value.size;
+
+                       if ( typeof text !== 'undefined' ) {
+                               clipdoardText = clipdoardText.replace( name + ': not calculated', name + ': ' + text );
+                       }
+               } );
+
+               copyButton.attr( 'data-clipboard-text', clipdoardText );
+
+               $( '#health-check-accordion-block-wp-paths-sizes' ).find( 'td[class]' ).each( function( i, element ) {
+                       var td = $( element );
+                       var name = td.attr( 'class' );
+
+                       if ( data.hasOwnProperty( name ) && data[ name ].size ) {
+                               td.text( data[ name ].size );
+                       }
+               } );
+       }
+
+       if ( isDebugTab ) {
+               getDirectorySizes();
+       }
</ins><span class="cx" style="display: block; padding: 0 10px"> } );
</span></span></pre></div>
<a id="trunksrcwpadminadminajaxphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/admin-ajax.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/admin-ajax.php 2019-04-12 19:04:13 UTC (rev 45175)
+++ trunk/src/wp-admin/admin-ajax.php   2019-04-12 19:23:13 UTC (rev 45176)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -136,6 +136,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">        'health-check-is-in-debug-mode',
</span><span class="cx" style="display: block; padding: 0 10px">        'health-check-background-updates',
</span><span class="cx" style="display: block; padding: 0 10px">        'health-check-loopback-requests',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        'health-check-get-sizes',
</ins><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px"> // Deprecated
</span></span></pre></div>
<a id="trunksrcwpadmincsssitehealthcss"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/css/site-health.css</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/css/site-health.css    2019-04-12 19:04:13 UTC (rev 45175)
+++ trunk/src/wp-admin/css/site-health.css      2019-04-12 19:23:13 UTC (rev 45176)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -377,6 +377,13 @@
</span><span class="cx" style="display: block; padding: 0 10px">        margin-left: 22px;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+.health-check-wp-paths-sizes.spinner {
+       position: absolute;
+       visibility: visible;
+       float: none;
+       margin: 0 4px;
+}
+
</ins><span class="cx" style="display: block; padding: 0 10px"> @media screen and (max-width: 782px) {
</span><span class="cx" style="display: block; padding: 0 10px">        .health-check-body {
</span><span class="cx" style="display: block; padding: 0 10px">                margin: 0 12px;
</span></span></pre></div>
<a id="trunksrcwpadminincludesajaxactionsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/includes/ajax-actions.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/includes/ajax-actions.php      2019-04-12 19:04:13 UTC (rev 45175)
+++ trunk/src/wp-admin/includes/ajax-actions.php        2019-04-12 19:23:13 UTC (rev 45176)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -4958,3 +4958,52 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        wp_send_json_success();
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+/**
+ * Ajax handler for site health check to get directories and database sizes.
+ *
+ * @since 5.2.0
+ */
+function wp_ajax_health_check_get_sizes() {
+       check_ajax_referer( 'health-check-site-status-result' );
+
+       if ( ! current_user_can( 'install_plugins' ) ) {
+               wp_send_json_error();
+       }
+
+       if ( ! class_exists( 'WP_Debug_Data' ) ) {
+               require_once( ABSPATH . 'wp-admin/includes/class-wp-debug-data.php' );
+       }
+
+       $sizes_data = WP_Debug_Data::get_sizes();
+       $all_sizes  = array();
+
+       foreach ( $sizes_data as $name => $value ) {
+               $name = sanitize_text_field( $name );
+               $data = array();
+
+               if ( isset( $value['size'] ) ) {
+                       if ( is_string( $value['size'] ) ) {
+                               $data['size'] = sanitize_text_field( $value['size'] );
+                       } else {
+                               $data['size'] = (int) $value['size'];
+                       }
+               }
+
+               if ( isset( $value['debug'] ) ) {
+                       if ( is_string( $value['debug'] ) ) {
+                               $data['debug'] = sanitize_text_field( $value['debug'] );
+                       } else {
+                               $data['debug'] = (int) $value['debug'];
+                       }
+               }
+
+               $all_sizes[ $name ] = $data;
+       }
+
+       if ( isset( $all_sizes['total_size']['debug'] ) && 'not available' === $all_sizes['total_size']['debug'] ) {
+               wp_send_json_error( $all_sizes );
+       }
+
+       wp_send_json_success( $all_sizes );
+}
</ins></span></pre></div>
<a id="trunksrcwpadminincludesclasswpdebugdataphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/includes/class-wp-debug-data.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/includes/class-wp-debug-data.php       2019-04-12 19:04:13 UTC (rev 45175)
+++ trunk/src/wp-admin/includes/class-wp-debug-data.php 2019-04-12 19:23:13 UTC (rev 45176)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -387,110 +387,21 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $size_db = WP_Debug_Data::get_database_size();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $not_calculated = __( 'Not calculated' );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                /*
-                * We will be using the PHP max execution time to prevent the size calculations
-                * from causing a timeout. The default value is 30 seconds, and some
-                * hosts do not allow you to read configuration values.
-                */
-               if ( function_exists( 'ini_get' ) ) {
-                       $max_execution_time = ini_get( 'max_execution_time' );
-               }
-
-               // The max_execution_time defaults to 0 when PHP runs from cli.
-               // We still want to limit it below.
-               if ( empty( $max_execution_time ) ) {
-                       $max_execution_time = 30;
-               }
-
-               // Here 20 seconds is a "sensible default" for how long to make the user wait for the directory size calculation.
-               // When testing 20 seconds seem enough in nearly all cases. The remaining edge cases are likely testing or development sites
-               // that have very large number of files, for example `node_modules` in plugins or themes, etc.
-               if ( $max_execution_time > 20 ) {
-                       $max_execution_time = 20;
-               } elseif ( $max_execution_time > 10 ) {
-                       // If the max_execution_time is set to lower than 20 seconds, reduce it a bit to prevent
-                       // edge-case timeouts that may happen after the size loop has finished running.
-                       $max_execution_time -= 1;
-               }
-
-               // Go through the various installation directories and calculate their sizes.
-               $size_directories = array(
-                       'wordpress' => array(
-                               'path' => ABSPATH,
-                               'size' => 0,
-                       ),
-                       'themes'    => array(
-                               'path' => trailingslashit( get_theme_root() ),
-                               'size' => 0,
-                       ),
-                       'plugins'   => array(
-                               'path' => trailingslashit( WP_PLUGIN_DIR ),
-                               'size' => 0,
-                       ),
-                       'uploads'   => array(
-                               'path' => $upload_dir['basedir'],
-                               'size' => 0,
-                       ),
-               );
-
-               $size_total = 0;
-
-               // Loop over all the directories we want to gather the sizes for.
-               foreach ( $size_directories as $size => $attributes ) {
-                       $dir_size = null; // Default to timeout.
-
-                       if ( microtime( true ) - WP_START_TIMESTAMP < $max_execution_time ) {
-                               $dir_size = get_dirsize( $attributes['path'], $max_execution_time );
-                       }
-
-                       if ( false === $dir_size ) {
-                               // Error reading.
-                               $size_directories[ $size ]['size']  = __( 'The size cannot be calculated. The directory is not accessible. Usually caused by invalid permissions.' );
-                               $size_directories[ $size ]['debug'] = 'not accessible';
-
-                               // Stop total size calculation.
-                               $size_total = null;
-                       } elseif ( null === $dir_size ) {
-                               // Timeout.
-                               $size_directories[ $size ]['size']  = __( 'The directory size calculation has timed out. Usually caused by a very large number of sub-directories and files.' );
-                               $size_directories[ $size ]['debug'] = 'timeout while calculating size';
-
-                               // Stop total size calculation.
-                               $size_total = null;
-                       } else {
-                               $is_subdir = ( strpos( $size_directories[ $size ]['path'], ABSPATH ) === 0 );
-
-                               // phpcs:ignore WordPress.WP.CapitalPDangit.Misspelled
-                               if ( null !== $size_total && ( 'wordpress' === $size || ! $is_subdir ) ) {
-                                       $size_total += $dir_size;
-                               }
-
-                               $size_directories[ $size ]['size']  = size_format( $dir_size, 2 );
-                               $size_directories[ $size ]['debug'] = $size_directories[ $size ]['size'];
-                       }
-               }
-
-               if ( null !== $size_total && $size_db > 0 ) {
-                       $size_total = size_format( $size_total + $size_db, 2 );
-               } else {
-                       $size_total = 0;
-               }
-
</del><span class="cx" style="display: block; padding: 0 10px">                 $info['wp-paths-sizes']['fields'] = array(
</span><span class="cx" style="display: block; padding: 0 10px">                        'uploads_path'       => array(
</span><span class="cx" style="display: block; padding: 0 10px">                                'label' => __( 'Uploads Directory Location' ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                'value' => $size_directories['uploads']['path'],
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         'value' => $upload_dir['basedir'],
</ins><span class="cx" style="display: block; padding: 0 10px">                         ),
</span><span class="cx" style="display: block; padding: 0 10px">                        'uploads_size'       => array(
</span><span class="cx" style="display: block; padding: 0 10px">                                'label' => __( 'Uploads Directory Size' ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                'value' => $size_directories['uploads']['size'],
-                               'debug' => $size_directories['uploads']['debug'],
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         'value' => $not_calculated,
+                               'debug' => 'not calculated',
</ins><span class="cx" style="display: block; padding: 0 10px">                         ),
</span><span class="cx" style="display: block; padding: 0 10px">                        'themes_path'        => array(
</span><span class="cx" style="display: block; padding: 0 10px">                                'label' => __( 'Themes Directory Location' ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                'value' => $size_directories['themes']['path'],
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         'value' => trailingslashit( get_theme_root() ),
</ins><span class="cx" style="display: block; padding: 0 10px">                         ),
</span><span class="cx" style="display: block; padding: 0 10px">                        'current_theme_path' => array(
</span><span class="cx" style="display: block; padding: 0 10px">                                'label' => __( 'Current Theme Directory' ),
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -498,35 +409,36 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        ),
</span><span class="cx" style="display: block; padding: 0 10px">                        'themes_size'        => array(
</span><span class="cx" style="display: block; padding: 0 10px">                                'label' => __( 'Themes Directory Size' ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                'value' => $size_directories['themes']['size'],
-                               'debug' => $size_directories['themes']['debug'],
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         'value' => $not_calculated,
+                               'debug' => 'not calculated',
</ins><span class="cx" style="display: block; padding: 0 10px">                         ),
</span><span class="cx" style="display: block; padding: 0 10px">                        'plugins_path'       => array(
</span><span class="cx" style="display: block; padding: 0 10px">                                'label' => __( 'Plugins Directory Location' ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                'value' => $size_directories['plugins']['path'],
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         'value' => trailingslashit( WP_PLUGIN_DIR ),
</ins><span class="cx" style="display: block; padding: 0 10px">                         ),
</span><span class="cx" style="display: block; padding: 0 10px">                        'plugins_size'       => array(
</span><span class="cx" style="display: block; padding: 0 10px">                                'label' => __( 'Plugins Directory Size' ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                'value' => $size_directories['plugins']['size'],
-                               'debug' => $size_directories['plugins']['debug'],
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         'value' => $not_calculated,
+                               'debug' => 'not calculated',
</ins><span class="cx" style="display: block; padding: 0 10px">                         ),
</span><span class="cx" style="display: block; padding: 0 10px">                        'wordpress_path'     => array(
</span><span class="cx" style="display: block; padding: 0 10px">                                'label' => __( 'WordPress Directory Location' ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                'value' => $size_directories['wordpress']['path'],
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         'value' => ABSPATH,
</ins><span class="cx" style="display: block; padding: 0 10px">                         ),
</span><span class="cx" style="display: block; padding: 0 10px">                        'wordpress_size'     => array(
</span><span class="cx" style="display: block; padding: 0 10px">                                'label' => __( 'WordPress Directory Size' ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                'value' => $size_directories['wordpress']['size'],
-                               'debug' => $size_directories['wordpress']['debug'],
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         'value' => $not_calculated,
+                               'debug' => 'not calculated',
</ins><span class="cx" style="display: block; padding: 0 10px">                         ),
</span><span class="cx" style="display: block; padding: 0 10px">                        'database_size'      => array(
</span><span class="cx" style="display: block; padding: 0 10px">                                'label' => __( 'Database size' ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                'value' => size_format( $size_db, 2 ),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         'value' => $not_calculated,
+                               'debug' => 'not calculated',
</ins><span class="cx" style="display: block; padding: 0 10px">                         ),
</span><span class="cx" style="display: block; padding: 0 10px">                        'total_size'         => array(
</span><span class="cx" style="display: block; padding: 0 10px">                                'label' => __( 'Total installation size' ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                'value' => $size_total > 0 ? $size_total : __( 'Total size is not available. Some errors were encountered when determining the size of your installation.' ),
-                               'debug' => $size_total > 0 ? $size_total : 'not available',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         'value' => $not_calculated,
+                               'debug' => 'not calculated',
</ins><span class="cx" style="display: block; padding: 0 10px">                         ),
</span><span class="cx" style="display: block; padding: 0 10px">                );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1188,4 +1100,125 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                return (int) $size;
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+       /**
+        * Fetch the sizes of the WordPress directories: `wordpress` (ABSPATH), `plugins`, `themes`, and `uploads`.
+        * Intended to supplement the array returned by `WP_Debug_Data::debug_data()`.
+        *
+        * @since 5.2.0
+        *
+        * @return array The sizes of the directories, also the database size and total installation size.
+        */
+       public static function get_sizes() {
+               $size_db    = self::get_database_size();
+               $upload_dir = wp_get_upload_dir();
+
+               /*
+                * We will be using the PHP max execution time to prevent the size calculations
+                * from causing a timeout. The default value is 30 seconds, and some
+                * hosts do not allow you to read configuration values.
+                */
+               if ( function_exists( 'ini_get' ) ) {
+                       $max_execution_time = ini_get( 'max_execution_time' );
+               }
+
+               // The max_execution_time defaults to 0 when PHP runs from cli.
+               // We still want to limit it below.
+               if ( empty( $max_execution_time ) ) {
+                       $max_execution_time = 30;
+               }
+
+               if ( $max_execution_time > 20 ) {
+                       // If the max_execution_time is set to lower than 20 seconds, reduce it a bit to prevent
+                       // edge-case timeouts that may happen after the size loop has finished running.
+                       $max_execution_time -= 2;
+               }
+
+               // Go through the various installation directories and calculate their sizes.
+               $all_sizes = array(
+                       'wordpress_size' => array(
+                               'path' => ABSPATH,
+                               'size' => 0,
+                       ),
+                       'themes_size'    => array(
+                               'path' => trailingslashit( get_theme_root() ),
+                               'size' => 0,
+                       ),
+                       'plugins_size'   => array(
+                               'path' => trailingslashit( WP_PLUGIN_DIR ),
+                               'size' => 0,
+                       ),
+                       'uploads_size'   => array(
+                               'path' => $upload_dir['basedir'],
+                               'size' => 0,
+                       ),
+               );
+
+               $size_total = 0;
+
+               // Loop over all the directories we want to gather the sizes for.
+               foreach ( $all_sizes as $name => $attributes ) {
+                       $dir_size = null; // Default to timeout.
+
+                       if ( microtime( true ) - WP_START_TIMESTAMP < $max_execution_time ) {
+                               $dir_size = recurse_dirsize( $attributes['path'], null, $max_execution_time );
+                       }
+
+                       if ( false === $dir_size ) {
+                               // Error reading.
+                               $all_sizes[ $name ]['size']  = __( 'The size cannot be calculated. The directory is not accessible. Usually caused by invalid permissions.' );
+                               $all_sizes[ $name ]['debug'] = 'not accessible';
+
+                               // Stop total size calculation.
+                               $size_total = null;
+                       } elseif ( null === $dir_size ) {
+                               // Timeout.
+                               $all_sizes[ $name ]['size']  = __( 'The directory size calculation has timed out. Usually caused by a very large number of sub-directories and files.' );
+                               $all_sizes[ $name ]['debug'] = 'timeout while calculating size';
+
+                               // Stop total size calculation.
+                               $size_total = null;
+                       } else {
+                               $is_subdir = ( strpos( $attributes['path'], ABSPATH ) === 0 );
+
+                               // phpcs:ignore WordPress.WP.CapitalPDangit.Misspelled
+                               if ( null !== $size_total && ( 'wordpress_size' === $name || ! $is_subdir ) ) {
+                                       $size_total += $dir_size;
+                               }
+
+                               $all_sizes[ $name ]['size']  = size_format( $dir_size, 2 );
+                               $all_sizes[ $name ]['debug'] = $all_sizes[ $name ]['size'];
+                       }
+               }
+
+               if ( $size_db > 0 ) {
+                       $database_size = size_format( $size_db, 2 );
+
+                       $all_sizes['database_size'] = array(
+                               'size'  => $database_size,
+                               'debug' => $database_size,
+                       );
+               } else {
+                       $all_sizes['database_size'] = array(
+                               'size'  => __( 'Not available' ),
+                               'debug' => 'not available',
+                       );
+               }
+
+               if ( null !== $size_total && $size_db > 0 ) {
+                       $total_size = size_format( $size_total + $size_db, 2 );
+
+                       $all_sizes['total_size'] = array(
+                               'size'  => $total_size,
+                               'debug' => $total_size,
+                       );
+               } else {
+                       $all_sizes['total_size'] = array(
+                               'size'  => __( 'Total size is not available. Some errors were encountered when determining the size of your installation.' ),
+                               'debug' => 'not available',
+                       );
+               }
+
+               return $all_sizes;
+       }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="trunksrcwpadminsitehealthinfophp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/site-health-info.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/site-health-info.php   2019-04-12 19:04:13 UTC (rev 45175)
+++ trunk/src/wp-admin/site-health-info.php     2019-04-12 19:23:13 UTC (rev 45176)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -62,8 +62,9 @@
</span><span class="cx" style="display: block; padding: 0 10px">        <p><?php _e( 'The Site Health check requires JavaScript.' ); ?></p>
</span><span class="cx" style="display: block; padding: 0 10px"> </div>
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-<div class="health-check-body hide-if-no-js">
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<div class="health-check-body health-check-debug-tab hide-if-no-js">
</ins><span class="cx" style="display: block; padding: 0 10px">         <?php
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px">         WP_Debug_Data::check_for_updates();
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        $info = WP_Debug_Data::debug_data();
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -93,20 +94,36 @@
</span><span class="cx" style="display: block; padding: 0 10px">        <div id="health-check-debug" class="health-check-accordion">
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                <?php
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+               $sizes_fields = array( 'uploads_size', 'themes_size', 'plugins_size', 'wordpress_size', 'database_size', 'total_size' );
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 foreach ( $info as $section => $details ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        if ( ! isset( $details['fields'] ) || empty( $details['fields'] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                continue;
</span><span class="cx" style="display: block; padding: 0 10px">                        }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px">                         ?>
</span><span class="cx" style="display: block; padding: 0 10px">                        <h3 class="health-check-accordion-heading">
</span><span class="cx" style="display: block; padding: 0 10px">                                <button aria-expanded="false" class="health-check-accordion-trigger" aria-controls="health-check-accordion-block-<?php echo esc_attr( $section ); ?>" type="button">
</span><span class="cx" style="display: block; padding: 0 10px">                                        <span class="title">
</span><span class="cx" style="display: block; padding: 0 10px">                                                <?php echo esc_html( $details['label'] ); ?>
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                                <?php
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                                <?php if ( isset( $details['show_count'] ) && $details['show_count'] ) : ?>
-                                                       <?php printf( '(%d)', count( $details['fields'] ) ); ?>
-                                               <?php endif; ?>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                         if ( isset( $details['show_count'] ) && $details['show_count'] ) {
+                                                       printf( '(%d)', count( $details['fields'] ) );
+                                               }
+
+                                               ?>
</ins><span class="cx" style="display: block; padding: 0 10px">                                         </span>
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                        <?php
+
+                                       if ( 'wp-paths-sizes' === $section ) {
+                                               ?>
+                                               <span class="health-check-wp-paths-sizes spinner" title="<?php esc_attr_e( 'Calculating directory sizes. This may take a while&hellip;' ); ?>"></span>
+                                               <?php
+                                       }
+
+                                       ?>
</ins><span class="cx" style="display: block; padding: 0 10px">                                         <span class="icon"></span>
</span><span class="cx" style="display: block; padding: 0 10px">                                </button>
</span><span class="cx" style="display: block; padding: 0 10px">                        </h3>
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -113,46 +130,44 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                        <div id="health-check-accordion-block-<?php echo esc_attr( $section ); ?>" class="health-check-accordion-panel" hidden="hidden">
</span><span class="cx" style="display: block; padding: 0 10px">                                <?php
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+                               $kses_settings = array(
+                                       'a'      => array(
+                                               'href' => true,
+                                       ),
+                                       'strong' => true,
+                                       'em'     => true,
+                               );
+
</ins><span class="cx" style="display: block; padding: 0 10px">                                 if ( isset( $details['description'] ) && ! empty( $details['description'] ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        printf(
-                                               '<p>%s</p>',
-                                               wp_kses(
-                                                       $details['description'],
-                                                       array(
-                                                               'a'      => array(
-                                                                       'href' => true,
-                                                               ),
-                                                               'strong' => true,
-                                                               'em'     => true,
-                                                       )
-                                               )
-                                       );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                 printf( '<p>%s</p>', wp_kses( $details['description'], $kses_settings ) );
</ins><span class="cx" style="display: block; padding: 0 10px">                                 }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px">                                 ?>
</span><span class="cx" style="display: block; padding: 0 10px">                                <table class="widefat striped health-check-table" role="presentation">
</span><span class="cx" style="display: block; padding: 0 10px">                                        <tbody>
</span><span class="cx" style="display: block; padding: 0 10px">                                        <?php
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        foreach ( $details['fields'] as $field ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+                                       foreach ( $details['fields'] as $field_name => $field ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                                                 if ( is_array( $field['value'] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                                        $values = '<ul>';
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px">                                                         foreach ( $field['value'] as $name => $value ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                                                $values .= sprintf(
-                                                                       '<li>%s: %s</li>',
-                                                                       esc_html( $name ),
-                                                                       esc_html( $value )
-                                                               );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                                         $values .= sprintf( '<li>%s: %s</li>', esc_html( $name ), esc_html( $value ) );
</ins><span class="cx" style="display: block; padding: 0 10px">                                                         }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px">                                                         $values .= '</ul>';
</span><span class="cx" style="display: block; padding: 0 10px">                                                } else {
</span><span class="cx" style="display: block; padding: 0 10px">                                                        $values = esc_html( $field['value'] );
</span><span class="cx" style="display: block; padding: 0 10px">                                                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                                printf(
-                                                       '<tr><td>%s</td><td>%s</td></tr>',
-                                                       esc_html( $field['label'] ),
-                                                       $values
-                                               );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                         if ( in_array( $field_name, $sizes_fields, true ) ) {
+                                                       printf( '<tr><td>%s</td><td class="%s">%s</td></tr>', esc_html( $field['label'] ), esc_attr( $field_name ), $values );
+                                               } else {
+                                                       printf( '<tr><td>%s</td><td>%s</td></tr>', esc_html( $field['label'] ), $values );
+                                               }
</ins><span class="cx" style="display: block; padding: 0 10px">                                         }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px">                                         ?>
</span><span class="cx" style="display: block; padding: 0 10px">                                        </tbody>
</span><span class="cx" style="display: block; padding: 0 10px">                                </table>
</span></span></pre>
</div>
</div>

</body>
</html>