Make WordPress Core

Changeset 48548


Ignore:
Timestamp:
07/21/2020 05:06:00 PM (4 years ago)
Author:
whyisjake
Message:

Site Health: Add tests to check for potential issues with plugin and theme auto-updates.

Fixes #50662.
Props desrosj, audrasjb.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-site-health.php

    r48539 r48548  
    17301730        if ( 'good' !== $result['status'] ) {
    17311731            $result['description'] .= $output;
     1732        }
     1733
     1734        return $result;
     1735    }
     1736
     1737    /**
     1738     * Test if plugin and theme auto-updates appear to be configured correctly.
     1739     *
     1740     * @since 5.5.0
     1741     *
     1742     * @return array The test results.
     1743     */
     1744    public function get_test_plugin_theme_auto_updates() {
     1745        $result = array(
     1746            'label'       => __( 'Plugin and Theme auto-updates appear to be configured correctly' ),
     1747            'status'      => 'good',
     1748            'badge'       => array(
     1749                'label' => __( 'Security' ),
     1750                'color' => 'blue',
     1751            ),
     1752            'description' => sprintf(
     1753                '<p>%s</p>',
     1754                __( 'Plugin and theme auto updates ensure that the latest versions are always installed.' )
     1755            ),
     1756            'actions'     => '',
     1757            'test'        => 'plugin_theme_auto_updates',
     1758        );
     1759
     1760        $check_plugin_theme_updates = $this->detect_plugin_theme_auto_update_issues();
     1761
     1762        $result['status'] = $check_plugin_theme_updates->status;
     1763
     1764        if ( 'good' !== $check_plugin_theme_updates->status ) {
     1765            $result['label'] = __( 'Your site may have problems auto-updating plugins and themes' );
     1766
     1767            $result['description'] .= sprintf(
     1768                '<p>%s</p>',
     1769                $check_plugin_theme_updates->message
     1770            );
    17321771        }
    17331772
     
    22892328
    22902329    /**
     2330     * Check for potential issues with plugin and theme auto-updates.
     2331     *
     2332     * Though there is no way to 100% determine if plugin and theme auto-updates are configured
     2333     * correctly, a few educated guesses could be made to flag any conditions that would
     2334     * potentially cause unexpected behaviors.
     2335     *
     2336     * @since 5.5.0
     2337     *
     2338     * @return object The test results.
     2339     */
     2340    function detect_plugin_theme_auto_update_issues() {
     2341        $test_plugins_enabled   = apply_filters( 'auto_update_plugin', true );
     2342        $test_themes_enabled    = apply_filters( 'auto_update_theme', true );
     2343        $ui_enabled_for_plugins = wp_is_auto_update_enabled_for_type( 'plugin' );
     2344        $ui_enabled_for_themes  = wp_is_auto_update_enabled_for_type( 'theme' );
     2345        $plugin_filter_present  = has_filter( 'auto_update_plugin' );
     2346        $theme_filter_present   = has_filter( 'auto_update_theme' );
     2347
     2348        if ( ( ! $test_plugins_enabled && $ui_enabled_for_plugins ) || ( $test_themes_enabled && $ui_enabled_for_themes ) ) {
     2349            return (object) array(
     2350                'status'  => 'critical',
     2351                'message' => __( 'Auto-updates for plugins and/or themes appear to be disabled, but settings are still set to be displayed. This could cause auto-updates to not work as expected.' ),
     2352            );
     2353        }
     2354
     2355        if ( ( ! $test_plugins_enabled && $plugin_filter_present ) && ( ! $test_themes_enabled && $theme_filter_present ) ) {
     2356            return (object) array(
     2357                'status'  => 'recommended',
     2358                'message' => __( 'Auto-updates for plugins and themes appear to be disabled. This will prevent your sites from receiving new versions automatically when available.' ),
     2359            );
     2360        } elseif ( ! $test_plugins_enabled && $plugin_filter_present ) {
     2361            return (object) array(
     2362                'status'  => 'recommended',
     2363                'message' => __( 'Auto-updates for plugins appear to be disabled. This will prevent your sites from receiving new versions automatically when available.' ),
     2364            );
     2365        } elseif ( ! $test_themes_enabled && $theme_filter_present ) {
     2366            return (object) array(
     2367                'status'  => 'recommended',
     2368                'message' => __( 'Auto-updates for themes appear to be disabled. This will prevent your sites from receiving new versions automatically when available.' ),
     2369            );
     2370        }
     2371
     2372        return (object) array(
     2373            'status'  => 'good',
     2374            'message' => __( 'There appears to be no issues with plugin and theme auto-updates.' ),
     2375        );
     2376    }
     2377
     2378    /**
    22912379     * Run a loopback test on our site.
    22922380     *
Note: See TracChangeset for help on using the changeset viewer.