Core_Upgrader::should_update_to_version( string $offered_ver ): bool
- Since
- 3.7.0
- Source
wp-admin/includes/class-core-upgrader.php:279
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
$offered_verstring- The offered version, of the format x.y.z.
Return value
bool- True if we should update to the offered version, otherwise false.
Performance profile
How much work a call to Core_Upgrader::should_update_to_version() 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
- Moderate
- Scaling
- Constant
- Instructions
- 54–113
- Plugin surface
- 3 hooks
- Called by
- 1
Reads stored settings via get_site_option(), cached per request but not free on a cold cache.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 133.
Third-party callbacks on 'allow_dev_auto_core_updates', 'allow_minor_auto_core_updates', 'allow_major_auto_core_updates' run inside this call, and their cost is not bounded by anything here.
1 place in core call this, so the cost is paid more often than your own code shows.
What it touches
- optionnetwork option
get_site_option()called directly - hookthird-party callbacks
apply_filters()called directly - regexregular expression over the whole input
preg_split()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 · 9 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost Core_Upgrader::should_update_to_version() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
$offered_ver === false | 54–69 | preg_split(), array_slice(), preg_split(), array_slice(), get_site_option(), get_site_option(), get_site_option() |
$offered_ver !== false && version_compare() | 60–75 | preg_split(), array_slice(), preg_split(), array_slice(), get_site_option(), get_site_option(), get_site_option(), version_compare() |
$offered_ver !== false && !version_compare() | 67–95 | preg_split(), array_slice(), preg_split(), array_slice(), get_site_option(), get_site_option(), get_site_option(), version_compare(), get_site_option() |
$offered_ver !== false && !version_compare() | 71–102 | preg_split(), array_slice(), preg_split(), array_slice(), get_site_option(), get_site_option(), get_site_option(), version_compare(), get_site_option(), apply_filters() |
$offered_ver !== false && !version_compare() && $current_branch !== false | 74–104 | preg_split(), array_slice(), preg_split(), array_slice(), get_site_option(), get_site_option(), get_site_option(), version_compare(), get_site_option(), version_compare() |
$offered_ver !== false && !version_compare() && apply_filters() && $current_branch === false | 77–107 | preg_split(), array_slice(), preg_split(), array_slice(), get_site_option(), get_site_option(), get_site_option(), version_compare(), get_site_option(), apply_filters(), apply_filters() |
$offered_ver !== false && $current_branch !== false | 78–108 | preg_split(), array_slice(), preg_split(), array_slice(), get_site_option(), get_site_option(), get_site_option(), version_compare(), get_site_option(), version_compare(), apply_filters() |
$offered_ver !== false && !version_compare() && apply_filters() && $current_branch !== false | 79–109 | preg_split(), array_slice(), preg_split(), array_slice(), get_site_option(), get_site_option(), get_site_option(), version_compare(), get_site_option(), apply_filters(), version_compare() |
$offered_ver !== false && apply_filters() && $current_branch !== false | 83–113 | preg_split(), array_slice(), preg_split(), array_slice(), get_site_option(), get_site_option(), get_site_option(), version_compare(), get_site_option(), apply_filters(), version_compare(), apply_filters() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 133 | 54–113 | 18 | |
| 8.5 | 133 | 54–113 | 18 | |
| 8.4 | 133 | 54–113 | 18 | 12 fewer instructions than PHP 8.3 |
| 8.3 | 145 | 63–125 | 18 | |
| 8.2 | 145 | 63–125 | 18 | |
| 8.1 | 145 | 63–125 | 18 | |
| 7.4 | 145 | 63–125 | 18 |
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 · 3
3 hooks fire while Core_Upgrader::should_update_to_version() runs, in this order:
- apply_filters( allow_dev_auto_core_updates )filterline 357 (+78 into the body)
Filters whether to enable automatic core updates for development versions.
- apply_filters( allow_minor_auto_core_updates )filterline 373 (+94 into the body)
Filters whether to enable minor automatic core updates.
- apply_filters( allow_major_auto_core_updates )filterline 386 (+107 into the body)
Filters whether to enable major automatic core updates.
Uses · 3
- get_site_option()Retrieve an option value for the current network based on name of option.
- str_contains()Polyfill for `str_contains()` function added in PHP 8.0.
- apply_filters()Calls the callback functions that have been added to a filter hook.
Used by · 1
- WP_Automatic_Updater::should_update()Tests to see if we can and should update a specific item.
Source code
public static function should_update_to_version( $offered_ver ) { require ABSPATH . WPINC . '/version.php'; // $wp_version; // x.y.z $current_branch = implode( '.', array_slice( preg_split( '/[.-]/', $wp_version ), 0, 2 ) ); // x.y $new_branch = implode( '.', array_slice( preg_split( '/[.-]/', $offered_ver ), 0, 2 ) ); // x.y $current_is_development_version = (bool) strpos( $wp_version, '-' ); // Defaults: $upgrade_dev = get_site_option( 'auto_update_core_dev', 'enabled' ) === 'enabled'; $upgrade_minor = get_site_option( 'auto_update_core_minor', 'enabled' ) === 'enabled'; $upgrade_major = get_site_option( 'auto_update_core_major', 'unset' ) === 'enabled'; // WP_AUTO_UPDATE_CORE = true (all), 'beta', 'rc', 'development', 'branch-development', 'minor', false. if ( defined( 'WP_AUTO_UPDATE_CORE' ) ) { if ( false === WP_AUTO_UPDATE_CORE ) { // Defaults to turned off, unless a filter allows it. $upgrade_dev = false; $upgrade_minor = false; $upgrade_major = false; } elseif ( true === WP_AUTO_UPDATE_CORE || in_array( WP_AUTO_UPDATE_CORE, array( 'beta', 'rc', 'development', 'branch-development' ), true ) ) { // ALL updates for core. $upgrade_dev = true; $upgrade_minor = true; $upgrade_major = true; } elseif ( 'minor' === WP_AUTO_UPDATE_CORE ) { // Only minor updates for core. $upgrade_dev = false; $upgrade_minor = true; $upgrade_major = false; } } // 1: If we're already on that version, not much point in updating? if ( $offered_ver === $wp_version ) { return false; } // 2: If we're running a newer version, that's a nope. if ( version_compare( $wp_version, $offered_ver, '>' ) ) { return false; } $failure_data = get_site_option( 'auto_core_update_failed' ); if ( $failure_data ) { // If this was a critical update failure, cannot update. if ( ! empty( $failure_data['critical'] ) ) { return false; } // Don't claim we can update on update-core.php if we have a non-critical failure logged. if ( $wp_version === $failure_data['current'] && str_contains( $offered_ver, '.1.next.minor' ) ) { return false; } /* * Cannot update if we're retrying the same A to B update that caused a non-critical failure. * Some non-critical failures do allow retries, like download_failed. * 3.7.1 => 3.7.2 resulted in files_not_writable, if we are still on 3.7.1 and still trying to update to 3.7.2. */ if ( empty( $failure_data['retry'] ) && $wp_version === $failure_data['current'] && $offered_ver === $failure_data['attempted'] ) { return false; } } // 3: 3.7-alpha-25000 -> 3.7-alpha-25678 -> 3.7-beta1 -> 3.7-beta2. if ( $current_is_development_version ) { /** * Filters whether to enable automatic core updates for development versions. * * @since 3.7.0 * * @param bool $upgrade_dev Whether to enable automatic updates for * development versions. */ if ( ! apply_filters( 'allow_dev_auto_core_updates', $upgrade_dev ) ) { return false;Changelog
Introduced in 3.7.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-admin/includes/class-core-upgrader.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.