From c117b9957f4a94946029cb18d80a27a4f4889289 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 23 Sep 2019 20:52:56 +0000 Subject: [PATCH] Site Health: Use `WP_Automatic_Updater::is_disabled()` to check whether automatic updates are disabled. The previous check for `DISALLOW_FILE_MODS` and `AUTOMATIC_UPDATER_DISABLED` constants didn't always provide accurate results. Props Clorith, kraftner, afragen. Fixes #47869. Built from https://develop.svn.wordpress.org/trunk@46276 git-svn-id: http://core.svn.wordpress.org/trunk@46088 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- .../class-wp-site-health-auto-updates.php | 33 ++++++++++++++++--- wp-includes/version.php | 2 +- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/wp-admin/includes/class-wp-site-health-auto-updates.php b/wp-admin/includes/class-wp-site-health-auto-updates.php index bbd5479829..c07f1dc743 100644 --- a/wp-admin/includes/class-wp-site-health-auto-updates.php +++ b/wp-admin/includes/class-wp-site-health-auto-updates.php @@ -26,11 +26,10 @@ class WP_Site_Health_Auto_Updates { */ 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_wp_automatic_updates_disabled(), $this->test_if_failed_update(), $this->test_vcs_abspath(), $this->test_check_wp_filesystem_method(), @@ -158,12 +157,36 @@ class WP_Site_Health_Auto_Updates { } } + /** + * 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-updates.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' ); @@ -308,7 +331,7 @@ class WP_Site_Health_Auto_Updates { * * @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; @@ -388,7 +411,7 @@ class WP_Site_Health_Auto_Updates { * * @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 diff --git a/wp-includes/version.php b/wp-includes/version.php index 036d4a0c4a..bcd820cfb2 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.3-alpha-46275'; +$wp_version = '5.3-alpha-46276'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.