web/wp-includes/update.php
branchwordpress
changeset 132 4d4862461b8d
parent 109 03b0d1493584
equal deleted inserted replaced
131:a4642baaf829 132:4d4862461b8d
    38 	// Update last_checked for current to prevent multiple blocking requests if request hangs
    38 	// Update last_checked for current to prevent multiple blocking requests if request hangs
    39 	$current->last_checked = time();
    39 	$current->last_checked = time();
    40 	set_transient( 'update_core', $current );
    40 	set_transient( 'update_core', $current );
    41 
    41 
    42 	if ( method_exists( $wpdb, 'db_version' ) )
    42 	if ( method_exists( $wpdb, 'db_version' ) )
    43 		$mysql_version = preg_replace('/[^0-9.].*/', '', $wpdb->db_version($wpdb->users));
    43 		$mysql_version = preg_replace('/[^0-9.].*/', '', $wpdb->db_version());
    44 	else
    44 	else
    45 		$mysql_version = 'N/A';
    45 		$mysql_version = 'N/A';
    46 	$local_package = isset( $wp_local_package )? $wp_local_package : '';
    46 	$local_package = isset( $wp_local_package )? $wp_local_package : '';
    47 	$url = "http://api.wordpress.org/core/version-check/1.3/?version=$wp_version&php=$php_version&locale=$locale&mysql=$mysql_version&local_package=$local_package";
    47 	$url = "http://api.wordpress.org/core/version-check/1.3/?version=$wp_version&php=$php_version&locale=$locale&mysql=$mysql_version&local_package=$local_package";
    48 
    48 
    49 	$options = array(
    49 	$options = array(
    50 		'timeout' => 3,
    50 		'timeout' => ( ( defined('DOING_CRON') && DOING_CRON ) ? 30 : 3),
    51 		'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' )
    51 		'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' )
    52 	);
    52 	);
    53 
    53 
    54 	$response = wp_remote_get($url, $options);
    54 	$response = wp_remote_get($url, $options);
    55 
    55 
   144 	set_transient( 'update_plugins', $current );
   144 	set_transient( 'update_plugins', $current );
   145 
   145 
   146 	$to_send = (object)compact('plugins', 'active');
   146 	$to_send = (object)compact('plugins', 'active');
   147 
   147 
   148 	$options = array(
   148 	$options = array(
   149 		'timeout' => 3,
   149 		'timeout' => ( ( defined('DOING_CRON') && DOING_CRON ) ? 30 : 3),
   150 		'body' => array( 'plugins' => serialize( $to_send ) ),
   150 		'body' => array( 'plugins' => serialize( $to_send ) ),
   151 		'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' )
   151 		'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' )
   152 	);
   152 	);
   153 
   153 
   154 	$raw_response = wp_remote_post('http://api.wordpress.org/plugins/update-check/1.0/', $options);
   154 	$raw_response = wp_remote_post('http://api.wordpress.org/plugins/update-check/1.0/', $options);
   199 	$new_option = new stdClass;
   199 	$new_option = new stdClass;
   200 	$new_option->last_checked = time( );
   200 	$new_option->last_checked = time( );
   201 	$timeout = 'load-themes.php' == current_filter() ? 3600 : 43200; //Check for updated every 60 minutes if hitting the themes page, Else, check every 12 hours
   201 	$timeout = 'load-themes.php' == current_filter() ? 3600 : 43200; //Check for updated every 60 minutes if hitting the themes page, Else, check every 12 hours
   202 	$time_not_changed = isset( $current_theme->last_checked ) && $timeout > ( time( ) - $current_theme->last_checked );
   202 	$time_not_changed = isset( $current_theme->last_checked ) && $timeout > ( time( ) - $current_theme->last_checked );
   203 
   203 
   204 	if( $time_not_changed )
   204 	$themes = array();
       
   205 	$checked = array();
       
   206 	$themes['current_theme'] = (array) $current_theme;
       
   207 	foreach( (array) $installed_themes as $theme_title => $theme ) {
       
   208 		$themes[$theme['Stylesheet']] = array();
       
   209 		$checked[$theme['Stylesheet']] = $theme['Version'];
       
   210 
       
   211 		foreach( (array) $theme as $key => $value ) {
       
   212 			$themes[$theme['Stylesheet']][$key] = $value;
       
   213 		}
       
   214 	}
       
   215 
       
   216 	$theme_changed = false;
       
   217 	foreach ( $checked as $slug => $v ) {
       
   218 		$new_option->checked[ $slug ] = $v;
       
   219 
       
   220 		if ( !isset( $current_theme->checked[ $slug ] ) || strval($current_theme->checked[ $slug ]) !== strval($v) )
       
   221 			$theme_changed = true;
       
   222 	}
       
   223 
       
   224 	if ( isset ( $current_theme->response ) && is_array( $current_theme->response ) ) {
       
   225 		foreach ( $current_theme->response as $slug => $update_details ) {
       
   226 			if ( ! isset($checked[ $slug ]) ) {
       
   227 				$theme_changed = true;
       
   228 				break;
       
   229 			}
       
   230 		}
       
   231 	}
       
   232 
       
   233 	if( $time_not_changed && !$theme_changed )
   205 		return false;
   234 		return false;
   206 
   235 
   207 	// Update last_checked for current to prevent multiple blocking requests if request hangs
   236 	// Update last_checked for current to prevent multiple blocking requests if request hangs
   208 	$current_theme->last_checked = time();
   237 	$current_theme->last_checked = time();
   209 	set_transient( 'update_themes', $current_theme );
   238 	set_transient( 'update_themes', $current_theme );
   210 
   239 
   211 	$current_theme->template = get_option( 'template' );
   240 	$current_theme->template = get_option( 'template' );
   212 
   241 
   213 	$themes = array( );
       
   214 	$themes['current_theme'] = (array) $current_theme;
       
   215 	foreach( (array) $installed_themes as $theme_title => $theme ) {
       
   216 		$themes[$theme['Stylesheet']] = array( );
       
   217 
       
   218 		foreach( (array) $theme as $key => $value ) {
       
   219 			$themes[$theme['Stylesheet']][$key] = $value;
       
   220 		}
       
   221 	}
       
   222 
       
   223 	$options = array(
   242 	$options = array(
   224 		'timeout'		=> 3,
   243 		'timeout' => ( ( defined('DOING_CRON') && DOING_CRON ) ? 30 : 3),
   225 		'body'			=> array( 'themes' => serialize( $themes ) ),
   244 		'body'			=> array( 'themes' => serialize( $themes ) ),
   226 		'user-agent'	=> 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' )
   245 		'user-agent'	=> 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' )
   227 	);
   246 	);
   228 
   247 
   229 	$raw_response = wp_remote_post( 'http://api.wordpress.org/themes/update-check/1.0/', $options );
   248 	$raw_response = wp_remote_post( 'http://api.wordpress.org/themes/update-check/1.0/', $options );
   233 
   252 
   234 	if( 200 != $raw_response['response']['code'] )
   253 	if( 200 != $raw_response['response']['code'] )
   235 		return false;
   254 		return false;
   236 
   255 
   237 	$response = unserialize( $raw_response['body'] );
   256 	$response = unserialize( $raw_response['body'] );
   238 	if( $response )
   257 	if( $response ) {
       
   258 		$new_option->checked = $checked;
   239 		$new_option->response = $response;
   259 		$new_option->response = $response;
       
   260 	}
   240 
   261 
   241 	set_transient( 'update_themes', $new_option );
   262 	set_transient( 'update_themes', $new_option );
   242 }
   263 }
   243 
   264 
   244 function _maybe_update_core() {
   265 function _maybe_update_core() {
   283 function _maybe_update_themes( ) {
   304 function _maybe_update_themes( ) {
   284 	$current = get_transient( 'update_themes' );
   305 	$current = get_transient( 'update_themes' );
   285 	if( isset( $current->last_checked ) && 43200 > ( time( ) - $current->last_checked ) )
   306 	if( isset( $current->last_checked ) && 43200 > ( time( ) - $current->last_checked ) )
   286 		return;
   307 		return;
   287 
   308 
   288 	wp_update_themes( );
   309 	wp_update_themes();
   289 }
   310 }
   290 
   311 
   291 add_action( 'admin_init', '_maybe_update_core' );
   312 add_action( 'admin_init', '_maybe_update_core' );
   292 add_action( 'wp_version_check', 'wp_version_check' );
   313 add_action( 'wp_version_check', 'wp_version_check' );
   293 
   314 
   294 add_action( 'load-plugins.php', 'wp_update_plugins' );
   315 add_action( 'load-plugins.php', 'wp_update_plugins' );
   295 add_action( 'load-update.php', 'wp_update_plugins' );
   316 add_action( 'load-update.php', 'wp_update_plugins' );
       
   317 add_action( 'load-update-core.php', 'wp_update_plugins' );
   296 add_action( 'admin_init', '_maybe_update_plugins' );
   318 add_action( 'admin_init', '_maybe_update_plugins' );
   297 add_action( 'wp_update_plugins', 'wp_update_plugins' );
   319 add_action( 'wp_update_plugins', 'wp_update_plugins' );
   298 
   320 
   299 add_action( 'load-themes.php', 'wp_update_themes' );
   321 add_action( 'load-themes.php', 'wp_update_themes' );
   300 add_action( 'load-update.php', 'wp_update_themes' );
   322 add_action( 'load-update.php', 'wp_update_themes' );