• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
WordPress core a2z

WordPress core a2z

WordPress core only

  • Home
  • Plugins
  • Blocks
  • Shortcodes
  • APIs
  • Classes
  • Files
  • Hooks
  • Sitemap
  • Blog
Home / APIs / wp_version_check() – Check WordPress version against the newest version.

You appear to be a bot. Output may be restricted

Description

Check WordPress version against the newest version.

The WordPress version, PHP version, and locale is sent. Checks against the WordPress server at api.wordpress.org. Will only check if WordPress isn't installing.

Usage

wp_version_check( $extra_stats, $force_check );

Parameters

$extra_stats
( array ) optional – Extra statistics to report to the WordPress.org API.
$force_check
( bool ) optional – Whether to bypass the transient cache and force a fresh update check. Defaults to false, true if $extra_stats is set.

Returns

void

Source

File name: wordpress/wp-includes/update.php


Lines:

1 to 100 of 237
function wp_version_check( $extra_stats = array(), $force_check = false ) {
  global $wpdb, $wp_local_package;

  if ( wp_installing() ) {
    return;
  }

  // Include an unmodified $wp_version.
  require ABSPATH . WPINC . '/version.php';
  $php_version = phpversion();

  $current      = get_site_transient( 'update_core' );
  $translations = wp_get_installed_translations( 'core' );

  // Invalidate the transient when $wp_version changes.
  if ( is_object( $current ) && $wp_version !== $current->version_checked ) {
    $current = false;
  }

  if ( ! is_object( $current ) ) {
    $current                  = new stdClass;
    $current->updates         = array();
    $current->version_checked = $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_version' ) ) {
    $mysql_version = preg_replace( '/[^0-9.].*/', '', $wpdb->db_version() );
  } else {
    $mysql_version = 'N/A';
  }

  if ( is_multisite() ) {
    $user_count        = get_user_count();
    $num_blogs         = get_blog_count();
    $wp_install        = network_site_url();
    $multisite_enabled = 1;
  } else {
    $user_count        = count_users();
    $user_count        = $user_count['total_users'];
    $multisite_enabled = 0;
    $num_blogs         = 1;
    $wp_install        = home_url( '/' );
  }

  $query = array(
    'version'            => $wp_version,
    'php'                => $php_version,
    'locale'             => $locale,
    'mysql'              => $mysql_version,
    'local_package'      => isset( $wp_local_package ) ? $wp_local_package : '',
    'blogs'              => $num_blogs,
    'users'              => $user_count,
    'multisite_enabled'  => $multisite_enabled,
    'initial_db_version' => get_site_option( 'initial_db_version' ),
  );

  
/**
 * Filters the query arguments sent as part of the core version check.
 *
 * WARNING: Changing this data may result in your site not receiving security updates.
 * Please exercise extreme caution.
 *
 * @since 4.9.0
 *
 * @param array $query {
 *     Version check query arguments.
 *
 *     @type string $version            WordPress version number.
 *     @type string $php                PHP version number.
 *     @type string $locale             The locale to retrieve updates for.
 *     @type string $mysql              MySQL version number.
 *     @type string $local_package      The value of the $wp_local_package global, when set.
 *     @type int    $blogs              Number of sites on this WordPress installation.
 *     @type int    $users              Number of users on this WordPress installation.
[1] [2] [3] Next »

 View on GitHub View on Trac

Published: 25th November 2019 | Last updated: 13th March 2021

Primary Sidebar

Information

Function name: wp_version_check
Plugin ref: WordPress
Version: 5.7.1
Sourcefile: wp-includes/update.php
File ref: wp-includes/update.php
Deprecated?: No
API Letters: C,V,W

Footer

WP-a2z
WordPress core a2z
WordPress core only
WordPress 5.7.1
WordPress a2z
WordPress core a2z
Genesis Theme Framework a2z
Jetpack a2z
WordPress develop tests
Easy Digital Downloads a2z
WooCommerce a2z
Yoast SEO a2z
WordPress Blocks

Site:  core.wp-a2z.org
© Copyright WP-a2z 2014-2021. All rights reserved.


Website designed and developed by Herb Miller
Proudly powered by WordPress and oik plugins

  • Home
  • Blog
  • Sitemap
  • Sites