WordPress at a glance
function is not described

WP_Automatic_Updater::should_update() WP 3.7.0

Tests to see if we can and should update a specific item.

This is a method of the class: WP_Automatic_Updater

Hooks from the method
Return

Null. Nothing.

Usage

$WP_Automatic_Updater = new WP_Automatic_Updater();
$var = $WP_Automatic_Updater->should_update( $type, $item, $context );
$type(string) (required)
The type of update being checked: 'core', 'theme', 'plugin', 'translation'.
$item(object) (required)
The update offer.
$context(string) (required)
The filesystem context (a path) against which filesystem access and status should be checked.

Notes

  • Global. wpdb. $wpdb WordPress database abstraction object.

Changelog

Since 3.7.0 Introduced.

Code of WP Automatic Updater::should update: wp-admin/includes/class-wp-automatic-updater.php WP 5.4.1

<?php
public function should_update( $type, $item, $context ) {
	// Used to see if WP_Filesystem is set up to allow unattended updates.
	$skin = new Automatic_Upgrader_Skin;

	if ( $this->is_disabled() ) {
		return false;
	}

	// Only relax the filesystem checks when the update doesn't include new files.
	$allow_relaxed_file_ownership = false;
	if ( 'core' == $type && isset( $item->new_files ) && ! $item->new_files ) {
		$allow_relaxed_file_ownership = true;
	}

	// If we can't do an auto core update, we may still be able to email the user.
	if ( ! $skin->request_filesystem_credentials( false, $context, $allow_relaxed_file_ownership ) || $this->is_vcs_checkout( $context ) ) {
		if ( 'core' == $type ) {
			$this->send_core_update_notification_email( $item );
		}
		return false;
	}

	// Next up, is this an item we can update?
	if ( 'core' == $type ) {
		$update = Core_Upgrader::should_update_to_version( $item->current );
	} else {
		$update = ! empty( $item->autoupdate );
	}

	/**
	 * Filters whether to automatically update core, a plugin, a theme, or a language.
	 *
	 * The dynamic portion of the hook name, `$type`, refers to the type of update
	 * being checked. Can be 'core', 'theme', 'plugin', or 'translation'.
	 *
	 * Generally speaking, plugins, themes, and major core versions are not updated
	 * by default, while translations and minor and development versions for core
	 * are updated by default.
	 *
	 * See the {@see 'allow_dev_auto_core_updates'}, {@see 'allow_minor_auto_core_updates'},
	 * and {@see 'allow_major_auto_core_updates'} filters for a more straightforward way to
	 * adjust core updates.
	 *
	 * @since 3.7.0
	 *
	 * @param bool   $update Whether to update.
	 * @param object $item   The update offer.
	 */
	$update = apply_filters( "auto_update_{$type}", $update, $item );

	if ( ! $update ) {
		if ( 'core' == $type ) {
			$this->send_core_update_notification_email( $item );
		}
		return false;
	}

	// If it's a core update, are we actually compatible with its requirements?
	if ( 'core' == $type ) {
		global $wpdb;

		$php_compat = version_compare( phpversion(), $item->php_version, '>=' );
		if ( file_exists( WP_CONTENT_DIR . '/db.php' ) && empty( $wpdb->is_mysql ) ) {
			$mysql_compat = true;
		} else {
			$mysql_compat = version_compare( $wpdb->db_version(), $item->mysql_version, '>=' );
		}

		if ( ! $php_compat || ! $mysql_compat ) {
			return false;
		}
	}

	// If updating a plugin, ensure the minimum PHP version requirements are satisfied.
	if ( 'plugin' === $type ) {
		if ( ! empty( $item->requires_php ) && version_compare( phpversion(), $item->requires_php, '<' ) ) {
			return false;
		}
	}

	return true;
}