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 234
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() ) {
    $num_blogs         = get_blog_count();
    $wp_install        = network_site_url();
    $multisite_enabled = 1;
  } else {
    $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'              => get_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.
 *     @type int    $multisite_enabled  Whether this WordPress installation uses Multisite.
 *     @type int    $initial_db_version Database version of WordPress at time of installation.
 * }

 View on GitHub View on Trac