Admin: Introduce the Site Health screens.

The Site Health tool serves two purposes:
- Provide site owners with information to improve the performance, reliability, and security of their site.
- Collect comprehensive debug information about the site.

By encouraging site owners to maintain their site and adhere to modern best practices, we ultimately improve the software hygeine of both the WordPress ecosystem, and the open internet as a whole.

Props Clorith, hedgefield, melchoyce, xkon, karmatosed, jordesign, earnjam, ianbelanger, wpscholar, desrosj, pedromendonca, peterbooker, jcastaneda, garyj, soean, pento, timothyblynjacobs, zodiac1978, dgroddick, garrett-eclipse, netweb, tobifjellner, pixolin, afercia, joedolson, birgire.
See #46573.


git-svn-id: https://develop.svn.wordpress.org/trunk@44986 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Gary Pendergast 2019-03-23 03:54:16 +00:00
parent 7793e670b8
commit dad6b61cfb
13 changed files with 4430 additions and 0 deletions

View File

@ -263,6 +263,7 @@ module.exports = function(grunt) {
[ WORKING_DIR + 'wp-admin/js/tags-box.js' ]: [ './src/js/_enqueues/admin/tags-box.js' ],
[ WORKING_DIR + 'wp-admin/js/tags-suggest.js' ]: [ './src/js/_enqueues/admin/tags-suggest.js' ],
[ WORKING_DIR + 'wp-admin/js/tags.js' ]: [ './src/js/_enqueues/admin/tags.js' ],
[ WORKING_DIR + 'wp-admin/js/site-health.js' ]: [ './src/js/_enqueues/admin/site-health.js' ],
[ WORKING_DIR + 'wp-admin/js/theme-plugin-editor.js' ]: [ './src/js/_enqueues/wp/theme-plugin-editor.js' ],
[ WORKING_DIR + 'wp-admin/js/theme.js' ]: [ './src/js/_enqueues/wp/theme.js' ],
[ WORKING_DIR + 'wp-admin/js/updates.js' ]: [ './src/js/_enqueues/wp/updates.js' ],

View File

@ -0,0 +1,229 @@
/**
* Interactions used by the Site Health modules in WordPress.
*
* @output wp-admin/js/site-health.js
*/
/* global ajaxurl, SiteHealth, wp */
jQuery( document ).ready( function( $ ) {
var data;
// Debug information copy section.
$( '.health-check-copy-field' ).click( function( e ) {
var $textarea = $( '#system-information-' + $( this ).data( 'copy-field' ) + '-copy-field' ),
$wrapper = $( this ).closest( 'div' );
e.preventDefault();
$textarea.select();
if ( document.execCommand( 'copy' ) ) {
$( '.copy-field-success', $wrapper ).addClass( 'visible' );
$( this ).focus();
wp.a11y.speak( SiteHealth.string.site_info_copied, 'polite' );
}
} );
// Accordion handling in various areas.
$( '.health-check-accordion' ).on( 'click', '.health-check-accordion-trigger', function() {
var isExpanded = ( 'true' === $( this ).attr( 'aria-expanded' ) );
if ( isExpanded ) {
$( this ).attr( 'aria-expanded', 'false' );
$( '#' + $( this ).attr( 'aria-controls' ) ).attr( 'hidden', true );
} else {
$( this ).attr( 'aria-expanded', 'true' );
$( '#' + $( this ).attr( 'aria-controls' ) ).attr( 'hidden', false );
}
} );
$( '.health-check-accordion' ).on( 'keyup', '.health-check-accordion-trigger', function( e ) {
if ( '38' === e.keyCode.toString() ) {
$( '.health-check-accordion-trigger', $( this ).closest( 'dt' ).prevAll( 'dt' ) ).focus();
} else if ( '40' === e.keyCode.toString() ) {
$( '.health-check-accordion-trigger', $( this ).closest( 'dt' ).nextAll( 'dt' ) ).focus();
}
} );
// Site Health test handling.
$( '.site-health-view-passed' ).on( 'click', function() {
var goodIssuesWrapper = $( '#health-check-issues-good' );
goodIssuesWrapper.toggleClass( 'hidden' );
$( this ).attr( 'aria-expanded', ! goodIssuesWrapper.hasClass( 'hidden' ) );
} );
/**
* Append a new issue to the issue list.
*
* @since 5.2.0
*
* @param {Object} issue The issue data.
*/
function AppendIssue( issue ) {
var template = wp.template( 'health-check-issue' ),
issueWrapper = $( '#health-check-issues-' + issue.status ),
issueCounter = $( '.issue-count', issueWrapper );
SiteHealth.site_status.issues[ issue.status ]++;
issueCounter.text( SiteHealth.site_status.issues[ issue.status ] );
$( '.issues', '#health-check-issues-' + issue.status ).append( template( issue ) );
}
/**
* Update site health status indicator as asynchronous tests are run and returned.
*
* @since 5.2.0
*/
function RecalculateProgression() {
var r, c, pct;
var $progressBar = $( '#progressbar' );
var $circle = $( '#progressbar svg #bar' );
var totalTests = parseInt( SiteHealth.site_status.issues.good, 0 ) + parseInt( SiteHealth.site_status.issues.recommended, 0 ) + ( parseInt( SiteHealth.site_status.issues.critical, 0 ) * 1.5 );
var failedTests = parseInt( SiteHealth.site_status.issues.recommended, 0 ) + ( parseInt( SiteHealth.site_status.issues.critical, 0 ) * 1.5 );
var val = 100 - Math.ceil( ( failedTests / totalTests ) * 100 );
if ( 0 === totalTests ) {
$progressBar.addClass( 'hidden' );
return;
}
$progressBar.removeClass( 'loading' );
r = $circle.attr( 'r' );
c = Math.PI * ( r * 2 );
if ( 0 > val ) {
val = 0;
}
if ( 100 < val ) {
val = 100;
}
pct = ( ( 100 - val ) / 100 ) * c;
$circle.css({ strokeDashoffset: pct } );
if ( 1 > parseInt( SiteHealth.site_status.issues.critical, 0 ) ) {
$( '#health-check-issues-critical' ).addClass( 'hidden' );
}
if ( 1 > parseInt( SiteHealth.site_status.issues.recommended, 0 ) ) {
$( '#health-check-issues-recommended' ).addClass( 'hidden' );
}
if ( 50 <= val ) {
$circle.addClass( 'orange' ).removeClass( 'red' );
}
if ( 90 <= val ) {
$circle.addClass( 'green' ).removeClass( 'orange' );
}
if ( 100 === val ) {
$( '.site-status-all-clear' ).removeClass( 'hide' );
$( '.site-status-has-issues' ).addClass( 'hide' );
}
$progressBar.attr( 'data-pct', val );
$progressBar.attr( 'aria-valuenow', val );
$( '.health-check-body' ).attr( 'aria-hidden', false );
$.post(
ajaxurl,
{
'action': 'health-check-site-status-result',
'_wpnonce': SiteHealth.nonce.site_status_result,
'counts': SiteHealth.site_status.issues
}
);
wp.a11y.speak( SiteHealth.string.site_health_complete_screen_reader.replace( '%s', val + '%' ), 'polite' );
}
/**
* Queue the next asynchronous test when we're ready to run it.
*
* @since 5.2.0
*/
function maybeRunNextAsyncTest() {
var doCalculation = true;
if ( 1 <= SiteHealth.site_status.async.length ) {
$.each( SiteHealth.site_status.async, function() {
var data = {
'action': 'health-check-' + this.test.replace( '_', '-' ),
'_wpnonce': SiteHealth.nonce.site_status
};
if ( this.completed ) {
return true;
}
doCalculation = false;
this.completed = true;
$.post(
ajaxurl,
data,
function( response ) {
AppendIssue( response.data );
maybeRunNextAsyncTest();
}
);
return false;
} );
}
if ( doCalculation ) {
RecalculateProgression();
}
}
if ( 'undefined' !== typeof SiteHealth ) {
if ( 0 === SiteHealth.site_status.direct.length && 0 === SiteHealth.site_status.async.length ) {
RecalculateProgression();
} else {
SiteHealth.site_status.issues = {
'good': 0,
'recommended': 0,
'critical': 0
};
}
if ( 0 < SiteHealth.site_status.direct.length ) {
$.each( SiteHealth.site_status.direct, function() {
AppendIssue( this );
} );
}
if ( 0 < SiteHealth.site_status.async.length ) {
data = {
'action': 'health-check-' + SiteHealth.site_status.async[0].test.replace( '_', '-' ),
'_wpnonce': SiteHealth.nonce.site_status
};
SiteHealth.site_status.async[0].completed = true;
$.post(
ajaxurl,
data,
function( response ) {
AppendIssue( response.data );
maybeRunNextAsyncTest();
}
);
} else {
RecalculateProgression();
}
}
} );

View File

@ -131,6 +131,11 @@ $core_actions_post = array(
'edit-theme-plugin-file',
'wp-privacy-export-personal-data',
'wp-privacy-erase-personal-data',
'health-check-site-status-result',
'health-check-dotorg-communication',
'health-check-is-in-debug-mode',
'health-check-background-updates',
'health-check-loopback-requests',
);
// Deprecated

View File

@ -0,0 +1,450 @@
body.site-health #wpcontent {
padding-left: 0;
}
body.site-health .wrap {
margin-right: 0;
margin-left: 0;
}
body.site-health .wrap h2 {
padding: 1rem 0;
font-size: 1.3em;
line-height: 1.4;
font-weight: 600;
}
body.site-health ul li,
body.site-health ol li {
line-height: 1.5;
}
body.site-health .health-check-header {
text-align: center;
margin-top: 0;
margin-bottom: 1rem;
background: #fff;
border-bottom: 1px solid #e2e4e7;
}
body.site-health .health-check-header .title-section {
display: flex;
align-items: center;
justify-content: center;
}
body.site-health .health-check-header .title-section h1 {
display: inline-block;
font-weight: 600;
margin: 1rem 0.8rem 1rem 0.8rem;
}
body.site-health .health-check-header .title-section #progressbar {
display: inline-block;
height: 40px;
width: 40px;
margin: 0;
border-radius: 100%;
position: relative;
font-weight: 600;
font-size: 0.4rem;
}
body.site-health .health-check-header .title-section #progressbar:after {
position: absolute;
display: block;
height: 80px;
width: 80px;
left: 50%;
top: 50%;
content: attr(data-pct) "%";
margin-top: -40px;
margin-left: -40px;
border-radius: 100%;
line-height: 80px;
font-size: 2em;
}
body.site-health .health-check-header .title-section #progressbar.hidden {
display: none;
}
body.site-health .health-check-header .title-section #progressbar.loading:after {
animation: loadingEllipsis 3s infinite ease-in-out;
}
body.site-health .health-check-header .title-section #progressbar.loading svg #bar {
stroke-dashoffset: 0;
stroke: #adc5d2;
animation: loadingPulse 3s infinite ease-in-out;
}
body.site-health .health-check-header .title-section #progressbar svg circle {
stroke-dashoffset: 0;
transition: stroke-dashoffset 1s linear;
stroke: #ccc;
stroke-width: 2em;
}
body.site-health .health-check-header .title-section #progressbar svg #bar {
stroke-dashoffset: 565;
stroke: #dc3232;
}
body.site-health .health-check-header .title-section #progressbar svg #bar.green {
stroke: #46b450;
}
body.site-health .health-check-header .title-section #progressbar svg #bar.orange {
stroke: #ffb900;
}
@keyframes loadingPulse {
0% {
stroke: #adc5d2;
}
50% {
stroke: #00a0d2;
}
100% {
stroke: #adc5d2;
}
}
@keyframes loadingEllipsis {
0% {
content: ".";
}
50% {
content: "..";
}
100% {
content: "...";
}
}
body.site-health .health-check-header .tabs-wrapper {
display: block;
}
body.site-health .health-check-header .tabs-wrapper .tab {
float: none;
display: inline-block;
text-decoration: none;
color: inherit;
padding: 0.5rem 1rem 1rem;
margin: 0 1rem;
transition: box-shadow 0.5s ease-in-out;
}
body.site-health .health-check-header .tabs-wrapper .tab:focus {
color: #191e23;
outline: 1px solid #6c7781;
box-shadow: none;
}
body.site-health .health-check-header .tabs-wrapper .tab.active {
box-shadow: inset 0 -3px #007cba;
font-weight: 600;
}
body.site-health .health-check-body {
max-width: 800px;
margin: 0 auto;
}
body.site-health .health-check-table thead th:first-child,
body.site-health .health-check-table thead td:first-child {
width: 30%;
}
body.site-health .health-check-table tbody td {
width: 70%;
}
body.site-health .health-check-table tbody td:first-child {
width: 30%;
}
body.site-health .health-check-table tbody td ul,
body.site-health .health-check-table tbody td ol {
margin: 0;
}
body.site-health .pass:before,
body.site-health .good:before {
content: "\f147";
display: inline-block;
color: #46b450;
font-family: dashicons;
vertical-align: top;
}
body.site-health .warning:before {
content: "\f460";
display: inline-block;
color: #ffb900;
font-family: dashicons;
}
body.site-health .info:before {
content: "\f348";
display: inline-block;
color: #00a0d2;
font-family: dashicons;
}
body.site-health .fail:before,
body.site-health .error:before {
content: "\f335";
display: inline-block;
color: #dc3232;
font-family: dashicons;
}
body.site-health .spinner {
float: none;
}
body.site-health .system-information-copy-wrapper {
display: block;
margin: 1rem 0;
}
body.site-health .system-information-copy-wrapper textarea {
border: 0;
padding: 0;
margin: 0;
position: absolute;
left: -9999px;
top: -9999px;
}
body.site-health .health-check-toggle-copy-section:hover {
background: none;
}
body.site-health .system-information-copy-wrapper .copy-button-wrapper {
margin: 0.5rem 0 1rem;
}
body.site-health .copy-field-success {
display: none;
color: #40860a;
line-height: 1.8;
margin-left: 0.5rem;
}
body.site-health .copy-field-success.visible {
display: inline-block;
height: 28px;
line-height: 28px;
}
body.site-health .site-status-has-issues {
display: block;
}
body.site-health .site-status-has-issues.hide {
display: none;
}
body.site-health h3 {
padding: 0;
font-weight: 400;
}
body.site-health .view-more {
text-align: center;
}
body.site-health .issues-wrapper:first-of-type {
margin-top: 3rem;
}
body.site-health .issues-wrapper {
margin-bottom: 3rem;
margin-top: 2rem;
}
body.site-health .site-status-all-clear {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
text-align: center;
height: 100%;
width: 100%;
margin-top: 0;
}
@media all and (min-width: 784px) {
body.site-health .site-status-all-clear {
margin: 5rem 0;
}
}
body.site-health .site-status-all-clear.hide {
display: none;
}
body.site-health .site-status-all-clear .dashicons {
font-size: 150px;
height: 130px;
width: 150px;
}
body.site-health .site-status-all-clear .encouragement {
font-size: 1.5rem;
font-weight: 600;
}
body.site-health .site-status-all-clear p {
margin: 0;
}
body .health-check-accordion {
border: 1px solid #e2e4e7;
}
body .health-check-accordion dt {
font-weight: 600;
border-top: 1px solid #e2e4e7;
}
body .health-check-accordion dt:first-child {
border-radius: 0.3em 0.3em 0 0;
border-top: none;
}
body .health-check-accordion .health-check-accordion-trigger {
background: #fff;
border: 0;
color: #212121;
cursor: pointer;
display: block;
font-weight: 400;
margin: 0;
padding: 1em 1.5em;
position: relative;
text-align: left;
width: 100%;
}
body .health-check-accordion .health-check-accordion-trigger:hover,
body .health-check-accordion .health-check-accordion-trigger:active {
background: #f8f9f9;
}
body .health-check-accordion .health-check-accordion-trigger:focus {
color: #191e23;
border: none;
box-shadow: none;
outline-offset: -2px;
outline: 1px dotted #555d66;
}
body .health-check-accordion .health-check-accordion-trigger .title {
display: inline-block;
pointer-events: none;
font-weight: 600;
}
body .health-check-accordion .health-check-accordion-trigger .icon {
border: solid #191e23;
border-width: 0 2px 2px 0;
height: 0.5rem;
pointer-events: none;
position: absolute;
right: 1.5em;
top: 50%;
transform: translateY(-70%) rotate(45deg);
width: 0.5rem;
}
body .health-check-accordion .health-check-accordion-trigger .badge {
display: inline-block;
padding: 0.1rem 0.5rem 0.15rem;
background-color: #d7dade;
border-radius: 3px;
color: #000;
font-weight: 600;
margin: 0 0.5rem;
}
body .health-check-accordion .health-check-accordion-trigger .badge.blue {
background-color: #0073af;
color: #fff;
}
body .health-check-accordion .health-check-accordion-trigger .badge.orange {
background-color: #ffb900;
color: #000;
}
body .health-check-accordion .health-check-accordion-trigger .badge.red {
background-color: #dc3232;
color: #fff;
}
body .health-check-accordion .health-check-accordion-trigger .badge.green {
background-color: #40860a;
color: #fff;
}
body .health-check-accordion .health-check-accordion-trigger .badge.pink {
background-color: #f4b0fc;
color: #000;
}
body .health-check-accordion .health-check-accordion-trigger .badge.gray {
background-color: #ccc;
color: #000;
}
body .health-check-accordion .health-check-accordion-trigger .badge.light-blue {
background-color: #10e9fb;
color: #000;
}
body .health-check-accordion .health-check-accordion-trigger .badge.light-green {
background-color: #60f999;
color: #000;
}
body .health-check-accordion .health-check-accordion-trigger[aria-expanded="true"] .icon {
transform: translateY(-30%) rotate(-135deg)
}
body .health-check-accordion .health-check-accordion-panel {
margin: 0;
padding: 1em 1.5em;
background: #fff;
}
body .health-check-accordion .health-check-accordion-panel > div {
display: block;
}
body .health-check-accordion .health-check-accordion-panel[hidden] {
display: none;
}
body .health-check-accordion dl dd {
margin: 0 0 0.5em 2em;
}
@media screen and (max-width: 782px) {
body.site-health .health-check-body {
margin: 0 12px;
width: initial;
}
}
/* The breakpoint is usually at 960px, the additional space is to allow for the margin. */
@media only screen and (max-width: 1004px) {
body.site-health .health-check-body {
margin: 0 22px;
width: initial;
}
}

View File

@ -12,3 +12,4 @@
@import url(widgets.css);
@import url(site-icon.css);
@import url(l10n.css);
@import url(site-health.css);

View File

@ -4858,3 +4858,101 @@ function wp_ajax_wp_privacy_erase_personal_data() {
wp_send_json_success( $response );
}
/**
* Ajax handler for site health checks on server communication.
*
* @since 5.2.0
*/
function wp_ajax_health_check_dotorg_communication() {
check_ajax_referer( 'health-check-site-status' );
if ( ! current_user_can( 'install_plugins' ) ) {
wp_send_json_error();
}
if ( ! class_exists( 'WP_Site_Health' ) ) {
require_once( ABSPATH . 'wp-admin/includes/class-wp-site-health.php' );
}
$site_health = new WP_Site_Health();
wp_send_json_success( $site_health->get_test_dotorg_communication() );
}
/**
* Ajax handler for site health checks on debug mode.
*
* @since 5.2.0
*/
function wp_ajax_health_check_is_in_debug_mode() {
wp_verify_nonce( 'health-check-site-status' );
if ( ! current_user_can( 'install_plugins' ) ) {
wp_send_json_error();
}
if ( ! class_exists( 'WP_Site_Health' ) ) {
require_once( ABSPATH . 'wp-admin/includes/class-wp-site-health.php' );
}
$site_health = new WP_Site_Health();
wp_send_json_success( $site_health->get_test_is_in_debug_mode() );
}
/**
* Ajax handler for site health checks on background updates.
*
* @since 5.2.0
*/
function wp_ajax_health_check_background_updates() {
check_ajax_referer( 'health-check-site-status' );
if ( ! current_user_can( 'install_plugins' ) ) {
wp_send_json_error();
}
if ( ! class_exists( 'WP_Site_Health' ) ) {
require_once( ABSPATH . 'wp-admin/includes/class-wp-site-health.php' );
}
$site_health = new WP_Site_Health();
wp_send_json_success( $site_health->get_test_background_updates() );
}
/**
* Ajax handler for site health checks on loopback requests.
*
* @since 5.2.0
*/
function wp_ajax_health_check_loopback_requests() {
check_ajax_referer( 'health-check-site-status' );
if ( ! current_user_can( 'install_plugins' ) ) {
wp_send_json_error();
}
if ( ! class_exists( 'WP_Site_Health' ) ) {
require_once( ABSPATH . 'wp-admin/includes/class-wp-site-health.php' );
}
$site_health = new WP_Site_Health();
wp_send_json_success( $site_health->get_test_loopback_requests() );
}
/**
* Ajax handler for site health check to update the result status.
*
* @since 5.2.0
*/
function wp_ajax_health_check_site_status_result() {
check_ajax_referer( 'health-check-site-status-result' );
if ( ! current_user_can( 'install_plugins' ) ) {
wp_send_json_error();
}
set_transient( 'health-check-site-status-result', wp_json_encode( $_POST['counts'] ) );
wp_send_json_success();
}

View File

@ -0,0 +1,985 @@
<?php
/**
* Class for providing debug data based on a users WordPress environment.
*
* @package WordPress
* @subpackage Site_Health
* @since 5.2.0
*/
class WP_Debug_Data {
/**
* Calls all core functions to check for updates.
*
* @since 5.2.0
*/
static function check_for_updates() {
wp_version_check();
wp_update_plugins();
wp_update_themes();
}
/**
* Static function for generating site debug data when required.
*
* @since 5.2.0
*
* @throws ImagickException
* @global wpdb $wpdb WordPress database abstraction object.
*
* @param string $locale Optional. An ISO formatted language code to provide debug translations in. Default null.
* @return array The debug data for the site.
*/
static function debug_data( $locale = null ) {
global $wpdb;
if ( ! empty( $locale ) ) {
// Change the language used for translations
if ( function_exists( 'switch_to_locale' ) ) {
$original_locale = get_locale();
$switched_locale = switch_to_locale( $locale );
}
}
$upload_dir = wp_upload_dir();
if ( file_exists( ABSPATH . 'wp-config.php' ) ) {
$wp_config_path = ABSPATH . 'wp-config.php';
// phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged
} elseif ( @file_exists( dirname( ABSPATH ) . '/wp-config.php' ) && ! @file_exists( dirname( ABSPATH ) . '/wp-settings.php' ) ) {
$wp_config_path = dirname( ABSPATH ) . '/wp-config.php';
}
$core_current_version = get_bloginfo( 'version' );
$core_updates = get_core_updates();
$core_update_needed = '';
foreach ( $core_updates as $core => $update ) {
if ( 'upgrade' === $update->response ) {
// translators: %s: Latest WordPress version number.
$core_update_needed = ' ' . sprintf( __( '( Latest version: %s )' ), $update->version );
} else {
$core_update_needed = '';
}
}
// Set up the array that holds all debug information.
$info = array(
'wp-core' => array(
'label' => __( 'WordPress' ),
'fields' => array(
'version' => array(
'label' => __( 'Version' ),
'value' => $core_current_version . $core_update_needed,
),
'language' => array(
'label' => __( 'Language' ),
'value' => ( ! empty( $locale ) ? $original_locale : get_locale() ),
),
'home_url' => array(
'label' => __( 'Home URL' ),
'value' => get_bloginfo( 'url' ),
'private' => true,
),
'site_url' => array(
'label' => __( 'Site URL' ),
'value' => get_bloginfo( 'wpurl' ),
'private' => true,
),
'permalink' => array(
'label' => __( 'Permalink structure' ),
'value' => get_option( 'permalink_structure' ) ?: __( 'No permalink structure set' ),
),
'https_status' => array(
'label' => __( 'Is this site using HTTPS?' ),
'value' => ( is_ssl() ? __( 'Yes' ) : __( 'No' ) ),
),
'user_registration' => array(
'label' => __( 'Can anyone register on this site?' ),
'value' => ( get_option( 'users_can_register' ) ? __( 'Yes' ) : __( 'No' ) ),
),
'default_comment_status' => array(
'label' => __( 'Default comment status' ),
'value' => get_option( 'default_comment_status' ),
),
'multisite' => array(
'label' => __( 'Is this a multisite?' ),
'value' => ( is_multisite() ? __( 'Yes' ) : __( 'No' ) ),
),
),
),
'wp-paths-sizes' => array(
'label' => __( 'Directories and Sizes' ),
'fields' => array(),
),
'wp-dropins' => array(
'label' => __( 'Drop-ins' ),
'show_count' => true,
'description' => __( 'Drop-ins are single files that replace or enhance WordPress features in ways that are not possible for traditional plugins.' ),
'fields' => array(),
),
'wp-active-theme' => array(
'label' => __( 'Active Theme' ),
'fields' => array(),
),
'wp-themes' => array(
'label' => __( 'Other Themes' ),
'show_count' => true,
'fields' => array(),
),
'wp-mu-plugins' => array(
'label' => __( 'Must Use Plugins' ),
'show_count' => true,
'fields' => array(),
),
'wp-plugins-active' => array(
'label' => __( 'Active Plugins' ),
'show_count' => true,
'fields' => array(),
),
'wp-plugins-inactive' => array(
'label' => __( 'Inactive Plugins' ),
'show_count' => true,
'fields' => array(),
),
'wp-media' => array(
'label' => __( 'Media Handling' ),
'fields' => array(),
),
'wp-server' => array(
'label' => __( 'Server' ),
'description' => __( 'The options shown below relate to your server setup. If changes are required, you may need your web host&#8217;s assistance.' ),
'fields' => array(),
),
'wp-database' => array(
'label' => __( 'Database' ),
'fields' => array(),
),
'wp-constants' => array(
'label' => __( 'WordPress Constants' ),
'description' => __( 'These settings are defined in your wp-config.php file, and alter where and how parts of WordPress are loaded.' ),
'fields' => array(
'ABSPATH' => array(
'label' => 'ABSPATH',
'value' => ( ! defined( 'ABSPATH' ) ? __( 'Undefined' ) : ABSPATH ),
'private' => true,
),
'WP_HOME' => array(
'label' => 'WP_HOME',
'value' => ( ! defined( 'WP_HOME' ) ? __( 'Undefined' ) : WP_HOME ),
),
'WP_SITEURL' => array(
'label' => 'WP_SITEURL',
'value' => ( ! defined( 'WP_SITEURL' ) ? __( 'Undefined' ) : WP_SITEURL ),
),
'WP_CONTENT_DIR' => array(
'label' => 'WP_CONTENT_DIR',
'value' => ( ! defined( 'WP_CONTENT_DIR' ) ? __( 'Undefined' ) : WP_CONTENT_DIR ),
),
'WP_PLUGIN_DIR' => array(
'label' => 'WP_PLUGIN_DIR',
'value' => ( ! defined( 'WP_PLUGIN_DIR' ) ? __( 'Undefined' ) : WP_PLUGIN_DIR ),
),
'WP_DEBUG' => array(
'label' => 'WP_DEBUG',
'value' => ( ! defined( 'WP_DEBUG' ) ? __( 'Undefined' ) : ( WP_DEBUG ? __( 'Enabled' ) : __( 'Disabled' ) ) ),
),
'WP_MAX_MEMORY_LIMIT' => array(
'label' => 'WP_MAX_MEMORY_LIMIT',
'value' => ( ! defined( 'WP_MAX_MEMORY_LIMIT' ) ? __( 'Undefined' ) : WP_MAX_MEMORY_LIMIT ),
),
'WP_DEBUG_DISPLAY' => array(
'label' => 'WP_DEBUG_DISPLAY',
'value' => ( ! defined( 'WP_DEBUG_DISPLAY' ) ? __( 'Undefined' ) : ( WP_DEBUG_DISPLAY ? __( 'Enabled' ) : __( 'Disabled' ) ) ),
),
'WP_DEBUG_LOG' => array(
'label' => 'WP_DEBUG_LOG',
'value' => ( ! defined( 'WP_DEBUG_LOG' ) ? __( 'Undefined' ) : ( WP_DEBUG_LOG ? __( 'Enabled' ) : __( 'Disabled' ) ) ),
),
'SCRIPT_DEBUG' => array(
'label' => 'SCRIPT_DEBUG',
'value' => ( ! defined( 'SCRIPT_DEBUG' ) ? __( 'Undefined' ) : ( SCRIPT_DEBUG ? __( 'Enabled' ) : __( 'Disabled' ) ) ),
),
'WP_CACHE' => array(
'label' => 'WP_CACHE',
'value' => ( ! defined( 'WP_CACHE' ) ? __( 'Undefined' ) : ( WP_CACHE ? __( 'Enabled' ) : __( 'Disabled' ) ) ),
),
'CONCATENATE_SCRIPTS' => array(
'label' => 'CONCATENATE_SCRIPTS',
'value' => ( ! defined( 'CONCATENATE_SCRIPTS' ) ? __( 'Undefined' ) : ( CONCATENATE_SCRIPTS ? __( 'Enabled' ) : __( 'Disabled' ) ) ),
),
'COMPRESS_SCRIPTS' => array(
'label' => 'COMPRESS_SCRIPTS',
'value' => ( ! defined( 'COMPRESS_SCRIPTS' ) ? __( 'Undefined' ) : ( COMPRESS_SCRIPTS ? __( 'Enabled' ) : __( 'Disabled' ) ) ),
),
'COMPRESS_CSS' => array(
'label' => 'COMPRESS_CSS',
'value' => ( ! defined( 'COMPRESS_CSS' ) ? __( 'Undefined' ) : ( COMPRESS_CSS ? __( 'Enabled' ) : __( 'Disabled' ) ) ),
),
'WP_LOCAL_DEV' => array(
'label' => 'WP_LOCAL_DEV',
'value' => ( ! defined( 'WP_LOCAL_DEV' ) ? __( 'Undefined' ) : ( WP_LOCAL_DEV ? __( 'Enabled' ) : __( 'Disabled' ) ) ),
),
),
),
'wp-filesystem' => array(
'label' => __( 'Filesystem Permissions' ),
'description' => __( 'Shows whether WordPress is able to write to the directories it needs access to.' ),
'fields' => array(
'all' => array(
'label' => __( 'The main WordPress directory' ),
'value' => ( wp_is_writable( ABSPATH ) ? __( 'Writable' ) : __( 'Not writable' ) ),
),
'wp-content' => array(
'label' => __( 'The wp-content directory' ),
'value' => ( wp_is_writable( WP_CONTENT_DIR ) ? __( 'Writable' ) : __( 'Not writable' ) ),
),
'uploads' => array(
'label' => __( 'The uploads directory' ),
'value' => ( wp_is_writable( $upload_dir['basedir'] ) ? __( 'Writable' ) : __( 'Not writable' ) ),
),
'plugins' => array(
'label' => __( 'The plugins directory' ),
'value' => ( wp_is_writable( WP_PLUGIN_DIR ) ? __( 'Writable' ) : __( 'Not writable' ) ),
),
'themes' => array(
'label' => __( 'The themes directory' ),
'value' => ( wp_is_writable( get_template_directory() . '/..' ) ? __( 'Writable' ) : __( 'Not writable' ) ),
),
),
),
);
// Conditionally add debug information for multisite setups.
if ( is_multisite() ) {
$network_query = new WP_Network_Query();
$network_ids = $network_query->query(
array(
'fields' => 'ids',
'number' => 100,
'no_found_rows' => false,
)
);
$site_count = 0;
foreach ( $network_ids as $network_id ) {
$site_count += get_blog_count( $network_id );
}
$info['wp-core']['fields']['user_count'] = array(
'label' => __( 'User count' ),
'value' => get_user_count(),
);
$info['wp-core']['fields']['site_count'] = array(
'label' => __( 'Site count' ),
'value' => $site_count,
);
$info['wp-core']['fields']['network_count'] = array(
'label' => __( 'Network count' ),
'value' => $network_query->found_networks,
);
} else {
$user_count = count_users();
$info['wp-core']['fields']['user_count'] = array(
'label' => __( 'User count' ),
'value' => $user_count['total_users'],
);
}
// WordPress features requiring processing.
$wp_dotorg = wp_remote_get(
'https://wordpress.org',
array(
'timeout' => 10,
)
);
if ( ! is_wp_error( $wp_dotorg ) ) {
$info['wp-core']['fields']['dotorg_communication'] = array(
'label' => __( 'Communication with WordPress.org' ),
'value' => sprintf(
__( 'WordPress.org is reachable' )
),
);
} else {
$info['wp-core']['fields']['dotorg_communication'] = array(
'label' => __( 'Communication with WordPress.org' ),
'value' => sprintf(
// translators: %1$s: The IP address WordPress.org resolves to. %2$s: The error returned by the lookup.
__( 'Unable to reach WordPress.org at %1$s: %2$s' ),
gethostbyname( 'wordpress.org' ),
$wp_dotorg->get_error_message()
),
);
}
// Go through the various installation directories and calculate their sizes.
$uploads_dir = wp_upload_dir();
$inaccurate = false;
/*
* We will be using the PHP max execution time to prevent the size calculations
* from causing a timeout. We provide a default value of 30 seconds, as some
* hosts do not allow you to read configuration values.
*/
$max_execution_time = 30;
$start_execution_time = microtime( true );
if ( function_exists( 'ini_get' ) ) {
$max_execution_time = ini_get( 'max_execution_time' );
}
$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' => $uploads_dir['basedir'],
'size' => 0,
),
);
// Loop over all the directories we want to gather the sizes for.
foreach ( $size_directories as $size => $attributes ) {
/*
* We run a helper function with a RecursiveIterator, which
* may throw an exception if it can't access directories.
*
* If a failure is detected we mark the result as inaccurate.
*/
try {
$calculated_size = WP_Debug_data::get_directory_size( $attributes['path'], $max_execution_time, $start_execution_time );
$size_directories[ $size ]['size'] = $calculated_size;
/*
* If the size returned is -1, this means execution has
* exceeded the maximum execution time, also denoting an
* inaccurate value in the end.
*/
if ( -1 === $calculated_size ) {
$inaccurate = true;
}
} catch ( Exception $e ) {
$inaccurate = true;
}
}
$size_db = WP_Debug_Data::get_database_size();
$size_total = $size_directories['wordpress']['size'] + $size_db;
$info['wp-paths-sizes']['fields'] = array(
array(
'label' => __( 'Uploads Directory Location' ),
'value' => $size_directories['uploads']['path'],
),
array(
'label' => __( 'Uploads Directory Size' ),
'value' => ( -1 === $size_directories['uploads']['size'] ? __( 'Unable to determine the size of this directory' ) : size_format( $size_directories['uploads']['size'], 2 ) ),
),
array(
'label' => __( 'Themes Directory Location' ),
'value' => $size_directories['themes']['path'],
),
array(
'label' => __( 'Current Theme Directory' ),
'value' => get_template_directory(),
),
array(
'label' => __( 'Themes Directory Size' ),
'value' => ( -1 === $size_directories['themes']['size'] ? __( 'Unable to determine the size of this directory' ) : size_format( $size_directories['themes']['size'], 2 ) ),
),
array(
'label' => __( 'Plugins Directory Location' ),
'value' => $size_directories['plugins']['path'],
),
array(
'label' => __( 'Plugins Directory Size' ),
'value' => ( -1 === $size_directories['plugins']['size'] ? __( 'Unable to determine the size of this directory' ) : size_format( $size_directories['plugins']['size'], 2 ) ),
),
array(
'label' => __( 'WordPress Directory Location' ),
'value' => $size_directories['wordpress']['path'],
),
array(
'label' => __( 'WordPress Directory Size' ),
'value' => size_format( $size_directories['wordpress']['size'], 2 ),
),
array(
'label' => __( 'Database size' ),
'value' => size_format( $size_db, 2 ),
),
array(
'label' => __( 'Total installation size' ),
'value' => sprintf(
'%s%s',
size_format( $size_total, 2 ),
( false === $inaccurate ? '' : __( '- Some errors, likely caused by invalid permissions, were encountered when determining the size of your installation. This means the values represented may be inaccurate.' ) )
),
),
);
// Get a list of all drop-in replacements.
$dropins = get_dropins();
$dropin_description = _get_dropins();
foreach ( $dropins as $dropin_key => $dropin ) {
$info['wp-dropins']['fields'][ sanitize_key( $dropin_key ) ] = array(
'label' => $dropin_key,
'value' => $dropin_description[ $dropin_key ][0],
);
}
// Populate the media fields.
$info['wp-media']['fields']['image_editor'] = array(
'label' => __( 'Active editor' ),
'value' => _wp_image_editor_choose(),
);
// Get ImageMagic information, if available.
if ( class_exists( 'Imagick' ) ) {
// Save the Imagick instance for later use.
$imagick = new Imagick();
$imagick_version = $imagick->getVersion();
} else {
$imagick_version = __( 'Not available' );
}
$info['wp-media']['fields']['imagick_module_version'] = array(
'label' => __( 'ImageMagick version number' ),
'value' => ( is_array( $imagick_version ) ? $imagick_version['versionNumber'] : $imagick_version ),
);
$info['wp-media']['fields']['imagemagick_version'] = array(
'label' => __( 'ImageMagick version string' ),
'value' => ( is_array( $imagick_version ) ? $imagick_version['versionString'] : $imagick_version ),
);
// If Imagick is used as our editor, provide some more information about its limitations.
if ( 'WP_Image_Editor_Imagick' === _wp_image_editor_choose() && isset( $imagick ) && $imagick instanceof Imagick ) {
$limits = array(
'area' => ( defined( 'imagick::RESOURCETYPE_AREA' ) ? size_format( $imagick->getResourceLimit( imagick::RESOURCETYPE_AREA ) ) : __( 'Not available' ) ),
'disk' => ( defined( 'imagick::RESOURCETYPE_DISK' ) ? $imagick->getResourceLimit( imagick::RESOURCETYPE_DISK ) : __( 'Not available' ) ),
'file' => ( defined( 'imagick::RESOURCETYPE_FILE' ) ? $imagick->getResourceLimit( imagick::RESOURCETYPE_FILE ) : __( 'Not available' ) ),
'map' => ( defined( 'imagick::RESOURCETYPE_MAP' ) ? size_format( $imagick->getResourceLimit( imagick::RESOURCETYPE_MAP ) ) : __( 'Not available' ) ),
'memory' => ( defined( 'imagick::RESOURCETYPE_MEMORY' ) ? size_format( $imagick->getResourceLimit( imagick::RESOURCETYPE_MEMORY ) ) : __( 'Not available' ) ),
'thread' => ( defined( 'imagick::RESOURCETYPE_THREAD' ) ? $imagick->getResourceLimit( imagick::RESOURCETYPE_THREAD ) : __( 'Not available' ) ),
);
$info['wp-media']['fields']['imagick_limits'] = array(
'label' => __( 'Imagick Resource Limits' ),
'value' => $limits,
);
}
// Get GD information, if available.
if ( function_exists( 'gd_info' ) ) {
$gd = gd_info();
} else {
$gd = false;
}
$info['wp-media']['fields']['gd_version'] = array(
'label' => __( 'GD version' ),
'value' => ( is_array( $gd ) ? $gd['GD Version'] : __( 'Not available' ) ),
);
// Get Ghostscript information, if available.
if ( function_exists( 'exec' ) ) {
$gs = exec( 'gs --version' );
$gs = ( ! empty( $gs ) ? $gs : __( 'Not available' ) );
} else {
$gs = __( 'Unable to determine if Ghostscript is installed' );
}
$info['wp-media']['fields']['ghostscript_version'] = array(
'label' => __( 'Ghostscript version' ),
'value' => $gs,
);
// Populate the server debug fields.
$info['wp-server']['fields']['server_architecture'] = array(
'label' => __( 'Server architecture' ),
'value' => ( ! function_exists( 'php_uname' ) ? __( 'Unable to determine server architecture' ) : sprintf( '%s %s %s', php_uname( 's' ), php_uname( 'r' ), php_uname( 'm' ) ) ),
);
$info['wp-server']['fields']['httpd_software'] = array(
'label' => __( 'Web server' ),
'value' => ( isset( $_SERVER['SERVER_SOFTWARE'] ) ? $_SERVER['SERVER_SOFTWARE'] : __( 'Unable to determine what web server software is used' ) ),
);
$info['wp-server']['fields']['php_version'] = array(
'label' => __( 'PHP version' ),
'value' => ( ! function_exists( 'phpversion' ) ? __( 'Unable to determine PHP version' ) : sprintf(
'%s %s',
phpversion(),
( 64 === PHP_INT_SIZE * 8 ? __( '(Supports 64bit values)' ) : __( '(Does not support 64bit values)' ) )
)
),
);
$info['wp-server']['fields']['php_sapi'] = array(
'label' => __( 'PHP SAPI' ),
'value' => ( ! function_exists( 'php_sapi_name' ) ? __( 'Unable to determine PHP SAPI' ) : php_sapi_name() ),
);
// Some servers disable `ini_set()` and `ini_get()`, we check this before trying to get configuration values.
if ( ! function_exists( 'ini_get' ) ) {
$info['wp-server']['fields']['ini_get'] = array(
'label' => __( 'Server settings' ),
'value' => __( 'Unable to determine some settings, as the ini_get() function has been disabled.' ),
);
} else {
$info['wp-server']['fields']['max_input_variables'] = array(
'label' => __( 'PHP max input variables' ),
'value' => ini_get( 'max_input_vars' ),
);
$info['wp-server']['fields']['time_limit'] = array(
'label' => __( 'PHP time limit' ),
'value' => ini_get( 'max_execution_time' ),
);
$info['wp-server']['fields']['memory_limit'] = array(
'label' => __( 'PHP memory limit' ),
'value' => ini_get( 'memory_limit' ),
);
$info['wp-server']['fields']['max_input_time'] = array(
'label' => __( 'Max input time' ),
'value' => ini_get( 'max_input_time' ),
);
$info['wp-server']['fields']['upload_max_size'] = array(
'label' => __( 'Upload max filesize' ),
'value' => ini_get( 'upload_max_filesize' ),
);
$info['wp-server']['fields']['php_post_max_size'] = array(
'label' => __( 'PHP post max size' ),
'value' => ini_get( 'post_max_size' ),
);
}
if ( function_exists( 'curl_version' ) ) {
$curl = curl_version();
$info['wp-server']['fields']['curl_version'] = array(
'label' => __( 'cURL version' ),
'value' => sprintf( '%s %s', $curl['version'], $curl['ssl_version'] ),
);
} else {
$info['wp-server']['fields']['curl_version'] = array(
'label' => __( 'cURL version' ),
'value' => __( 'Not available' ),
);
}
$info['wp-server']['fields']['suhosin'] = array(
'label' => __( 'Is SUHOSIN installed?' ),
'value' => ( ( extension_loaded( 'suhosin' ) || ( defined( 'SUHOSIN_PATCH' ) && constant( 'SUHOSIN_PATCH' ) ) ) ? __( 'Yes' ) : __( 'No' ) ),
);
$info['wp-server']['fields']['imagick_availability'] = array(
'label' => __( 'Is the Imagick library available?' ),
'value' => ( extension_loaded( 'imagick' ) ? __( 'Yes' ) : __( 'No' ) ),
);
// Check if a .htaccess file exists.
if ( is_file( ABSPATH . '/.htaccess' ) ) {
// If the file exists, grab the content of it.
$htaccess_content = file_get_contents( ABSPATH . '/.htaccess' );
// Filter away the core WordPress rules.
$filtered_htaccess_content = trim( preg_replace( '/\# BEGIN WordPress[\s\S]+?# END WordPress/si', '', $htaccess_content ) );
$info['wp-server']['fields']['htaccess_extra_rules'] = array(
'label' => __( 'htaccess rules' ),
'value' => ( ! empty( $filtered_htaccess_content ) ? __( 'Custom rules have been added to your htaccess file.' ) : __( 'Your htaccess file contains only core WordPress features.' ) ),
);
}
// Populate the database debug fields.
if ( is_resource( $wpdb->dbh ) ) {
// Old mysql extension.
$extension = 'mysql';
} elseif ( is_object( $wpdb->dbh ) ) {
// mysqli or PDO.
$extension = get_class( $wpdb->dbh );
} else {
// Unknown sql extension.
$extension = null;
}
/*
* Check what database engine is used, this will throw compatibility
* warnings from PHP compatibility testers, but `mysql_*` is
* still valid in PHP 5.6, so we need to account for that.
*/
if ( method_exists( $wpdb, 'db_version' ) ) {
if ( $wpdb->use_mysqli ) {
// phpcs:ignore WordPress.DB.RestrictedFunctions.mysql_mysqli_get_server_info
$server = mysqli_get_server_info( $wpdb->dbh );
} else {
// phpcs:ignore WordPress.DB.RestrictedFunctions.mysql_mysql_get_server_info
$server = mysql_get_server_info( $wpdb->dbh );
}
} else {
$server = null;
}
if ( isset( $wpdb->use_mysqli ) && $wpdb->use_mysqli ) {
$client_version = $wpdb->dbh->client_info;
} else {
// phpcs:ignore WordPress.DB.RestrictedFunctions.mysql_mysql_get_client_info
if ( preg_match( '|[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}|', mysql_get_client_info(), $matches ) ) {
$client_version = $matches[0];
} else {
$client_version = null;
}
}
$info['wp-database']['fields']['extension'] = array(
'label' => __( 'Extension' ),
'value' => $extension,
);
$info['wp-database']['fields']['server_version'] = array(
'label' => __( 'Server version' ),
'value' => $server,
);
$info['wp-database']['fields']['client_version'] = array(
'label' => __( 'Client version' ),
'value' => $client_version,
);
$info['wp-database']['fields']['database_user'] = array(
'label' => __( 'Database user' ),
'value' => $wpdb->dbuser,
'private' => true,
);
$info['wp-database']['fields']['database_host'] = array(
'label' => __( 'Database host' ),
'value' => $wpdb->dbhost,
'private' => true,
);
$info['wp-database']['fields']['database_name'] = array(
'label' => __( 'Database name' ),
'value' => $wpdb->dbname,
'private' => true,
);
$info['wp-database']['fields']['database_prefix'] = array(
'label' => __( 'Database prefix' ),
'value' => $wpdb->prefix,
'private' => true,
);
// List must use plugins if there are any.
$mu_plugins = get_mu_plugins();
foreach ( $mu_plugins as $plugin_path => $plugin ) {
$plugin_version = $plugin['Version'];
$plugin_author = $plugin['Author'];
$plugin_version_string = __( 'No version or author information is available.' );
if ( ! empty( $plugin_version ) && ! empty( $plugin_author ) ) {
// translators: %1$s: Plugin version number. %2$s: Plugin author name.
$plugin_version_string = sprintf( __( 'Version %1$s by %2$s' ), $plugin_version, $plugin_author );
}
if ( empty( $plugin_version ) && ! empty( $plugin_author ) ) {
// translators: %s: Plugin author name.
$plugin_version_string = sprintf( __( 'By %s' ), $plugin_author );
}
if ( ! empty( $plugin_version ) && empty( $plugin_author ) ) {
// translators: %s: Plugin version number.
$plugin_version_string = sprintf( __( 'Version %s' ), $plugin_version );
}
$info['wp-mu-plugins']['fields'][ sanitize_key( $plugin['Name'] ) ] = array(
'label' => $plugin['Name'],
'value' => $plugin_version_string,
);
}
// List all available plugins.
$plugins = get_plugins();
$plugin_updates = get_plugin_updates();
foreach ( $plugins as $plugin_path => $plugin ) {
$plugin_part = ( is_plugin_active( $plugin_path ) ) ? 'wp-plugins-active' : 'wp-plugins-inactive';
$plugin_version = $plugin['Version'];
$plugin_author = $plugin['Author'];
$plugin_version_string = __( 'No version or author information is available.' );
if ( ! empty( $plugin_version ) && ! empty( $plugin_author ) ) {
// translators: %1$s: Plugin version number. %2$s: Plugin author name.
$plugin_version_string = sprintf( __( 'Version %1$s by %2$s' ), $plugin_version, $plugin_author );
}
if ( empty( $plugin_version ) && ! empty( $plugin_author ) ) {
// translators: %s: Plugin author name.
$plugin_version_string = sprintf( __( 'By %s' ), $plugin_author );
}
if ( ! empty( $plugin_version ) && empty( $plugin_author ) ) {
// translators: %s: Plugin version number.
$plugin_version_string = sprintf( __( 'Version %s' ), $plugin_version );
}
if ( array_key_exists( $plugin_path, $plugin_updates ) ) {
// translators: %s: Latest plugin version number.
$plugin_update_needed = ' ' . sprintf( __( '(Latest version: %s)' ), $plugin_updates[ $plugin_path ]->update->new_version );
} else {
$plugin_update_needed = '';
}
$info[ $plugin_part ]['fields'][ sanitize_key( $plugin['Name'] ) ] = array(
'label' => $plugin['Name'],
'value' => $plugin_version_string . $plugin_update_needed,
);
}
// Populate the section for the currently active theme.
global $_wp_theme_features;
$theme_features = array();
if ( ! empty( $_wp_theme_features ) ) {
foreach ( $_wp_theme_features as $feature => $options ) {
$theme_features[] = $feature;
}
}
$active_theme = wp_get_theme();
$theme_updates = get_theme_updates();
if ( array_key_exists( $active_theme->stylesheet, $theme_updates ) ) {
// translators: %s: Latest theme version number.
$theme_update_needed_active = ' ' . sprintf( __( '(Latest version: %s)' ), $theme_updates[ $active_theme->stylesheet ]->update['new_version'] );
} else {
$theme_update_needed_active = '';
}
$info['wp-active-theme']['fields'] = array(
'name' => array(
'label' => __( 'Name' ),
// phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
'value' => $active_theme->Name,
),
'version' => array(
'label' => __( 'Version' ),
// phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
'value' => $active_theme->Version . $theme_update_needed_active,
),
'author' => array(
'label' => __( 'Author' ),
// phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
'value' => wp_kses( $active_theme->Author, array() ),
),
'author_website' => array(
'label' => __( 'Author website' ),
'value' => ( $active_theme->offsetGet( 'Author URI' ) ? $active_theme->offsetGet( 'Author URI' ) : __( 'Undefined' ) ),
),
'parent_theme' => array(
'label' => __( 'Parent theme' ),
'value' => ( $active_theme->parent_theme ? $active_theme->parent_theme : __( 'None' ) ),
),
'theme_features' => array(
'label' => __( 'Theme features' ),
'value' => implode( ', ', $theme_features ),
),
);
// Populate a list of all themes available in the install.
$all_themes = wp_get_themes();
foreach ( $all_themes as $theme_slug => $theme ) {
// Ignore the currently active theme from the list of all themes.
if ( $active_theme->stylesheet == $theme_slug ) {
continue;
}
// phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
$theme_version = $theme->Version;
// phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
$theme_author = $theme->Author;
$theme_version_string = __( 'No version or author information is available.' );
if ( ! empty( $theme_version ) && ! empty( $theme_author ) ) {
// translators: %1$s: Theme version number. %2$s: Theme author name.
$theme_version_string = sprintf( __( 'Version %1$s by %2$s' ), $theme_version, wp_kses( $theme_author, array() ) );
}
if ( empty( $theme_version ) && ! empty( $theme_author ) ) {
// translators: %s: Theme author name.
$theme_version_string = sprintf( __( 'By %s' ), wp_kses( $theme_author, array() ) );
}
if ( ! empty( $theme_version ) && empty( $theme_author ) ) {
// translators: %s: Theme version number.
$theme_version_string = sprintf( __( 'Version %s' ), $theme_version );
}
if ( array_key_exists( $theme_slug, $theme_updates ) ) {
// translators: %s: Latest theme version number.
$theme_update_needed = ' ' . sprintf( __( '(Latest version: %s)' ), $theme_updates[ $theme_slug ]->update['new_version'] );
} else {
$theme_update_needed = '';
}
$info['wp-themes']['fields'][ sanitize_key( $theme->Name ) ] = array(
'label' => sprintf(
// translators: %1$s: Theme name. %2$s: Theme slug.
__( '%1$s (%2$s)' ),
// phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
$theme->Name,
$theme_slug
),
'value' => $theme_version_string . $theme_update_needed,
);
}
// Add more filesystem checks
if ( defined( 'WPMU_PLUGIN_DIR' ) && is_dir( WPMU_PLUGIN_DIR ) ) {
$info['wp-filesystem']['fields']['mu_plugin_directory'] = array(
'label' => __( 'The must use plugins directory' ),
'value' => ( wp_is_writable( WPMU_PLUGIN_DIR ) ? __( 'Writable' ) : __( 'Not writable' ) ),
);
}
/**
* Add or modify new debug sections.
*
* Plugin or themes may wish to introduce their own debug information without creating additional admin pages for this
* kind of information as it is rarely needed, they can then utilize this filter to introduce their own sections.
*
* Array keys added by core are all prefixed with `wp-`, plugins and themes are encouraged to use their own slug as
* a prefix, both for consistency as well as avoiding key collisions.
*
* @since 5.2.0
*
* @param array $args {
* The debug information to be added to the core information page.
*
* @type string $label The title for this section of the debug output.
* @type string $description Optional. A description for your information section which may contain basic HTML
* markup: `em`, `strong` and `a` for linking to documentation or putting emphasis.
* @type boolean $show_count Optional. If set to `true` the amount of fields will be included in the title for
* this section.
* @type boolean $private Optional. If set to `true` the section and all associated fields will be excluded
* from the copy-paste text area.
* @type array $fields {
* An associative array containing the data to be displayed.
*
* @type string $label The label for this piece of information.
* @type string $value The output that is of interest for this field.
* @type boolean $private Optional. If set to `true` the field will not be included in the copy-paste text area
* on top of the page, allowing you to show, for example, API keys here.
* }
* }
*/
$info = apply_filters( 'debug_information', $info );
if ( ! empty( $locale ) ) {
// Change the language used for translations
if ( function_exists( 'restore_previous_locale' ) && $switched_locale ) {
restore_previous_locale();
}
}
return $info;
}
/**
* Print the formatted variation of the information gathered for debugging, in a manner
* suitable for a text area that can be instantly copied to a forum or support ticket.
*
* @since 5.2.0
*
* @param array $info_array Information gathered from the `WP_Debug_Data::debug_data` function.
*/
public static function textarea_format( $info_array ) {
echo "`\n";
foreach ( $info_array as $section => $details ) {
// Skip this section if there are no fields, or the section has been declared as private.
if ( empty( $details['fields'] ) || ( isset( $details['private'] ) && $details['private'] ) ) {
continue;
}
printf(
"### %s%s ###\n\n",
$details['label'],
( isset( $details['show_count'] ) && $details['show_count'] ? sprintf( ' (%d)', count( $details['fields'] ) ) : '' )
);
foreach ( $details['fields'] as $field ) {
if ( isset( $field['private'] ) && true === $field['private'] ) {
continue;
}
$values = $field['value'];
if ( is_array( $field['value'] ) ) {
$values = '';
foreach ( $field['value'] as $name => $value ) {
$values .= sprintf(
"\n\t%s: %s",
$name,
$value
);
}
}
printf(
"%s: %s\n",
$field['label'],
$values
);
}
echo "\n";
}
echo '`';
}
/**
* Return the size of a directory, including all subdirectories.
*
* @since 5.2.0
*
* @param string $path The directory to check.
* @param string|int $max_execution_time How long a PHP script can run on this host.
* @param float $start_execution_time When we started executing this section of the script.
*
* @return int The directory size, in bytes.
*/
public static function get_directory_size( $path, $max_execution_time, $start_execution_time ) {
$size = 0;
foreach ( new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $path ) ) as $file ) {
// Check if the maximum execution time is a value considered "infinite".
if ( 0 !== $max_execution_time && -1 !== $max_execution_time ) {
$runtime = ( microtime( true ) - $start_execution_time );
// If the script has been running as long, or longer, as it is allowed, return a failure message.
if ( $runtime >= $max_execution_time ) {
return -1;
}
}
$size += $file->getSize();
}
return $size;
}
/**
* Fetch the total size of all the database tables for the active database user.
*
* @since 5.2.0
*
* @return int The size of the database, in bytes.
*/
public static function get_database_size() {
global $wpdb;
$size = 0;
$rows = $wpdb->get_results( 'SHOW TABLE STATUS', ARRAY_A );
if ( $wpdb->num_rows > 0 ) {
foreach ( $rows as $row ) {
$size += $row['Data_length'] + $row['Index_length'];
}
}
return $size;
}
}

View File

@ -0,0 +1,434 @@
<?php
/**
* Class for testing automatic updates in the WordPress code.
*
* @package WordPress
* @subpackage Site_Health
* @since 5.2.0
*/
class WP_Site_Health_Auto_Updates {
/**
* WP_Site_Health_Auto_Updates constructor.
* @since 5.2.0
*/
public function __construct() {
include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
}
/**
* Run tests to determine if auto-updates can run.
*
* @since 5.2.0
*
* @return array The test results.
*/
public function run_tests() {
$tests = array(
$this->test_constants( 'DISALLOW_FILE_MODS', false ),
$this->test_constants( 'AUTOMATIC_UPDATER_DISABLED', false ),
$this->test_constants( 'WP_AUTO_UPDATE_CORE', true ),
$this->test_wp_version_check_attached(),
$this->test_filters_automatic_updater_disabled(),
$this->test_if_failed_update(),
$this->test_vcs_abspath(),
$this->test_check_wp_filesystem_method(),
$this->test_all_files_writable(),
$this->test_accepts_dev_updates(),
$this->test_accepts_minor_updates(),
);
$tests = array_filter( $tests );
$tests = array_map(
function( $test ) {
$test = (object) $test;
if ( empty( $test->severity ) ) {
$test->severity = 'warning';
}
return $test;
},
$tests
);
return $tests;
}
/**
* Test if auto-updated related constants are set correctly.
*
* @since 5.2.0
*
* @param string $constant The name of the constant to check.
* @param bool $value The value that the constant should be, if set.
* @return array The test results.
*/
public function test_constants( $constant, $value ) {
if ( defined( $constant ) && constant( $constant ) != $allowed_constants[ $constant ] ) {
return array(
'description' => sprintf(
/* translators: %s: Name of the constant used. */
__( 'The %s constant is defined and enabled.' ),
"<code>$constant</code>"
),
'severity' => 'fail',
);
}
}
/**
* Check if updates are intercepted by a filter.
*
* @since 5.2.0
*
* @return array The test results.
*/
public function test_wp_version_check_attached() {
$cookies = wp_unslash( $_COOKIE );
$timeout = 10;
$headers = array(
'Cache-Control' => 'no-cache',
);
// Include Basic auth in loopback requests.
if ( isset( $_SERVER['PHP_AUTH_USER'] ) && isset( $_SERVER['PHP_AUTH_PW'] ) ) {
$headers['Authorization'] = 'Basic ' . base64_encode( wp_unslash( $_SERVER['PHP_AUTH_USER'] ) . ':' . wp_unslash( $_SERVER['PHP_AUTH_PW'] ) );
}
$url = add_query_arg(
array(
'health-check-test-wp_version_check' => true,
),
admin_url()
);
$test = wp_remote_get( $url, compact( 'cookies', 'headers', 'timeout' ) );
$response = wp_remote_retrieve_body( $test );
if ( 'yes' !== $response ) {
return array(
'description' => sprintf(
/* translators: %s: Name of the filter used. */
__( 'A plugin has prevented updates by disabling %s.' ),
'<code>wp_version_check()</code>'
),
'severity' => 'fail',
);
}
}
/**
* Check if automatic updates are disabled by a filter.
*
* @since 5.2.0
*
* @return array The test results.
*/
public function test_filters_automatic_updater_disabled() {
if ( apply_filters( 'automatic_updater_disabled', false ) ) {
return array(
'description' => sprintf(
/* translators: %s: Name of the filter used. */
__( 'The %s filter is enabled.' ),
'<code>automatic_updater_disabled</code>'
),
'severity' => 'fail',
);
}
}
/**
* Check if automatic updates have tried to run, but failed, previously.
*
* @since 5.2.0
*
* @return array|bool The test results. false if the auto updates failed.
*/
function test_if_failed_update() {
$failed = get_site_option( 'auto_core_update_failed' );
if ( ! $failed ) {
return false;
}
if ( ! empty( $failed['critical'] ) ) {
$description = __( 'A previous automatic background update ended with a critical failure, so updates are now disabled.' );
$description .= ' ' . __( 'You would have received an email because of this.' );
$description .= ' ' . __( "When you've been able to update using the \"Update Now\" button on Dashboard > Updates, we'll clear this error for future update attempts." );
$description .= ' ' . sprintf(
/* translators: %s: Code of error shown. */
__( 'The error code was %s.' ),
'<code>' . $failed['error_code'] . '</code>'
);
return array(
'description' => $description,
'severity' => 'warning',
);
}
$description = __( 'A previous automatic background update could not occur.' );
if ( empty( $failed['retry'] ) ) {
$description .= ' ' . __( 'You would have received an email because of this.' );
}
$description .= ' ' . __( "We'll try again with the next release." );
$description .= ' ' . sprintf(
/* translators: %s: Code of error shown. */
__( 'The error code was %s.' ),
'<code>' . $failed['error_code'] . '</code>'
);
return array(
'description' => $description,
'severity' => 'warning',
);
}
/**
* Check if WordPress is controlled by a VCS (Git, Subversion etc).
*
* @since 5.2.0
*
* @return array The test results.
*/
public function test_vcs_abspath() {
$context_dirs = array( ABSPATH );
$vcs_dirs = array( '.svn', '.git', '.hg', '.bzr' );
$check_dirs = array();
foreach ( $context_dirs as $context_dir ) {
// Walk up from $context_dir to the root.
do {
$check_dirs[] = $context_dir;
// Once we've hit '/' or 'C:\', we need to stop. dirname will keep returning the input here.
if ( dirname( $context_dir ) == $context_dir ) {
break;
}
// Continue one level at a time.
} while ( $context_dir = dirname( $context_dir ) );
}
$check_dirs = array_unique( $check_dirs );
// Search all directories we've found for evidence of version control.
foreach ( $vcs_dirs as $vcs_dir ) {
foreach ( $check_dirs as $check_dir ) {
// phpcs:ignore
if ( $checkout = @is_dir( rtrim( $check_dir, '\\/' ) . "/$vcs_dir" ) ) {
break 2;
}
}
}
if ( $checkout && ! apply_filters( 'automatic_updates_is_vcs_checkout', true, ABSPATH ) ) {
return array(
'description' => sprintf(
// translators: %1$s: Folder name. %2$s: Version control directory. %3$s: Filter name.
__( 'The folder %1$s was detected as being under version control (%2$s), but the %3$s filter is allowing updates.' ),
'<code>' . $check_dir . '</code>',
"<code>$vcs_dir</code>",
'<code>automatic_updates_is_vcs_checkout</code>'
),
'severity' => 'info',
);
}
if ( $checkout ) {
return array(
'description' => sprintf(
// translators: %1$s: Folder name. %2$s: Version control directory.
__( 'The folder %1$s was detected as being under version control (%2$s).' ),
'<code>' . $check_dir . '</code>',
"<code>$vcs_dir</code>"
),
'severity' => 'fail',
);
}
return array(
'description' => __( 'No version control systems were detected.' ),
'severity' => 'pass',
);
}
/**
* Check if we can access files without providing credentials.
*
* @since 5.2.0
*
* @return array The test results.
*/
function test_check_wp_filesystem_method() {
$skin = new Automatic_Upgrader_Skin;
$success = $skin->request_filesystem_credentials( false, ABSPATH );
if ( ! $success ) {
$description = __( 'Your installation of WordPress prompts for FTP credentials to perform updates.' );
$description .= ' ' . __( '(Your site is performing updates over FTP due to file ownership. Talk to your hosting company.)' );
return array(
'description' => $description,
'severity' => 'fail',
);
}
return array(
'description' => __( "Your installation of WordPress doesn't require FTP credentials to perform updates." ),
'severity' => 'pass',
);
}
/**
* Check if core files are writable by the web user/group.
*
* @since 5.2.0
*
* @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
*
* @return array|bool The test results. false if they're not writeable.
*/
function test_all_files_writable() {
global $wp_filesystem;
include ABSPATH . WPINC . '/version.php'; // $wp_version; // x.y.z
$skin = new Automatic_Upgrader_Skin;
$success = $skin->request_filesystem_credentials( false, ABSPATH );
if ( ! $success ) {
return false;
}
WP_Filesystem();
if ( 'direct' != $wp_filesystem->method ) {
return false;
}
$checksums = get_core_checksums( $wp_version, 'en_US' );
$dev = ( false !== strpos( $wp_version, '-' ) );
// Get the last stable version's files and test against that
if ( ! $checksums && $dev ) {
$checksums = get_core_checksums( (float) $wp_version - 0.1, 'en_US' );
}
// There aren't always checksums for development releases, so just skip the test if we still can't find any
if ( ! $checksums && $dev ) {
return false;
}
if ( ! $checksums ) {
$description = sprintf(
// translators: %s: WordPress version
__( "Couldn't retrieve a list of the checksums for WordPress %s." ),
$wp_version
);
$description .= ' ' . __( 'This could mean that connections are failing to WordPress.org.' );
return array(
'description' => $description,
'severity' => 'warning',
);
}
$unwritable_files = array();
foreach ( array_keys( $checksums ) as $file ) {
if ( 'wp-content' == substr( $file, 0, 10 ) ) {
continue;
}
if ( ! file_exists( ABSPATH . '/' . $file ) ) {
continue;
}
if ( ! is_writable( ABSPATH . '/' . $file ) ) {
$unwritable_files[] = $file;
}
}
if ( $unwritable_files ) {
if ( count( $unwritable_files ) > 20 ) {
$unwritable_files = array_slice( $unwritable_files, 0, 20 );
$unwritable_files[] = '...';
}
return array(
'description' => __( 'Some files are not writable by WordPress:' ) . ' <ul><li>' . implode( '</li><li>', $unwritable_files ) . '</li></ul>',
'severity' => 'fail',
);
} else {
return array(
'description' => __( 'All of your WordPress files are writable.' ),
'severity' => 'pass',
);
}
}
/**
* Check if the install is using a development branch and can use nightly packages.
*
* @since 5.2.0
*
* @return array|bool The test results. false if it isn't a development version.
*/
function test_accepts_dev_updates() {
include ABSPATH . WPINC . '/version.php'; // $wp_version; // x.y.z
// Only for dev versions
if ( false === strpos( $wp_version, '-' ) ) {
return false;
}
if ( defined( 'WP_AUTO_UPDATE_CORE' ) && ( 'minor' === WP_AUTO_UPDATE_CORE || false === WP_AUTO_UPDATE_CORE ) ) {
return array(
'description' => sprintf(
/* translators: %s: Name of the constant used. */
__( 'WordPress development updates are blocked by the %s constant.' ),
'<code>WP_AUTO_UPDATE_CORE</code>'
),
'severity' => 'fail',
);
}
if ( ! apply_filters( 'allow_dev_auto_core_updates', $wp_version ) ) {
return array(
'description' => sprintf(
/* translators: %s: Name of the filter used. */
__( 'WordPress development updates are blocked by the %s filter.' ),
'<code>allow_dev_auto_core_updates</code>'
),
'severity' => 'fail',
);
}
}
/**
* Check if the site supports automatic minor updates.
*
* @since 5.2.0
*
* @return array The test results.
*/
function test_accepts_minor_updates() {
if ( defined( 'WP_AUTO_UPDATE_CORE' ) && false === WP_AUTO_UPDATE_CORE ) {
return array(
'description' => sprintf(
/* translators: %s: Name of the constant used. */
__( 'WordPress security and maintenance releases are blocked by %s.' ),
"<code>define( 'WP_AUTO_UPDATE_CORE', false );</code>"
),
'severity' => 'fail',
);
}
if ( ! apply_filters( 'allow_minor_auto_core_updates', true ) ) {
return array(
'description' => sprintf(
/* translators: %s: Name of the filter used. */
__( 'WordPress security and maintenance releases are blocked by the %s filter.' ),
'<code>allow_minor_auto_core_updates</code>'
),
'severity' => 'fail',
);
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -263,6 +263,7 @@ $menu[75] = array( __( 'Tools' ), 'edit_posts', 'tools.php',
$submenu['tools.php'][5] = array( __( 'Available Tools' ), 'edit_posts', 'tools.php' );
$submenu['tools.php'][10] = array( __( 'Import' ), 'import', 'import.php' );
$submenu['tools.php'][15] = array( __( 'Export' ), 'export', 'export.php' );
$submenu['tools.php'][20] = array( __( 'Site Health' ), 'install_plugins', 'site-health.php' );
if ( is_multisite() && ! is_main_site() ) {
$submenu['tools.php'][25] = array( __( 'Delete Site' ), 'delete_site', 'ms-delete-site.php' );
}

View File

@ -0,0 +1,168 @@
<?php
/**
* Tools Administration Screen.
*
* @package WordPress
* @subpackage Administration
*/
/** WordPress Administration Bootstrap */
require_once( dirname( __FILE__ ) . '/admin.php' );
if ( ! current_user_can( 'install_plugins' ) ) {
wp_die( __( 'Sorry, you do not have permission to access the debug data.' ), '', array( 'reponse' => 401 ) );
}
wp_enqueue_style( 'site-health' );
wp_enqueue_script( 'site-health' );
if ( ! class_exists( 'WP_Debug_Data' ) ) {
require_once( ABSPATH . 'wp-admin/includes/class-wp-debug-data.php' );
}
if ( ! class_exists( 'WP_Site_Health' ) ) {
require_once( ABSPATH . 'wp-admin/includes/class-wp-site-health.php' );
}
$health_check_site_status = new WP_Site_Health();
require_once( ABSPATH . 'wp-admin/admin-header.php' );
?>
<div class="wrap health-check-header">
<div class="title-section">
<h1>
<?php _ex( 'Site Health', 'Menu, Section and Page Title' ); ?>
</h1>
<div id="progressbar" class="loading" data-pct="0" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" aria-valuetext="<?php esc_attr_e( 'Site tests are running, please wait a moment.' ); ?>">
<svg width="100%" height="100%" viewBox="0 0 200 200" version="1.1" xmlns="http://www.w3.org/2000/svg">
<circle r="90" cx="100" cy="100" fill="transparent" stroke-dasharray="565.48" stroke-dashoffset="0"></circle>
<circle id="bar" r="90" cx="100" cy="100" fill="transparent" stroke-dasharray="565.48" stroke-dashoffset="0"></circle>
</svg>
</div>
</div>
<nav class="tabs-wrapper" aria-label="<?php esc_attr_e( 'Secondary menu' ); ?>">
<a href="<?php echo esc_url( admin_url( 'site-health.php' ) ); ?>" class="tab">
<?php _e( 'Status' ); ?>
</a>
<a href="<?php echo esc_url( admin_url( 'site-health.php?tab=debug' ) ); ?>" class="tab active" aria-current="true">
<?php _e( 'Info' ); ?>
</a>
</nav>
<div class="wp-clearfix"></div>
</div>
<div class="wrap health-check-body">
<?php
WP_Debug_Data::check_for_updates();
$info = WP_Debug_Data::debug_data();
?>
<h2>
<?php _e( 'Site Info' ); ?>
</h2>
<p>
<?php _e( 'You can export the information on this page so it can be easily copied and pasted in support requests such as on the WordPress.org forums, or shared with your website / theme / plugin developers.' ); ?>
</p>
<div class="system-information-copy-wrapper">
<textarea id="system-information-default-copy-field" readonly><?php WP_Debug_Data::textarea_format( $info ); ?></textarea>
<?php
if ( 0 !== strpos( get_locale(), 'en' ) ) :
$english_info = WP_Debug_Data::debug_data( 'en_US' );
?>
<textarea id="system-information-english-copy-field" readonly><?php WP_Debug_Data::textarea_format( $english_info ); ?></textarea>
<?php endif; ?>
<div class="copy-button-wrapper">
<button type="button" class="button button-primary health-check-copy-field" data-copy-field="default"><?php _e( 'Copy to clipboard' ); ?></button>
<span class="copy-field-success" aria-hidden="true">Copied!</span>
</div>
<?php if ( 0 !== strpos( get_locale(), 'en' ) ) : ?>
<div class="copy-button-wrapper">
<button type="button" class="button health-check-copy-field" data-copy-field="english"><?php _e( 'Copy to clipboard (English)' ); ?></button>
<span class="copy-field-success" aria-hidden="true">Copied!</span>
</div>
<?php endif; ?>
</div>
<dl id="health-check-debug" role="presentation" class="health-check-accordion">
<?php
foreach ( $info as $section => $details ) {
if ( ! isset( $details['fields'] ) || empty( $details['fields'] ) ) {
continue;
}
?>
<dt role="heading" aria-level="3">
<button aria-expanded="false" class="health-check-accordion-trigger" aria-controls="health-check-accordion-block-<?php echo esc_attr( $section ); ?>" id="health-check-accordion-heading-<?php echo esc_attr( $section ); ?>" type="button">
<span class="title">
<?php echo esc_html( $details['label'] ); ?>
<?php if ( isset( $details['show_count'] ) && $details['show_count'] ) : ?>
<?php printf( '(%d)', count( $details['fields'] ) ); ?>
<?php endif; ?>
</span>
<span class="icon"></span>
</button>
</dt>
<dd id="health-check-accordion-block-<?php echo esc_attr( $section ); ?>" role="region" aria-labelledby="health-check-accordion-heading-<?php echo esc_attr( $section ); ?>" class="health-check-accordion-panel" hidden="hidden">
<?php
if ( isset( $details['description'] ) && ! empty( $details['description'] ) ) {
printf(
'<p>%s</p>',
wp_kses(
$details['description'],
array(
'a' => array(
'href' => true,
),
'strong' => true,
'em' => true,
)
)
);
}
?>
<table class="widefat striped health-check-table">
<tbody>
<?php
foreach ( $details['fields'] as $field ) {
if ( is_array( $field['value'] ) ) {
$values = '';
foreach ( $field['value'] as $name => $value ) {
$values .= sprintf(
'<li>%s: %s</li>',
esc_html( $name ),
esc_html( $value )
);
}
} else {
$values = esc_html( $field['value'] );
}
printf(
'<tr><td>%s</td><td>%s</td></tr>',
esc_html( $field['label'] ),
$values
);
}
?>
</tbody>
</table>
</dd>
<?php } ?>
</dl>
</div>
<?php
include( ABSPATH . 'wp-admin/admin-footer.php' );

View File

@ -0,0 +1,131 @@
<?php
/**
* Tools Administration Screen.
*
* @package WordPress
* @subpackage Administration
*/
if ( isset( $_GET['tab'] ) && 'debug' === $_GET['tab'] ) {
require_once( dirname( __FILE__ ) . '/site-health-info.php' );
return;
}
/** WordPress Administration Bootstrap */
require_once( dirname( __FILE__ ) . '/admin.php' );
if ( ! current_user_can( 'install_plugins' ) ) {
wp_die( __( 'Sorry, you do not have permission to access site health information.' ), '', array( 'reponse' => 401 ) );
}
wp_enqueue_style( 'site-health' );
wp_enqueue_script( 'site-health' );
if ( ! class_exists( 'WP_Site_Health' ) ) {
require_once( ABSPATH . 'wp-admin/includes/class-wp-site-health.php' );
}
$health_check_site_status = new WP_Site_Health();
require_once( ABSPATH . 'wp-admin/admin-header.php' );
?>
<div class="wrap health-check-header">
<div class="title-section">
<h1>
<?php _ex( 'Site Health', 'Menu, Section and Page Title' ); ?>
</h1>
<div id="progressbar" class="loading" data-pct="0" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" aria-valuetext="<?php esc_attr_e( 'Site tests are running, please wait a moment.' ); ?>">
<svg width="100%" height="100%" viewBox="0 0 200 200" version="1.1" xmlns="http://www.w3.org/2000/svg">
<circle r="90" cx="100" cy="100" fill="transparent" stroke-dasharray="565.48" stroke-dashoffset="0"></circle>
<circle id="bar" r="90" cx="100" cy="100" fill="transparent" stroke-dasharray="565.48" stroke-dashoffset="0"></circle>
</svg>
</div>
</div>
<nav class="tabs-wrapper" aria-label="<?php esc_attr_e( 'Secondary menu' ); ?>">
<a href="<?php echo esc_url( admin_url( 'site-health.php' ) ); ?>" class="tab active" aria-current="true">
<?php _e( 'Status' ); ?>
</a>
<a href="<?php echo esc_url( admin_url( 'site-health.php?tab=debug' ) ); ?>" class="tab">
<?php _e( 'Info' ); ?>
</a>
</nav>
<div class="wp-clearfix"></div>
</div>
<div class="wrap health-check-body">
<div class="site-status-all-clear hide">
<p class="icon">
<span class="dashicons dashicons-yes"></span>
</p>
<p class="encouragement">
<?php _e( 'Great job!' ); ?>
</p>
<p>
<?php _e( 'Everything is running smoothly here.' ); ?>
</p>
</div>
<div class="site-status-has-issues">
<h2>
<?php _e( 'Site Health Status' ); ?>
</h2>
<p><?php _e( 'The site health check shows critical information about your WordPress configuration and items that require your attention.' ); ?></p>
<div class="issues-wrapper" id="health-check-issues-critical">
<h3>
<span class="issue-count">0</span> <?php _e( 'Critical issues' ); ?>
</h3>
<dl id="health-check-site-status-critical" role="presentation" class="health-check-accordion issues"></dl>
</div>
<div class="issues-wrapper" id="health-check-issues-recommended">
<h3>
<span class="issue-count">0</span> <?php _e( 'Recommended improvements' ); ?>
</h3>
<dl id="health-check-site-status-recommended" role="presentation" class="health-check-accordion issues"></dl>
</div>
</div>
<div class="view-more">
<button type="button" class="button site-health-view-passed" aria-expanded="false">
<?php _e( 'Show passed tests' ); ?>
</button>
</div>
<div class="issues-wrapper hidden" id="health-check-issues-good">
<h3>
<span class="issue-count">0</span> <?php _e( 'Items with no issues detected' ); ?>
</h3>
<dl id="health-check-site-status-good" role="presentation" class="health-check-accordion issues"></dl>
</div>
</div>
<script id="tmpl-health-check-issue" type="text/template">
<dt role="heading" aria-level="4">
<button aria-expanded="false" class="health-check-accordion-trigger" aria-controls="health-check-accordion-block-{{ data.test }}" id="health-check-accordion-heading-{{ data.test }}" type="button">
<span class="title">{{ data.label }}</span>
<span class="badge {{ data.badge.color }}">{{ data.badge.label }}</span>
<span class="icon"></span>
</button>
</dt>
<dd id="health-check-accordion-block-{{ data.test }}" aria-labelledby="health-check-accordion-heading-{{ data.test }}" role="region" class="health-check-accordion-panel" hidden="hidden">
{{{ data.description }}}
<div class="actions">
<p class="button-container">{{{ data.actions }}}</p>
</div>
</dd>
</script>
<?php
include( ABSPATH . 'wp-admin/admin-footer.php' );

View File

@ -1688,6 +1688,8 @@ function wp_default_scripts( &$scripts ) {
)
);
$scripts->add( 'site-health', "/wp-admin/js/site-health$suffix.js", array( 'jquery', 'wp-util', 'wp-a11y' ), false, 1 );
$scripts->add( 'updates', "/wp-admin/js/updates$suffix.js", array( 'jquery', 'wp-util', 'wp-a11y' ), false, 1 );
did_action( 'init' ) && $scripts->localize(
'updates',
@ -1933,6 +1935,7 @@ function wp_default_styles( &$styles ) {
$styles->add( 'site-icon', "/wp-admin/css/site-icon$suffix.css" );
$styles->add( 'l10n', "/wp-admin/css/l10n$suffix.css" );
$styles->add( 'code-editor', "/wp-admin/css/code-editor$suffix.css", array( 'wp-codemirror' ) );
$styles->add( 'site-health', "/wp-admin/css/site-health$suffix.css" );
$styles->add( 'wp-admin', false, array( 'dashicons', 'common', 'forms', 'admin-menu', 'dashboard', 'list-tables', 'edit', 'revisions', 'media', 'themes', 'about', 'nav-menus', 'widgets', 'site-icon', 'l10n' ) );