rebase on oct-10-2023

This commit is contained in:
Rachit Bhargava
2023-10-10 17:23:21 -04:00
parent d37566ffb6
commit d096058d7d
4789 changed files with 254611 additions and 307223 deletions

View File

@@ -18,7 +18,7 @@ class WP_Site_Health {
private $mysql_server_version = '';
private $mysql_required_version = '5.5';
private $mysql_recommended_version = '5.7';
private $mariadb_recommended_version = '10.3';
private $mariadb_recommended_version = '10.4';
public $php_memory_limit;
@@ -746,7 +746,7 @@ class WP_Site_Health {
)
),
'actions' => sprintf(
'<p><a href="%s" target="_blank" rel="noopener">%s <span class="screen-reader-text">%s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a></p>',
'<p><a href="%s" target="_blank" rel="noopener">%s<span class="screen-reader-text"> %s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a></p>',
esc_url( wp_get_update_php_url() ),
__( 'Learn more about updating PHP' ),
/* translators: Hidden accessibility text. */
@@ -772,8 +772,10 @@ class WP_Site_Health {
return $result;
}
// The PHP version is still receiving security fixes, but is lower than
// the expected minimum version that will be required by WordPress in the near future.
/*
* The PHP version is still receiving security fixes, but is lower than
* the expected minimum version that will be required by WordPress in the near future.
*/
if ( $response['is_secure'] && $response['is_lower_than_future_minimum'] ) {
// The `is_secure` array key name doesn't actually imply this is a secure version of PHP. It only means it receives security updates.
@@ -892,7 +894,7 @@ class WP_Site_Health {
esc_url( __( 'https://make.wordpress.org/hosting/handbook/handbook/server-environment/#php-extensions' ) ),
'target="_blank" rel="noopener"',
sprintf(
' <span class="screen-reader-text">%s</span><span aria-hidden="true" class="dashicons dashicons-external"></span>',
'<span class="screen-reader-text"> %s</span><span aria-hidden="true" class="dashicons dashicons-external"></span>',
/* translators: Hidden accessibility text. */
__( '(opens in a new tab)' )
)
@@ -1216,7 +1218,7 @@ class WP_Site_Health {
__( 'The SQL server is a required piece of software for the database WordPress uses to store all your site&#8217;s content and settings.' )
),
'actions' => sprintf(
'<p><a href="%s" target="_blank" rel="noopener">%s <span class="screen-reader-text">%s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a></p>',
'<p><a href="%s" target="_blank" rel="noopener">%s<span class="screen-reader-text"> %s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a></p>',
/* translators: Localized version of WordPress requirements if one exists. */
esc_url( __( 'https://wordpress.org/about/requirements/' ) ),
__( 'Learn more about what WordPress requires to run.' ),
@@ -1366,7 +1368,7 @@ class WP_Site_Health {
* libmysql has supported utf8mb4 since 5.5.3, same as the MySQL server.
* mysqlnd has supported utf8mb4 since 5.0.9.
*/
if ( false !== strpos( $mysql_client_version, 'mysqlnd' ) ) {
if ( str_contains( $mysql_client_version, 'mysqlnd' ) ) {
$mysql_client_version = preg_replace( '/^\D+([\d.]+).*/', '$1', $mysql_client_version );
if ( version_compare( $mysql_client_version, '5.0.9', '<' ) ) {
$result['status'] = 'recommended';
@@ -1456,9 +1458,9 @@ class WP_Site_Health {
);
$result['actions'] = sprintf(
'<p><a href="%s" target="_blank" rel="noopener">%s <span class="screen-reader-text">%s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a></p>',
'<p><a href="%s" target="_blank" rel="noopener">%s<span class="screen-reader-text"> %s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a></p>',
/* translators: Localized Support reference. */
esc_url( __( 'https://wordpress.org/support' ) ),
esc_url( __( 'https://wordpress.org/support/forums/' ) ),
__( 'Get help resolving this issue.' ),
/* translators: Hidden accessibility text. */
__( '(opens in a new tab)' )
@@ -1494,7 +1496,7 @@ class WP_Site_Health {
__( 'Debug mode is often enabled to gather more details about an error or site failure, but may contain sensitive information which should not be available on a publicly available website.' )
),
'actions' => sprintf(
'<p><a href="%s" target="_blank" rel="noopener">%s <span class="screen-reader-text">%s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a></p>',
'<p><a href="%s" target="_blank" rel="noopener">%s<span class="screen-reader-text"> %s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a></p>',
/* translators: Documentation explaining debugging in WordPress. */
esc_url( __( 'https://wordpress.org/documentation/article/debugging-in-wordpress/' ) ),
__( 'Learn more about debugging in WordPress.' ),
@@ -1508,7 +1510,7 @@ class WP_Site_Health {
if ( defined( 'WP_DEBUG_LOG' ) && WP_DEBUG_LOG ) {
$result['label'] = __( 'Your site is set to log errors to a potentially public file' );
$result['status'] = ( 0 === strpos( ini_get( 'error_log' ), ABSPATH ) ) ? 'critical' : 'recommended';
$result['status'] = str_starts_with( ini_get( 'error_log' ), ABSPATH ) ? 'critical' : 'recommended';
$result['description'] .= sprintf(
'<p>%s</p>',
@@ -1557,8 +1559,10 @@ class WP_Site_Health {
* @return array The test results.
*/
public function get_test_https_status() {
// Enforce fresh HTTPS detection results. This is normally invoked by using cron,
// but for Site Health it should always rely on the latest results.
/*
* Enforce fresh HTTPS detection results. This is normally invoked by using cron,
* but for Site Health it should always rely on the latest results.
*/
wp_update_https_detection_errors();
$default_update_url = wp_get_default_update_https_url();
@@ -1585,8 +1589,10 @@ class WP_Site_Health {
);
if ( ! wp_is_using_https() ) {
// If the website is not using HTTPS, provide more information
// about whether it is supported and how it can be enabled.
/*
* If the website is not using HTTPS, provide more information
* about whether it is supported and how it can be enabled.
*/
$result['status'] = 'recommended';
$result['label'] = __( 'Your website does not use HTTPS' );
@@ -1840,8 +1846,10 @@ class WP_Site_Health {
require_once ABSPATH . 'wp-admin/includes/class-wp-site-health-auto-updates.php';
}
// Run the auto-update tests in a separate class,
// as there are many considerations to be made.
/*
* Run the auto-update tests in a separate class,
* as there are many considerations to be made.
*/
$automatic_updates = new WP_Site_Health_Auto_Updates();
$tests = $automatic_updates->run_tests();
@@ -1925,6 +1933,183 @@ class WP_Site_Health {
return $result;
}
/**
* Tests available disk space for updates.
*
* @since 6.3.0
*
* @return array The test results.
*/
public function get_test_available_updates_disk_space() {
$available_space = function_exists( 'disk_free_space' ) ? @disk_free_space( WP_CONTENT_DIR . '/upgrade/' ) : false;
$result = array(
'label' => __( 'Disk space available to safely perform updates' ),
'status' => 'good',
'badge' => array(
'label' => __( 'Security' ),
'color' => 'blue',
),
'description' => sprintf(
/* translators: %s: Available disk space in MB or GB. */
'<p>' . __( '%s available disk space was detected, update routines can be performed safely.' ) . '</p>',
size_format( $available_space )
),
'actions' => '',
'test' => 'available_updates_disk_space',
);
if ( false === $available_space ) {
$result['description'] = __( 'Could not determine available disk space for updates.' );
$result['status'] = 'recommended';
} elseif ( $available_space < 20 * MB_IN_BYTES ) {
$result['description'] = __( 'Available disk space is critically low, less than 20 MB available. Proceed with caution, updates may fail.' );
$result['status'] = 'critical';
} elseif ( $available_space < 100 * MB_IN_BYTES ) {
$result['description'] = __( 'Available disk space is low, less than 100 MB available.' );
$result['status'] = 'recommended';
}
return $result;
}
/**
* Tests if plugin and theme temporary backup directories are writable or can be created.
*
* @since 6.3.0
*
* @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
*
* @return array The test results.
*/
public function get_test_update_temp_backup_writable() {
global $wp_filesystem;
$result = array(
'label' => __( 'Plugin and theme temporary backup directory is writable' ),
'status' => 'good',
'badge' => array(
'label' => __( 'Security' ),
'color' => 'blue',
),
'description' => sprintf(
/* translators: %s: wp-content/upgrade-temp-backup */
'<p>' . __( 'The %s directory used to improve the stability of plugin and theme updates is writable.' ) . '</p>',
'<code>wp-content/upgrade-temp-backup</code>'
),
'actions' => '',
'test' => 'update_temp_backup_writable',
);
if ( ! function_exists( 'WP_Filesystem' ) ) {
require_once ABSPATH . '/wp-admin/includes/file.php';
}
ob_start();
$credentials = request_filesystem_credentials( '' );
ob_end_clean();
if ( false === $credentials || ! WP_Filesystem( $credentials ) ) {
$result['status'] = 'recommended';
$result['label'] = __( 'Could not access filesystem' );
$result['description'] = __( 'Unable to connect to the filesystem. Please confirm your credentials.' );
return $result;
}
$wp_content = $wp_filesystem->wp_content_dir();
if ( ! $wp_content ) {
$result['status'] = 'critical';
$result['label'] = __( 'Unable to locate WordPress content directory' );
$result['description'] = sprintf(
/* translators: %s: wp-content */
'<p>' . __( 'The %s directory cannot be located.' ) . '</p>',
'<code>wp-content</code>'
);
return $result;
}
$upgrade_dir_exists = $wp_filesystem->is_dir( "$wp_content/upgrade" );
$upgrade_dir_is_writable = $wp_filesystem->is_writable( "$wp_content/upgrade" );
$backup_dir_exists = $wp_filesystem->is_dir( "$wp_content/upgrade-temp-backup" );
$backup_dir_is_writable = $wp_filesystem->is_writable( "$wp_content/upgrade-temp-backup" );
$plugins_dir_exists = $wp_filesystem->is_dir( "$wp_content/upgrade-temp-backup/plugins" );
$plugins_dir_is_writable = $wp_filesystem->is_writable( "$wp_content/upgrade-temp-backup/plugins" );
$themes_dir_exists = $wp_filesystem->is_dir( "$wp_content/upgrade-temp-backup/themes" );
$themes_dir_is_writable = $wp_filesystem->is_writable( "$wp_content/upgrade-temp-backup/themes" );
if ( $plugins_dir_exists && ! $plugins_dir_is_writable && $themes_dir_exists && ! $themes_dir_is_writable ) {
$result['status'] = 'critical';
$result['label'] = __( 'Plugin and theme temporary backup directories exist but are not writable' );
$result['description'] = sprintf(
/* translators: 1: wp-content/upgrade-temp-backup/plugins, 2: wp-content/upgrade-temp-backup/themes. */
'<p>' . __( 'The %1$s and %2$s directories exist but are not writable. These directories are used to improve the stability of plugin updates. Please make sure the server has write permissions to these directories.' ) . '</p>',
'<code>wp-content/upgrade-temp-backup/plugins</code>',
'<code>wp-content/upgrade-temp-backup/themes</code>'
);
return $result;
}
if ( $plugins_dir_exists && ! $plugins_dir_is_writable ) {
$result['status'] = 'critical';
$result['label'] = __( 'Plugin temporary backup directory exists but is not writable' );
$result['description'] = sprintf(
/* translators: %s: wp-content/upgrade-temp-backup/plugins */
'<p>' . __( 'The %s directory exists but is not writable. This directory is used to improve the stability of plugin updates. Please make sure the server has write permissions to this directory.' ) . '</p>',
'<code>wp-content/upgrade-temp-backup/plugins</code>'
);
return $result;
}
if ( $themes_dir_exists && ! $themes_dir_is_writable ) {
$result['status'] = 'critical';
$result['label'] = __( 'Theme temporary backup directory exists but is not writable' );
$result['description'] = sprintf(
/* translators: %s: wp-content/upgrade-temp-backup/themes */
'<p>' . __( 'The %s directory exists but is not writable. This directory is used to improve the stability of theme updates. Please make sure the server has write permissions to this directory.' ) . '</p>',
'<code>wp-content/upgrade-temp-backup/themes</code>'
);
return $result;
}
if ( ( ! $plugins_dir_exists || ! $themes_dir_exists ) && $backup_dir_exists && ! $backup_dir_is_writable ) {
$result['status'] = 'critical';
$result['label'] = __( 'The temporary backup directory exists but is not writable' );
$result['description'] = sprintf(
/* translators: %s: wp-content/upgrade-temp-backup */
'<p>' . __( 'The %s directory exists but is not writable. This directory is used to improve the stability of plugin and theme updates. Please make sure the server has write permissions to this directory.' ) . '</p>',
'<code>wp-content/upgrade-temp-backup</code>'
);
return $result;
}
if ( ! $backup_dir_exists && $upgrade_dir_exists && ! $upgrade_dir_is_writable ) {
$result['status'] = 'critical';
$result['label'] = __( 'The upgrade directory exists but is not writable' );
$result['description'] = sprintf(
/* translators: %s: wp-content/upgrade */
'<p>' . __( 'The %s directory exists but is not writable. This directory is used for plugin and theme updates. Please make sure the server has write permissions to this directory.' ) . '</p>',
'<code>wp-content/upgrade</code>'
);
return $result;
}
if ( ! $upgrade_dir_exists && ! $wp_filesystem->is_writable( $wp_content ) ) {
$result['status'] = 'critical';
$result['label'] = __( 'The upgrade directory cannot be created' );
$result['description'] = sprintf(
/* translators: 1: wp-content/upgrade, 2: wp-content. */
'<p>' . __( 'The %1$s directory does not exist, and the server does not have write permissions in %2$s to create it. This directory is used for plugin and theme updates. Please make sure the server has write permissions in %2$s.' ) . '</p>',
'<code>wp-content/upgrade</code>',
'<code>wp-content</code>'
);
return $result;
}
return $result;
}
/**
* Tests if loopbacks work as expected.
*
@@ -2295,7 +2480,7 @@ class WP_Site_Health {
);
} else {
$result['actions'] .= sprintf(
'<p><a href="%s" target="_blank" rel="noopener">%s <span class="screen-reader-text">%s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a></p>',
'<p><a href="%s" target="_blank" rel="noopener">%s<span class="screen-reader-text"> %s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a></p>',
__( 'https://developer.wordpress.org/rest-api/frequently-asked-questions/#why-is-authentication-not-working' ),
__( 'Learn how to configure the Authorization header.' ),
/* translators: Hidden accessibility text. */
@@ -2328,7 +2513,7 @@ class WP_Site_Health {
'status' => 'good',
'label' => '',
'actions' => sprintf(
'<p><a href="%1$s" target="_blank" rel="noopener noreferrer">%2$s <span class="screen-reader-text">%3$s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a></p>',
'<p><a href="%1$s" target="_blank" rel="noopener noreferrer">%2$s<span class="screen-reader-text"> %3$s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a></p>',
__( 'https://wordpress.org/documentation/article/optimization/#Caching' ),
__( 'Learn more about page cache' ),
/* translators: Hidden accessibility text. */
@@ -2454,7 +2639,7 @@ class WP_Site_Health {
__( 'A persistent object cache makes your site&#8217;s database more efficient, resulting in faster load times because WordPress can retrieve your site&#8217;s content and settings much more quickly.' )
),
'actions' => sprintf(
'<p><a href="%s" target="_blank" rel="noopener">%s <span class="screen-reader-text">%s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a></p>',
'<p><a href="%s" target="_blank" rel="noopener">%s<span class="screen-reader-text"> %s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a></p>',
esc_url( $action_url ),
__( 'Learn more about persistent object caching.' ),
/* translators: Hidden accessibility text. */
@@ -2532,71 +2717,79 @@ class WP_Site_Health {
public static function get_tests() {
$tests = array(
'direct' => array(
'wordpress_version' => array(
'wordpress_version' => array(
'label' => __( 'WordPress Version' ),
'test' => 'wordpress_version',
),
'plugin_version' => array(
'plugin_version' => array(
'label' => __( 'Plugin Versions' ),
'test' => 'plugin_version',
),
'theme_version' => array(
'theme_version' => array(
'label' => __( 'Theme Versions' ),
'test' => 'theme_version',
),
'php_version' => array(
'php_version' => array(
'label' => __( 'PHP Version' ),
'test' => 'php_version',
),
'php_extensions' => array(
'php_extensions' => array(
'label' => __( 'PHP Extensions' ),
'test' => 'php_extensions',
),
'php_default_timezone' => array(
'php_default_timezone' => array(
'label' => __( 'PHP Default Timezone' ),
'test' => 'php_default_timezone',
),
'php_sessions' => array(
'php_sessions' => array(
'label' => __( 'PHP Sessions' ),
'test' => 'php_sessions',
),
'sql_server' => array(
'sql_server' => array(
'label' => __( 'Database Server version' ),
'test' => 'sql_server',
),
'utf8mb4_support' => array(
'utf8mb4_support' => array(
'label' => __( 'MySQL utf8mb4 support' ),
'test' => 'utf8mb4_support',
),
'ssl_support' => array(
'ssl_support' => array(
'label' => __( 'Secure communication' ),
'test' => 'ssl_support',
),
'scheduled_events' => array(
'scheduled_events' => array(
'label' => __( 'Scheduled events' ),
'test' => 'scheduled_events',
),
'http_requests' => array(
'http_requests' => array(
'label' => __( 'HTTP Requests' ),
'test' => 'http_requests',
),
'rest_availability' => array(
'rest_availability' => array(
'label' => __( 'REST API availability' ),
'test' => 'rest_availability',
'skip_cron' => true,
),
'debug_enabled' => array(
'debug_enabled' => array(
'label' => __( 'Debugging enabled' ),
'test' => 'is_in_debug_mode',
),
'file_uploads' => array(
'file_uploads' => array(
'label' => __( 'File uploads' ),
'test' => 'file_uploads',
),
'plugin_theme_auto_updates' => array(
'plugin_theme_auto_updates' => array(
'label' => __( 'Plugin and theme auto-updates' ),
'test' => 'plugin_theme_auto_updates',
),
'update_temp_backup_writable' => array(
'label' => __( 'Plugin and theme temporary backup directory access' ),
'test' => 'update_temp_backup_writable',
),
'available_updates_disk_space' => array(
'label' => __( 'Available disk space' ),
'test' => 'available_updates_disk_space',
),
),
'async' => array(
'dotorg_communication' => array(
@@ -3140,7 +3333,7 @@ class WP_Site_Health {
public function get_page_cache_headers() {
$cache_hit_callback = static function ( $header_value ) {
return false !== strpos( strtolower( $header_value ), 'hit' );
return str_contains( strtolower( $header_value ), 'hit' );
};
$cache_headers = array(
@@ -3195,9 +3388,11 @@ class WP_Site_Health {
$headers = array();
// Include basic auth in loopback requests. Note that this will only pass along basic auth when user is
// initiating the test. If a site requires basic auth, the test will fail when it runs in WP Cron as part of
// wp_site_health_scheduled_check. This logic is copied from WP_Site_Health::can_perform_loopback().
/*
* Include basic auth in loopback requests. Note that this will only pass along basic auth when user is
* initiating the test. If a site requires basic auth, the test will fail when it runs in WP Cron as part of
* wp_site_health_scheduled_check. This logic is copied from WP_Site_Health::can_perform_loopback().
*/
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'] ) );
}