WordPress.org

Make WordPress Core


Ignore:
Timestamp:
01/12/2020 01:31:49 PM (17 months ago)
Author:
SergeyBiryukov
Message:

Site Health: Introduce Site Health Status dashboard widget.

The widget informs administrators of any potential issues that should be addressed to improve the performance or security of their website, and directs them to the Site Health screen for more details.

Props Clorith, hedgefield, guddu1315.
See #47606.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/dashboard.php

    r47016 r47063  
    4141        add_filter( 'postbox_classes_dashboard_dashboard_php_nag', 'dashboard_php_nag_class' );
    4242        wp_add_dashboard_widget( 'dashboard_php_nag', __( 'PHP Update Required' ), 'wp_dashboard_php_nag' );
     43    }
     44
     45    // Site Health.
     46    if ( current_user_can( 'view_site_health_checks' ) ) {
     47        if ( ! class_exists( 'WP_Site_Health' ) ) {
     48            require_once( ABSPATH . 'wp-admin/includes/class-wp-site-health.php' );
     49        }
     50
     51        WP_Site_Health::initialize();
     52
     53        wp_enqueue_style( 'site-health' );
     54        wp_enqueue_script( 'site-health' );
     55
     56        wp_add_dashboard_widget( 'dashboard_site_health', __( 'Site Health Status' ), 'wp_dashboard_site_health' );
    4357    }
    4458
     
    17491763
    17501764    return $classes;
     1765}
     1766
     1767/**
     1768 * Displays the Site Health Status widget.
     1769 *
     1770 * @since 5.4.0
     1771 */
     1772function wp_dashboard_site_health() {
     1773    $get_issues = get_transient( 'health-check-site-status-result' );
     1774
     1775    $issue_counts = new stdClass();
     1776
     1777    if ( false !== $get_issues ) {
     1778        $issue_counts = json_decode( $get_issues );
     1779    }
     1780
     1781    if ( ! is_object( $issue_counts ) || empty( $issue_counts ) ) {
     1782        $issue_counts = (object) array(
     1783            'good'        => 0,
     1784            'recommended' => 0,
     1785            'critical'    => 0,
     1786        );
     1787    }
     1788
     1789    $issues_total = $issue_counts->recommended + $issue_counts->critical;
     1790    ?>
     1791    <div class="health-check-title-section site-health-progress-wrapper loading hide-if-no-js">
     1792        <div class="site-health-progress">
     1793            <svg role="img" aria-hidden="true" focusable="false" width="100%" height="100%" viewBox="0 0 200 200" version="1.1" xmlns="http://www.w3.org/2000/svg">
     1794                <circle r="90" cx="100" cy="100" fill="transparent" stroke-dasharray="565.48" stroke-dashoffset="0"></circle>
     1795                <circle id="bar" r="90" cx="100" cy="100" fill="transparent" stroke-dasharray="565.48" stroke-dashoffset="0"></circle>
     1796            </svg>
     1797        </div>
     1798        <div class="site-health-progress-label">
     1799            <?php if ( false === $get_issues ) : ?>
     1800                <?php _e( 'No information yet&hellip;' ); ?>
     1801            <?php else : ?>
     1802                <?php _e( 'Results are still loading&hellip;' ); ?>
     1803            <?php endif; ?>
     1804        </div>
     1805    </div>
     1806
     1807    <?php if ( false === $get_issues ) : ?>
     1808        <p>
     1809            <?php _e( 'No Site Health information has been gathered yet, you can do so by visiting the Site Health screen, alternatively the checks will run periodically.' ); ?>
     1810        </p>
     1811
     1812        <p>
     1813            <?php
     1814            printf(
     1815                /* translators: %s: URL to Site Health screen. */
     1816                __( '<a href="%s">Visit the Site Health screen</a> to gather information on about your site.' ),
     1817                esc_url( admin_url( 'site-health.php' ) )
     1818            );
     1819            ?>
     1820        </p>
     1821
     1822    <?php else : ?>
     1823        <p>
     1824            <?php if ( $issue_counts->critical > 0 ) : ?>
     1825                <?php _e( 'Your site has critical issues that should be addressed as soon as possible to improve the performance or security of your website.' ); ?>
     1826            <?php elseif ( $issues_total <= 0 ) : ?>
     1827                <?php _e( 'Great job! Your site currently passes all site health checks.' ); ?>
     1828            <?php else : ?>
     1829                <?php _e( 'Your site health is looking quite good, but there are still some things you can do to improve the performance and security of your website.' ); ?>
     1830            <?php endif; ?>
     1831        </p>
     1832    <?php endif; ?>
     1833
     1834    <?php if ( $issues_total > 0 && false !== $get_issues ) : ?>
     1835        <p>
     1836            <?php
     1837            printf(
     1838                /* translators: 1: Number of issues. 2: URL to Site Health screen. */
     1839                __( 'Take a look at the <strong>%1$d items</strong> on the <a href="%2$s">Site Health Status screen</a>.' ),
     1840                $issues_total,
     1841                esc_url( admin_url( 'site-health.php' ) )
     1842            );
     1843            ?>
     1844        </p>
     1845    <?php endif; ?>
     1846
     1847    <?php
    17511848}
    17521849
Note: See TracChangeset for help on using the changeset viewer.