wp_version_check() – Checks WordPress version against the newest version.

You appear to be a bot. Output may be restricted

Description

Checks 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 270
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 = 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_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( '/' );
  }

  $extensions = get_loaded_extensions();
  sort( $extensions, SORT_STRING | SORT_FLAG_CASE );
  $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' ),
    'extensions'         => array_combine( $extensions, array_map( 'phpversion', $extensions ) ),
    'platform_flags'     => array(
      'os'   => PHP_OS,
      'bits' => PHP_INT_SIZE === 4 ? 32 : 64,
    ),
    'image_support'      => array(),
  );

  if ( function_exists( 'gd_info' ) ) {
    $gd_info = gd_info();
    // Filter to supported values.
    $gd_info = array_filter( $gd_info );

    // Add data for GD WebP and AVIF support.
    $query['image_support']['gd'] = array_keys(
      array_filter(
        array(
          'webp' => isset( $gd_info['WebP Support'] ),
          'avif' => isset( $gd_info['AVIF Support'] ),
        )
      )

 View on GitHub View on Trac