--- a/wp/wp-admin/includes/class-wp-site-health-auto-updates.php Tue Oct 22 16:11:46 2019 +0200
+++ b/wp/wp-admin/includes/class-wp-site-health-auto-updates.php Tue Dec 15 13:49:49 2020 +0100
@@ -10,10 +10,11 @@
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';
+ require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
}
@@ -26,11 +27,10 @@
*/
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_constants( 'WP_AUTO_UPDATE_CORE', array( true, 'minor' ) ),
$this->test_wp_version_check_attached(),
$this->test_filters_automatic_updater_disabled(),
+ $this->test_wp_automatic_updates_disabled(),
$this->test_if_failed_update(),
$this->test_vcs_abspath(),
$this->test_check_wp_filesystem_method(),
@@ -60,13 +60,17 @@
* Test if auto-updates related constants are set correctly.
*
* @since 5.2.0
+ * @since 5.5.1 The `$value` parameter can accept an array.
*
- * @param string $constant The name of the constant to check.
- * @param bool $value The value that the constant should be, if set.
+ * @param string $constant The name of the constant to check.
+ * @param bool|string|array $value The value that the constant should be, if set,
+ * or an array of acceptable values.
* @return array The test results.
*/
public function test_constants( $constant, $value ) {
- if ( defined( $constant ) && constant( $constant ) != $value ) {
+ $acceptable_values = (array) $value;
+
+ if ( defined( $constant ) && ! in_array( constant( $constant ), $acceptable_values, true ) ) {
return array(
'description' => sprintf(
/* translators: %s: Name of the constant used. */
@@ -95,6 +99,8 @@
$headers = array(
'Cache-Control' => 'no-cache',
);
+ /** This filter is documented in wp-includes/class-wp-http-streams.php */
+ $sslverify = apply_filters( 'https_local_ssl_verify', false );
// Include Basic auth in loopback requests.
if ( isset( $_SERVER['PHP_AUTH_USER'] ) && isset( $_SERVER['PHP_AUTH_PW'] ) ) {
@@ -108,7 +114,7 @@
admin_url( 'site-health.php' )
);
- $test = wp_remote_get( $url, compact( 'cookies', 'headers', 'timeout' ) );
+ $test = wp_remote_get( $url, compact( 'cookies', 'headers', 'timeout', 'sslverify' ) );
if ( is_wp_error( $test ) ) {
return array(
@@ -143,6 +149,7 @@
* @return array The test results.
*/
public function test_filters_automatic_updater_disabled() {
+ /** This filter is documented in wp-admin/includes/class-wp-automatic-updater.php */
if ( apply_filters( 'automatic_updater_disabled', false ) ) {
return array(
'description' => sprintf(
@@ -156,11 +163,35 @@
}
/**
+ * Check if automatic updates are disabled.
+ *
+ * @since 5.3.0
+ *
+ * @return array|bool The test results. False if auto-updates are enabled.
+ */
+ public function test_wp_automatic_updates_disabled() {
+ if ( ! class_exists( 'WP_Automatic_Updater' ) ) {
+ require_once ABSPATH . 'wp-admin/includes/class-wp-automatic-updater.php';
+ }
+
+ $auto_updates = new WP_Automatic_Updater();
+
+ if ( ! $auto_updates->is_disabled() ) {
+ return false;
+ }
+
+ return array(
+ 'description' => __( 'All automatic updates are disabled.' ),
+ '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.
+ * @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' );
@@ -219,7 +250,7 @@
$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 ) {
+ if ( dirname( $context_dir ) === $context_dir ) {
break;
}
@@ -239,10 +270,11 @@
}
}
+ /** This filter is documented in wp-admin/includes/class-wp-automatic-updater.php */
if ( $checkout && ! apply_filters( 'automatic_updates_is_vcs_checkout', true, ABSPATH ) ) {
return array(
'description' => sprintf(
- // translators: 1: Folder name. 2: Version control directory. 3: Filter name.
+ /* translators: 1: Folder name. 2: Version control directory. 3: 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>",
@@ -255,12 +287,12 @@
if ( $checkout ) {
return array(
'description' => sprintf(
- // translators: 1: Folder name. 2: Version control directory.
+ /* translators: 1: Folder name. 2: 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',
+ 'severity' => 'warning',
);
}
@@ -304,12 +336,12 @@
*
* @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
*
- * @return array|bool The test results. false if they're not writeable.
+ * @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
+ require ABSPATH . WPINC . '/version.php'; // $wp_version; // x.y.z
$skin = new Automatic_Upgrader_Skin;
$success = $skin->request_filesystem_credentials( false, ABSPATH );
@@ -320,25 +352,25 @@
WP_Filesystem();
- if ( 'direct' != $wp_filesystem->method ) {
+ 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
+ // 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
+ // 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
+ /* translators: %s: WordPress version. */
__( "Couldn't retrieve a list of the checksums for WordPress %s." ),
$wp_version
);
@@ -351,7 +383,7 @@
$unwritable_files = array();
foreach ( array_keys( $checksums ) as $file ) {
- if ( 'wp-content' == substr( $file, 0, 10 ) ) {
+ if ( 'wp-content' === substr( $file, 0, 10 ) ) {
continue;
}
if ( ! file_exists( ABSPATH . $file ) ) {
@@ -384,11 +416,11 @@
*
* @since 5.2.0
*
- * @return array|bool The test results. false if it isn't a development version.
+ * @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
+ require ABSPATH . WPINC . '/version.php'; // $wp_version; // x.y.z
+ // Only for dev versions.
if ( false === strpos( $wp_version, '-' ) ) {
return false;
}
@@ -404,6 +436,7 @@
);
}
+ /** This filter is documented in wp-admin/includes/class-core-upgrader.php */
if ( ! apply_filters( 'allow_dev_auto_core_updates', $wp_version ) ) {
return array(
'description' => sprintf(
@@ -435,6 +468,7 @@
);
}
+ /** This filter is documented in wp-admin/includes/class-core-upgrader.php */
if ( ! apply_filters( 'allow_minor_auto_core_updates', true ) ) {
return array(
'description' => sprintf(