wppaste
WordPress

wp_version_check( array $extra_stats = array(), bool $force_check = false )

Since
2.3.0
Source
wp-includes/update.php:31
Checks WordPress version against the newest version.

Description

The WordPress version, PHP version, and locale is sent to api.wordpress.org.

Checks against the WordPress server at api.wordpress.org. Will only check if WordPress isn't installing.

Compatibility

WordPress
since 2.3.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

$extra_statsarrayoptional
Extra statistics to report to the WordPress.org API.Default: array()
$force_checkbooloptional
Whether to bypass the transient cache and force a fresh update check.
Defaults to false, true if $extra_stats is set.Default: false

Performance profile

How much work a call to wp_version_check() 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
Expensive

Reaches an outbound HTTP request via wp_remote_post().

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
6–14

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

Plugin surface
3 hooks

Third-party callbacks on 'core_version_check_locale', 'core_version_check_query_args', 'wp_maybe_auto_update' run inside this call, and their cost is not bounded by anything here.

Called by
5

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

What it touches

  • transienttransientget_site_transient()called directly
  • hookthird-party callbacksapply_filters()called directly
  • optionnetwork optionget_site_option()called directly
  • httpoutbound HTTP requestwp_remote_post()called directly
  • cacheobject cachewp_cache_get()one call below wp_version_check()

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

What one call costs · 2 distinct outcomes

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

WhenInstructionsCalls it makes
always6–7none
!$all_unprefixed_tables && str_ends_with()14str_ends_with()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev4906–1443
8.54906–1443
8.44906–144313 fewer instructions than PHP 8.3
8.35036–1443
8.25036–1443
8.15036–1443
7.45036–1443

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 wp_version_check() runs, in this order:

  1. apply_filters( core_version_check_locale )filterline 73 (+42 into the body)

    Filters the locale requested for WordPress core translations.

  2. apply_filters( core_version_check_query_args )filterline 209 (+178 into the body)

    Filters the query arguments sent as part of the core version check.

  3. do_action( wp_maybe_auto_update )actionline 337 (+306 into the body)

    Fires during wp_cron, starting the auto-update process.

Uses · 32

Show all 32

Used by · 5

Source code

function wp_version_check( $extra_stats = array(), $force_check = false ) {	global $wpdb, $wp_local_package; 	if ( wp_installing() ) {		return;	} 	$php_version = PHP_VERSION; 	$current      = get_site_transient( 'update_core' );	$translations = wp_get_installed_translations( 'core' ); 	// Invalidate the transient when $wp_version changes.	if ( is_object( $current ) && wp_get_wp_version() !== $current->version_checked ) {		$current = false;	} 	if ( ! is_object( $current ) ) {		$current                  = new stdClass();		$current->updates         = array();		$current->version_checked = wp_get_wp_version();	} 	if ( ! empty( $extra_stats ) ) {		$force_check = true;	} 	// Wait 1 minute between multiple version check requests.	$timeout          = MINUTE_IN_SECONDS;	$time_not_changed = isset( $current->last_checked ) && $timeout > ( time() - $current->last_checked ); 	if ( ! $force_check && $time_not_changed ) {		return;	} 	/**	 * Filters the locale requested for WordPress core translations.	 *	 * @since 2.8.0	 *	 * @param string $locale Current locale.	 */	$locale = apply_filters( 'core_version_check_locale', get_locale() ); 	// Update last_checked for current to prevent multiple blocking requests if request hangs.	$current->last_checked = time();	set_site_transient( 'update_core', $current ); 	if ( method_exists( $wpdb, 'db_server_info' ) ) {		$mysql_version = $wpdb->db_server_info();	} elseif ( method_exists( $wpdb, 'db_version' ) ) {		$mysql_version = preg_replace( '/[^0-9.].*/', '', $wpdb->db_version() );	} else {		$mysql_version = 'N/A';	} 	if ( is_multisite() ) {		$num_blogs         = get_blog_count();		$wp_install        = network_site_url();		$multisite_enabled = 1;	} else {		$multisite_enabled = 0;		$num_blogs         = 1;		$wp_install        = home_url( '/' );	} 	$extensions = get_loaded_extensions();	sort( $extensions, SORT_STRING | SORT_FLAG_CASE );	$query = array(		'version'            => wp_get_wp_version(),		'php'                => $php_version,		'locale'             => $locale,		'mysql'              => $mysql_version,		'local_package'      => isset( $wp_local_package ) ? $wp_local_package : '',		'blogs'              => $num_blogs,		'users'              => get_user_count(),		'multisite_enabled'  => $multisite_enabled,		'initial_db_version' => get_site_option( 'initial_db_version' ),		'myisam_tables'      => array(),		'extensions'         => array_combine( $extensions, array_map( 'phpversion', $extensions ) ),

Changelog

Introduced in 2.3.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 6.9.7 tag, from src/wp-includes/update.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.