wppaste
WordPress

WP_Automatic_Updater::should_update( string $type, object $item, string $context ): bool

Since
3.7.0
Source
wp-admin/includes/class-wp-automatic-updater.php:195
Tests to see if we can and should update a specific item.

Compatibility

WordPress
since 3.7.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Parameters

$typestring
The type of update being checked: 'core', 'theme', 'plugin', 'translation'.
$itemobject
The update offer.
$contextstring
The filesystem context (a path) against which filesystem access and status should be checked.

Return value

bool
True if the item should be updated, false otherwise.

Performance profile

How much work a call to WP_Automatic_Updater::should_update() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Heavy

Reads or writes the filesystem via file_exists().

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
10–102

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 128.

Plugin surface
1 hook

Third-party callbacks on 'auto_update_{$type}' run inside this call, and their cost is not bounded by anything here.

Called by
1

1 place in core call this, so the cost is paid more often than your own code shows.

What it touches

  • optionnetwork optionget_site_option()called directly
  • hookthird-party callbacksapply_filters()called directly
  • filesystemfilesystem accessfile_exists()called directly

Further down the call graph this can also reach cache, serialize, query and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 33 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Automatic_Updater::should_update() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
->is_disabled()10->is_disabled()
!->is_disabled() && $type !== "core" && !->request_filesystem_credentials()21–26->is_disabled(), ->request_filesystem_credentials()
!->is_disabled() && !->request_filesystem_credentials() && $type === "core"24–29->is_disabled(), ->request_filesystem_credentials(), ->send_core_update_notification_email()
!->is_disabled() && $type !== "core" && ->request_filesystem_credentials() && ->is_vcs_checkout()25–30->is_disabled(), ->request_filesystem_credentials(), ->is_vcs_checkout()
!->is_disabled() && ->request_filesystem_credentials() && ->is_vcs_checkout() && $type === "core"28–33->is_disabled(), ->request_filesystem_credentials(), ->is_vcs_checkout(), ->send_core_update_notification_email()
!->is_disabled() && $type !== "core" && ->request_filesystem_credentials() && !->is_vcs_checkout()42–54->is_disabled(), ->request_filesystem_credentials(), ->is_vcs_checkout(), apply_filters()
!->is_disabled() && ->request_filesystem_credentials() && !->is_vcs_checkout()44–54->is_disabled(), ->request_filesystem_credentials(), ->is_vcs_checkout(), ::Core_Upgrader(), apply_filters()
!->is_disabled() && ->request_filesystem_credentials() && !->is_vcs_checkout() && $value45–53->is_disabled(), ->request_filesystem_credentials(), ->is_vcs_checkout(), apply_filters(), ->send_core_update_notification_email()
!->is_disabled() && $type !== "core" && ->request_filesystem_credentials() && !->is_vcs_checkout() && $value && !wp_is_auto_update_enabled_for_type()46–58->is_disabled(), ->request_filesystem_credentials(), ->is_vcs_checkout(), wp_is_auto_update_enabled_for_type(), apply_filters()
!->is_disabled() && ->request_filesystem_credentials() && !->is_vcs_checkout() && $type === "core" && $value47–53->is_disabled(), ->request_filesystem_credentials(), ->is_vcs_checkout(), ::Core_Upgrader(), apply_filters(), ->send_core_update_notification_email()
!->is_disabled() && ->request_filesystem_credentials() && !->is_vcs_checkout() && $value && !wp_is_auto_update_enabled_for_type()49–57->is_disabled(), ->request_filesystem_credentials(), ->is_vcs_checkout(), wp_is_auto_update_enabled_for_type(), apply_filters(), ->send_core_update_notification_email()
!->is_disabled() && $type !== "core" && ->request_filesystem_credentials() && !->is_vcs_checkout() && !$value && $type && !empty($item)53–61->is_disabled(), ->request_filesystem_credentials(), ->is_vcs_checkout(), apply_filters(), version_compare()
21 further outcomes, up to 102 instructions
!->is_disabled() && ->request_filesystem_credentials() && !->is_vcs_checkout() && !$value && $type && !empty($item)55–61->is_disabled(), ->request_filesystem_credentials(), ->is_vcs_checkout(), ::Core_Upgrader(), apply_filters(), version_compare()
!->is_disabled() && $type !== "core" && ->request_filesystem_credentials() && !->is_vcs_checkout() && !wp_is_auto_update_enabled_for_type() && $type && !empty($item)57–65->is_disabled(), ->request_filesystem_credentials(), ->is_vcs_checkout(), wp_is_auto_update_enabled_for_type(), apply_filters(), version_compare()
!->is_disabled() && $type !== "core" && ->request_filesystem_credentials() && !->is_vcs_checkout() && $value && wp_is_auto_update_enabled_for_type()58–70->is_disabled(), ->request_filesystem_credentials(), ->is_vcs_checkout(), wp_is_auto_update_enabled_for_type(), get_site_option(), apply_filters()
!->is_disabled() && ->request_filesystem_credentials() && !->is_vcs_checkout() && !$value && file_exists() && empty($wpdb)60–73->is_disabled(), ->request_filesystem_credentials(), ->is_vcs_checkout(), apply_filters(), version_compare(), file_exists()
!->is_disabled() && ->request_filesystem_credentials() && !->is_vcs_checkout() && $value && wp_is_auto_update_enabled_for_type()61–69->is_disabled(), ->request_filesystem_credentials(), ->is_vcs_checkout(), wp_is_auto_update_enabled_for_type(), get_site_option(), apply_filters(), ->send_core_update_notification_email()
!->is_disabled() && ->request_filesystem_credentials() && !->is_vcs_checkout() && $type === "core" && !$value && file_exists() && empty($wpdb)62–73->is_disabled(), ->request_filesystem_credentials(), ->is_vcs_checkout(), ::Core_Upgrader(), apply_filters(), version_compare(), file_exists()
!->is_disabled() && ->request_filesystem_credentials() && !->is_vcs_checkout() && !wp_is_auto_update_enabled_for_type() && file_exists() && empty($wpdb)64–77->is_disabled(), ->request_filesystem_credentials(), ->is_vcs_checkout(), wp_is_auto_update_enabled_for_type(), apply_filters(), version_compare(), file_exists()
!->is_disabled() && ->request_filesystem_credentials() && !->is_vcs_checkout() && !$value64–79->is_disabled(), ->request_filesystem_credentials(), ->is_vcs_checkout(), apply_filters(), version_compare(), file_exists(), ->db_version(), version_compare()
!->is_disabled() && ->request_filesystem_credentials() && !->is_vcs_checkout() && $type === "core" && !$value66–79->is_disabled(), ->request_filesystem_credentials(), ->is_vcs_checkout(), ::Core_Upgrader(), apply_filters(), version_compare(), file_exists(), ->db_version(), version_compare()
!->is_disabled() && ->request_filesystem_credentials() && !->is_vcs_checkout() && !wp_is_auto_update_enabled_for_type()68–83->is_disabled(), ->request_filesystem_credentials(), ->is_vcs_checkout(), wp_is_auto_update_enabled_for_type(), apply_filters(), version_compare(), file_exists(), ->db_version(), version_compare()
!->is_disabled() && $type !== "core" && ->request_filesystem_credentials() && !->is_vcs_checkout() && wp_is_auto_update_enabled_for_type() && $type && !empty($item)69–77->is_disabled(), ->request_filesystem_credentials(), ->is_vcs_checkout(), wp_is_auto_update_enabled_for_type(), get_site_option(), apply_filters(), version_compare()
!->is_disabled() && ->request_filesystem_credentials() && !->is_vcs_checkout() && !$value && file_exists() && empty($wpdb) && version_compare() && $type && !empty($item)72–80->is_disabled(), ->request_filesystem_credentials(), ->is_vcs_checkout(), apply_filters(), version_compare(), file_exists(), version_compare()
!->is_disabled() && ->request_filesystem_credentials() && !->is_vcs_checkout() && $type === "core" && !$value && file_exists() && empty($wpdb) && version_compare() && $type && !empty($item)74–80->is_disabled(), ->request_filesystem_credentials(), ->is_vcs_checkout(), ::Core_Upgrader(), apply_filters(), version_compare(), file_exists(), version_compare()
!->is_disabled() && ->request_filesystem_credentials() && !->is_vcs_checkout() && !wp_is_auto_update_enabled_for_type() && file_exists() && empty($wpdb) && version_compare() && $type && !empty($item)76–84->is_disabled(), ->request_filesystem_credentials(), ->is_vcs_checkout(), wp_is_auto_update_enabled_for_type(), apply_filters(), version_compare(), file_exists(), version_compare()
!->is_disabled() && ->request_filesystem_credentials() && !->is_vcs_checkout() && wp_is_auto_update_enabled_for_type() && file_exists() && empty($wpdb)76–89->is_disabled(), ->request_filesystem_credentials(), ->is_vcs_checkout(), wp_is_auto_update_enabled_for_type(), get_site_option(), apply_filters(), version_compare(), file_exists()
!->is_disabled() && ->request_filesystem_credentials() && !->is_vcs_checkout() && !$value && version_compare() && $type && !empty($item)76–86->is_disabled(), ->request_filesystem_credentials(), ->is_vcs_checkout(), apply_filters(), version_compare(), file_exists(), ->db_version(), version_compare(), version_compare()
!->is_disabled() && ->request_filesystem_credentials() && !->is_vcs_checkout() && $type === "core" && !$value && version_compare() && $type && !empty($item)78–86->is_disabled(), ->request_filesystem_credentials(), ->is_vcs_checkout(), ::Core_Upgrader(), apply_filters(), version_compare(), file_exists(), ->db_version(), version_compare(), version_compare()
!->is_disabled() && ->request_filesystem_credentials() && !->is_vcs_checkout() && !wp_is_auto_update_enabled_for_type() && version_compare() && $type && !empty($item)80–90->is_disabled(), ->request_filesystem_credentials(), ->is_vcs_checkout(), wp_is_auto_update_enabled_for_type(), apply_filters(), version_compare(), file_exists(), ->db_version(), version_compare(), version_compare()
!->is_disabled() && ->request_filesystem_credentials() && !->is_vcs_checkout() && wp_is_auto_update_enabled_for_type()80–95->is_disabled(), ->request_filesystem_credentials(), ->is_vcs_checkout(), wp_is_auto_update_enabled_for_type(), get_site_option(), apply_filters(), version_compare(), file_exists(), ->db_version(), version_compare()
!->is_disabled() && ->request_filesystem_credentials() && !->is_vcs_checkout() && wp_is_auto_update_enabled_for_type() && file_exists() && empty($wpdb) && version_compare() && $type && !empty($item)88–96->is_disabled(), ->request_filesystem_credentials(), ->is_vcs_checkout(), wp_is_auto_update_enabled_for_type(), get_site_option(), apply_filters(), version_compare(), file_exists(), version_compare()
!->is_disabled() && ->request_filesystem_credentials() && !->is_vcs_checkout() && wp_is_auto_update_enabled_for_type() && version_compare() && $type && !empty($item)92–102->is_disabled(), ->request_filesystem_credentials(), ->is_vcs_checkout(), wp_is_auto_update_enabled_for_type(), get_site_option(), apply_filters(), version_compare(), file_exists(), ->db_version(), version_compare(), version_compare()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev12810–10223
8.512810–10223
8.412810–102233 fewer instructions than PHP 8.3
8.313110–10523
8.213110–10523
8.113110–10523
7.413110–10523

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Hooks and filters fired · 1

One hook fires while WP_Automatic_Updater::should_update() runs, in this order:

  1. apply_filters( auto_update_{$type} )filterline 268 (+73 into the body)

    Filters whether to automatically update core, a plugin, a theme, or a language.

Uses · 8

Used by · 1

Source code

	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 );		} elseif ( 'plugin' === $type || 'theme' === $type ) {			$update = ! empty( $item->autoupdate ); 			if ( ! $update && wp_is_auto_update_enabled_for_type( $type ) ) {				// Check if the site admin has enabled auto-updates by default for the specific item.				$auto_updates = (array) get_site_option( "auto_update_{$type}s", array() );				$update       = in_array( $item->{$type}, $auto_updates, true );			}		} else {			$update = ! empty( $item->autoupdate );		} 		// If the `disable_autoupdate` flag is set, override any user-choice, but allow filters.		if ( ! empty( $item->disable_autoupdate ) ) {			$update = false;		} 		/**		 * 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.		 *		 * Possible hook names include:		 *		 *  - `auto_update_core`		 *  - `auto_update_plugin`		 *  - `auto_update_theme`		 *  - `auto_update_translation`		 *		 * Since WordPress 3.7, minor and development versions of core, and translations have		 * been auto-updated by default. New installs on WordPress 5.6 or higher will also		 * auto-update major versions by default. Starting in 5.6, older sites can opt-in to		 * major version auto-updates, and auto-updates for plugins and themes.		 *		 * 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		 * @since 5.5.0 The `$update` parameter accepts the value of null.		 *		 * @param bool|null $update Whether to update. The value of null is internally used		 *                          to detect whether nothing has hooked into this filter.		 * @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;

Changelog

Introduced in 3.7.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.0.4 tag, from src/wp-admin/includes/class-wp-automatic-updater.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.