WP_Site_Health::detect_plugin_theme_auto_update_issues(): object

In this article

Checks for potential issues with plugin and theme auto-updates.

Description

Though there is no way to 100% determine if plugin and theme auto-updates are configured correctly, a few educated guesses could be made to flag any conditions that would potentially cause unexpected behaviors.

Return

object The test results.

Source

public function detect_plugin_theme_auto_update_issues() {
	$mock_plugin = (object) array(
		'id'            => 'w.org/plugins/a-fake-plugin',
		'slug'          => 'a-fake-plugin',
		'plugin'        => 'a-fake-plugin/a-fake-plugin.php',
		'new_version'   => '9.9',
		'url'           => 'https://wordpress.org/plugins/a-fake-plugin/',
		'package'       => 'https://downloads.wordpress.org/plugin/a-fake-plugin.9.9.zip',
		'icons'         => array(
			'2x' => 'https://ps.w.org/a-fake-plugin/assets/icon-256x256.png',
			'1x' => 'https://ps.w.org/a-fake-plugin/assets/icon-128x128.png',
		),
		'banners'       => array(
			'2x' => 'https://ps.w.org/a-fake-plugin/assets/banner-1544x500.png',
			'1x' => 'https://ps.w.org/a-fake-plugin/assets/banner-772x250.png',
		),
		'banners_rtl'   => array(),
		'tested'        => '5.5.0',
		'requires_php'  => '5.6.20',
		'compatibility' => new stdClass(),
	);

	$mock_theme = (object) array(
		'theme'        => 'a-fake-theme',
		'new_version'  => '9.9',
		'url'          => 'https://wordpress.org/themes/a-fake-theme/',
		'package'      => 'https://downloads.wordpress.org/theme/a-fake-theme.9.9.zip',
		'requires'     => '5.0.0',
		'requires_php' => '5.6.20',
	);

	$test_plugins_enabled = wp_is_auto_update_forced_for_item( 'plugin', true, $mock_plugin );
	$test_themes_enabled  = wp_is_auto_update_forced_for_item( 'theme', true, $mock_theme );

	$ui_enabled_for_plugins = wp_is_auto_update_enabled_for_type( 'plugin' );
	$ui_enabled_for_themes  = wp_is_auto_update_enabled_for_type( 'theme' );
	$plugin_filter_present  = has_filter( 'auto_update_plugin' );
	$theme_filter_present   = has_filter( 'auto_update_theme' );

	if ( ( ! $test_plugins_enabled && $ui_enabled_for_plugins )
		|| ( ! $test_themes_enabled && $ui_enabled_for_themes )
	) {
		return (object) array(
			'status'  => 'critical',
			'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.' ),
		);
	}

	if ( ( ! $test_plugins_enabled && $plugin_filter_present )
		&& ( ! $test_themes_enabled && $theme_filter_present )
	) {
		return (object) array(
			'status'  => 'recommended',
			'message' => __( 'Auto-updates for plugins and themes appear to be disabled. This will prevent your site from receiving new versions automatically when available.' ),
		);
	} elseif ( ! $test_plugins_enabled && $plugin_filter_present ) {
		return (object) array(
			'status'  => 'recommended',
			'message' => __( 'Auto-updates for plugins appear to be disabled. This will prevent your site from receiving new versions automatically when available.' ),
		);
	} elseif ( ! $test_themes_enabled && $theme_filter_present ) {
		return (object) array(
			'status'  => 'recommended',
			'message' => __( 'Auto-updates for themes appear to be disabled. This will prevent your site from receiving new versions automatically when available.' ),
		);
	}

	return (object) array(
		'status'  => 'good',
		'message' => __( 'There appear to be no issues with plugin and theme auto-updates.' ),
	);
}

Changelog

VersionDescription
5.5.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.