wp_version_check

Definition:
function wp_version_check() {}

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 server. Will only check if WordPress isn’t installing.

Return values

returns:Returns null if update is unsupported. Returns false if check is too soon.

Defined filters

  • core_version_check_locale
    apply_filters( 'core_version_check_locale', get_locale()

Source code

function wp_version_check() {

	if ( defined('WP_INSTALLING') )

		return;



	global $wpdb, $wp_local_package;

	include ABSPATH . WPINC . '/version.php'; // include an unmodified $wp_version

	$php_version = phpversion();



	$current = get_site_transient( 'update_core' );

	if ( ! is_object($current) ) {

		$current = new stdClass;

		$current->updates = array();

		$current->version_checked = $wp_version;

	}



	$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( );

		$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['total_users'],

		'multisite_enabled' => $multisite_enabled

	);



	$url = 'http://api.wordpress.org/core/version-check/1.6/?' . http_build_query( $query, null, '&' );



	$options = array(

		'timeout' => ( ( defined('DOING_CRON') && DOING_CRON ) ? 30 : 3 ),

		'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ),

		'headers' => array(

			'wp_install' => $wp_install,

			'wp_blog' => home_url( '/' )

		)

	);



	$response = wp_remote_get($url, $options);



	if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) )

		return false;



	$body = trim( wp_remote_retrieve_body( $response ) );

	if ( ! $body = maybe_unserialize( $body ) )

		return false;

	if ( ! isset( $body['offers'] ) )

		return false;

	$offers = $body['offers'];



	foreach ( $offers as &$offer ) {

		foreach ( $offer as $offer_key => $value ) {

			if ( 'packages' == $offer_key )

				$offer['packages'] = (object) array_intersect_key( array_map( 'esc_url', $offer['packages'] ),

					array_fill_keys( array( 'full', 'no_content', 'new_bundled', 'partial' ), '' ) );

			elseif ( 'download' == $offer_key )

				$offer['download'] = esc_url( $value );

			else

				$offer[ $offer_key ] = esc_html( $value );

		}

		$offer = (object) array_intersect_key( $offer, array_fill_keys( array( 'response', 'download', 'locale',

			'packages', 'current', 'php_version', 'mysql_version', 'new_bundled', 'partial_version' ), '' ) );

	}



	$updates = new stdClass();

	$updates->updates = $offers;

	$updates->last_checked = time();

	$updates->version_checked = $wp_version;

	set_site_transient( 'update_core',  $updates);

}

4261

Advertisements

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: