web/wp-includes/update.php
changeset 194 32102edaa81b
parent 136 bde1974c263b
child 204 09a1c134465b
equal deleted inserted replaced
193:2f6f6f7551ca 194:32102edaa81b
    21  */
    21  */
    22 function wp_version_check() {
    22 function wp_version_check() {
    23 	if ( defined('WP_INSTALLING') )
    23 	if ( defined('WP_INSTALLING') )
    24 		return;
    24 		return;
    25 
    25 
    26 	global $wp_version, $wpdb, $wp_local_package;
    26 	global $wpdb, $wp_local_package;
       
    27 	include ABSPATH . WPINC . '/version.php'; // include an unmodified $wp_version
    27 	$php_version = phpversion();
    28 	$php_version = phpversion();
    28 
    29 
    29 	$current = get_transient( 'update_core' );
    30 	$current = get_site_transient( 'update_core' );
    30 	if ( ! is_object($current) ) {
    31 	if ( ! is_object($current) ) {
    31 		$current = new stdClass;
    32 		$current = new stdClass;
    32 		$current->updates = array();
    33 		$current->updates = array();
    33 		$current->version_checked = $wp_version;
    34 		$current->version_checked = $wp_version;
    34 	}
    35 	}
    35 
    36 
       
    37 	// Wait 60 seconds between multiple version check requests
       
    38 	$timeout = 60;
       
    39 	$time_not_changed = isset( $current->last_checked ) && $timeout > ( time() - $current->last_checked );
       
    40 	if ( $time_not_changed )
       
    41 		return false;
       
    42 
    36 	$locale = apply_filters( 'core_version_check_locale', get_locale() );
    43 	$locale = apply_filters( 'core_version_check_locale', get_locale() );
    37 
    44 
    38 	// Update last_checked for current to prevent multiple blocking requests if request hangs
    45 	// Update last_checked for current to prevent multiple blocking requests if request hangs
    39 	$current->last_checked = time();
    46 	$current->last_checked = time();
    40 	set_transient( 'update_core', $current );
    47 	set_site_transient( 'update_core', $current );
    41 
    48 
    42 	if ( method_exists( $wpdb, 'db_version' ) )
    49 	if ( method_exists( $wpdb, 'db_version' ) )
    43 		$mysql_version = preg_replace('/[^0-9.].*/', '', $wpdb->db_version());
    50 		$mysql_version = preg_replace('/[^0-9.].*/', '', $wpdb->db_version());
    44 	else
    51 	else
    45 		$mysql_version = 'N/A';
    52 		$mysql_version = 'N/A';
    46 	$local_package = isset( $wp_local_package )? $wp_local_package : '';
    53 
    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";
    54 	if ( is_multisite( ) ) {
       
    55 		$user_count = get_user_count( );
       
    56 		$num_blogs = get_blog_count( );
       
    57 		$wp_install = network_site_url( );
       
    58 		$multisite_enabled = 1;
       
    59 	} else {
       
    60 		$user_count = count_users( );
       
    61 		$user_count = $user_count['total_users'];
       
    62 		$multisite_enabled = 0;
       
    63 		$num_blogs = 1;
       
    64 		$wp_install = home_url( '/' );
       
    65 	}
       
    66 
       
    67 	$query = array(
       
    68 		'version'           => $wp_version,
       
    69 		'php'               => $php_version,
       
    70 		'locale'            => $locale,
       
    71 		'mysql'             => $mysql_version,
       
    72 		'local_package'     => isset( $wp_local_package ) ? $wp_local_package : '',
       
    73 		'blogs'             => $num_blogs,
       
    74 		'users'             => $user_count,
       
    75 		'multisite_enabled' => $multisite_enabled
       
    76 	);
       
    77 
       
    78 	$url = 'http://api.wordpress.org/core/version-check/1.6/?' . http_build_query( $query, null, '&' );
    48 
    79 
    49 	$options = array(
    80 	$options = array(
    50 		'timeout' => ( ( defined('DOING_CRON') && DOING_CRON ) ? 30 : 3),
    81 		'timeout' => ( ( defined('DOING_CRON') && DOING_CRON ) ? 30 : 3 ),
    51 		'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' )
    82 		'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ),
       
    83 		'headers' => array(
       
    84 			'wp_install' => $wp_install,
       
    85 			'wp_blog' => home_url( '/' )
       
    86 		)
    52 	);
    87 	);
    53 
    88 
    54 	$response = wp_remote_get($url, $options);
    89 	$response = wp_remote_get($url, $options);
    55 
    90 
    56 	if ( is_wp_error( $response ) )
    91 	if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) )
    57 		return false;
    92 		return false;
    58 
    93 
    59 	if ( 200 != $response['response']['code'] )
    94 	$body = trim( wp_remote_retrieve_body( $response ) );
    60 		return false;
    95 	$body = maybe_unserialize( $body );
    61 
    96 
    62 	$body = trim( $response['body'] );
    97 	if ( ! is_array( $body ) || ! isset( $body['offers'] ) )
    63 	$body = str_replace(array("\r\n", "\r"), "\n", $body);
    98 		return false;
    64 	$new_options = array();
    99 
    65 	foreach( explode( "\n\n", $body ) as $entry) {
   100 	$offers = $body['offers'];
    66 		$returns = explode("\n", $entry);
   101 
    67 		$new_option = new stdClass();
   102 	foreach ( $offers as &$offer ) {
    68 		$new_option->response = esc_attr( $returns[0] );
   103 		foreach ( $offer as $offer_key => $value ) {
    69 		if ( isset( $returns[1] ) )
   104 			if ( 'packages' == $offer_key )
    70 			$new_option->url = esc_url( $returns[1] );
   105 				$offer['packages'] = (object) array_intersect_key( array_map( 'esc_url', $offer['packages'] ),
    71 		if ( isset( $returns[2] ) )
   106 					array_fill_keys( array( 'full', 'no_content', 'new_bundled', 'partial' ), '' ) );
    72 			$new_option->package = esc_url( $returns[2] );
   107 			elseif ( 'download' == $offer_key )
    73 		if ( isset( $returns[3] ) )
   108 				$offer['download'] = esc_url( $value );
    74 			$new_option->current = esc_attr( $returns[3] );
   109 			else
    75 		if ( isset( $returns[4] ) )
   110 				$offer[ $offer_key ] = esc_html( $value );
    76 			$new_option->locale = esc_attr( $returns[4] );
   111 		}
    77 		$new_options[] = $new_option;
   112 		$offer = (object) array_intersect_key( $offer, array_fill_keys( array( 'response', 'download', 'locale',
       
   113 			'packages', 'current', 'php_version', 'mysql_version', 'new_bundled', 'partial_version' ), '' ) );
    78 	}
   114 	}
    79 
   115 
    80 	$updates = new stdClass();
   116 	$updates = new stdClass();
    81 	$updates->updates = $new_options;
   117 	$updates->updates = $offers;
    82 	$updates->last_checked = time();
   118 	$updates->last_checked = time();
    83 	$updates->version_checked = $wp_version;
   119 	$updates->version_checked = $wp_version;
    84 	set_transient( 'update_core',  $updates);
   120 	set_site_transient( 'update_core',  $updates);
    85 }
   121 }
    86 
   122 
    87 /**
   123 /**
    88  * Check plugin versions against the latest versions hosted on WordPress.org.
   124  * Check plugin versions against the latest versions hosted on WordPress.org.
    89  *
   125  *
    91  * all plugins installed. Checks against the WordPress server at
   127  * all plugins installed. Checks against the WordPress server at
    92  * api.wordpress.org. Will only check if WordPress isn't installing.
   128  * api.wordpress.org. Will only check if WordPress isn't installing.
    93  *
   129  *
    94  * @package WordPress
   130  * @package WordPress
    95  * @since 2.3.0
   131  * @since 2.3.0
    96  * @uses $wp_version Used to notidy the WordPress version.
   132  * @uses $wp_version Used to notify the WordPress version.
    97  *
   133  *
    98  * @return mixed Returns null if update is unsupported. Returns false if check is too soon.
   134  * @return mixed Returns null if update is unsupported. Returns false if check is too soon.
    99  */
   135  */
   100 function wp_update_plugins() {
   136 function wp_update_plugins() {
   101 	global $wp_version;
   137 	include ABSPATH . WPINC . '/version.php'; // include an unmodified $wp_version
   102 
   138 
   103 	if ( defined('WP_INSTALLING') )
   139 	if ( defined('WP_INSTALLING') )
   104 		return false;
   140 		return false;
   105 
   141 
   106 	// If running blog-side, bail unless we've not checked in the last 12 hours
   142 	// If running blog-side, bail unless we've not checked in the last 12 hours
   107 	if ( !function_exists( 'get_plugins' ) )
   143 	if ( !function_exists( 'get_plugins' ) )
   108 		require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
   144 		require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
   109 
   145 
   110 	$plugins = get_plugins();
   146 	$plugins = get_plugins();
   111 	$active  = get_option( 'active_plugins' );
   147 	$active  = get_option( 'active_plugins', array() );
   112 	$current = get_transient( 'update_plugins' );
   148 	$current = get_site_transient( 'update_plugins' );
   113 	if ( ! is_object($current) )
   149 	if ( ! is_object($current) )
   114 		$current = new stdClass;
   150 		$current = new stdClass;
   115 
   151 
   116 	$new_option = new stdClass;
   152 	$new_option = new stdClass;
   117 	$new_option->last_checked = time();
   153 	$new_option->last_checked = time();
   118 	$timeout = 'load-plugins.php' == current_filter() ? 3600 : 43200; //Check for updated every 60 minutes if hitting the themes page, Else, check every 12 hours
   154 
       
   155 	// Check for update on a different schedule, depending on the page.
       
   156 	switch ( current_filter() ) {
       
   157 		case 'load-update-core.php' :
       
   158 			$timeout = 60; // 1 min
       
   159 			break;
       
   160 		case 'load-plugins.php' :
       
   161 		case 'load-update.php' :
       
   162 			$timeout = 3600; // 1 hour
       
   163 			break;
       
   164 		default :
       
   165 			$timeout = 43200; // 12 hours
       
   166 	}
       
   167 
   119 	$time_not_changed = isset( $current->last_checked ) && $timeout > ( time() - $current->last_checked );
   168 	$time_not_changed = isset( $current->last_checked ) && $timeout > ( time() - $current->last_checked );
   120 
   169 
   121 	$plugin_changed = false;
   170 	if ( $time_not_changed ) {
   122 	foreach ( $plugins as $file => $p ) {
   171 		$plugin_changed = false;
   123 		$new_option->checked[ $file ] = $p['Version'];
   172 		foreach ( $plugins as $file => $p ) {
   124 
   173 			$new_option->checked[ $file ] = $p['Version'];
   125 		if ( !isset( $current->checked[ $file ] ) || strval($current->checked[ $file ]) !== strval($p['Version']) )
   174 
   126 			$plugin_changed = true;
   175 			if ( !isset( $current->checked[ $file ] ) || strval($current->checked[ $file ]) !== strval($p['Version']) )
   127 	}
       
   128 
       
   129 	if ( isset ( $current->response ) && is_array( $current->response ) ) {
       
   130 		foreach ( $current->response as $plugin_file => $update_details ) {
       
   131 			if ( ! isset($plugins[ $plugin_file ]) ) {
       
   132 				$plugin_changed = true;
   176 				$plugin_changed = true;
   133 				break;
   177 		}
       
   178 
       
   179 		if ( isset ( $current->response ) && is_array( $current->response ) ) {
       
   180 			foreach ( $current->response as $plugin_file => $update_details ) {
       
   181 				if ( ! isset($plugins[ $plugin_file ]) ) {
       
   182 					$plugin_changed = true;
       
   183 					break;
       
   184 				}
   134 			}
   185 			}
   135 		}
   186 		}
   136 	}
   187 
   137 
   188 		// Bail if we've checked recently and if nothing has changed
   138 	// Bail if we've checked in the last 12 hours and if nothing has changed
   189 		if ( ! $plugin_changed )
   139 	if ( $time_not_changed && !$plugin_changed )
   190 			return false;
   140 		return false;
   191 	}
   141 
   192 
   142 	// Update last_checked for current to prevent multiple blocking requests if request hangs
   193 	// Update last_checked for current to prevent multiple blocking requests if request hangs
   143 	$current->last_checked = time();
   194 	$current->last_checked = time();
   144 	set_transient( 'update_plugins', $current );
   195 	set_site_transient( 'update_plugins', $current );
   145 
   196 
   146 	$to_send = (object)compact('plugins', 'active');
   197 	$to_send = (object) compact('plugins', 'active');
   147 
   198 
   148 	$options = array(
   199 	$options = array(
   149 		'timeout' => ( ( defined('DOING_CRON') && DOING_CRON ) ? 30 : 3),
   200 		'timeout' => ( ( defined('DOING_CRON') && DOING_CRON ) ? 30 : 3),
   150 		'body' => array( 'plugins' => serialize( $to_send ) ),
   201 		'body' => array( 'plugins' => serialize( $to_send ) ),
   151 		'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' )
   202 		'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' )
   152 	);
   203 	);
   153 
   204 
   154 	$raw_response = wp_remote_post('http://api.wordpress.org/plugins/update-check/1.0/', $options);
   205 	$raw_response = wp_remote_post('http://api.wordpress.org/plugins/update-check/1.0/', $options);
   155 
   206 
   156 	if ( is_wp_error( $raw_response ) )
   207 	if ( is_wp_error( $raw_response ) || 200 != wp_remote_retrieve_response_code( $raw_response ) )
   157 		return false;
   208 		return false;
   158 
   209 
   159 	if( 200 != $raw_response['response']['code'] )
   210 	$response = maybe_unserialize( wp_remote_retrieve_body( $raw_response ) );
   160 		return false;
   211 
   161 
   212 	if ( is_array( $response ) )
   162 	$response = unserialize( $raw_response['body'] );
       
   163 
       
   164 	if ( false !== $response )
       
   165 		$new_option->response = $response;
   213 		$new_option->response = $response;
   166 	else
   214 	else
   167 		$new_option->response = array();
   215 		$new_option->response = array();
   168 
   216 
   169 	set_transient( 'update_plugins', $new_option );
   217 	set_site_transient( 'update_plugins', $new_option );
   170 }
   218 }
   171 
   219 
   172 /**
   220 /**
   173  * Check theme versions against the latest versions hosted on WordPress.org.
   221  * Check theme versions against the latest versions hosted on WordPress.org.
   174  *
   222  *
   176  * WordPress server at api.wordpress.org. Will only check if WordPress isn't
   224  * WordPress server at api.wordpress.org. Will only check if WordPress isn't
   177  * installing.
   225  * installing.
   178  *
   226  *
   179  * @package WordPress
   227  * @package WordPress
   180  * @since 2.7.0
   228  * @since 2.7.0
   181  * @uses $wp_version Used to notidy the WordPress version.
   229  * @uses $wp_version Used to notify the WordPress version.
   182  *
   230  *
   183  * @return mixed Returns null if update is unsupported. Returns false if check is too soon.
   231  * @return mixed Returns null if update is unsupported. Returns false if check is too soon.
   184  */
   232  */
   185 function wp_update_themes( ) {
   233 function wp_update_themes() {
   186 	global $wp_version;
   234 	include ABSPATH . WPINC . '/version.php'; // include an unmodified $wp_version
   187 
   235 
   188 	if( defined( 'WP_INSTALLING' ) )
   236 	if ( defined( 'WP_INSTALLING' ) )
   189 		return false;
   237 		return false;
   190 
   238 
   191 	if( !function_exists( 'get_themes' ) )
   239 	$installed_themes = wp_get_themes();
   192 		require_once( ABSPATH . 'wp-includes/theme.php' );
   240 	$last_update = get_site_transient( 'update_themes' );
   193 
   241 	if ( ! is_object($last_update) )
   194 	$installed_themes = get_themes( );
   242 		$last_update = new stdClass;
   195 	$current_theme = get_transient( 'update_themes' );
       
   196 	if ( ! is_object($current_theme) )
       
   197 		$current_theme = new stdClass;
       
   198 
       
   199 	$new_option = new stdClass;
       
   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
       
   202 	$time_not_changed = isset( $current_theme->last_checked ) && $timeout > ( time( ) - $current_theme->last_checked );
       
   203 
   243 
   204 	$themes = array();
   244 	$themes = array();
   205 	$checked = array();
   245 	$checked = array();
   206 	$themes['current_theme'] = (array) $current_theme;
   246 
   207 	foreach( (array) $installed_themes as $theme_title => $theme ) {
   247 	// Put slug of current theme into request.
   208 		$themes[$theme['Stylesheet']] = array();
   248 	$themes['current_theme'] = get_option( 'stylesheet' );
   209 		$checked[$theme['Stylesheet']] = $theme['Version'];
   249 
   210 
   250 	foreach ( $installed_themes as $theme ) {
   211 		foreach( (array) $theme as $key => $value ) {
   251 		$checked[ $theme->get_stylesheet() ] = $theme->get('Version');
   212 			$themes[$theme['Stylesheet']][$key] = $value;
   252 
       
   253 		$themes[ $theme->get_stylesheet() ] = array(
       
   254 			'Name'       => $theme->get('Name'),
       
   255 			'Title'      => $theme->get('Name'),
       
   256 			'Version'    => $theme->get('Version'),
       
   257 			'Author'     => $theme->get('Author'),
       
   258 			'Author URI' => $theme->get('AuthorURI'),
       
   259 			'Template'   => $theme->get_template(),
       
   260 			'Stylesheet' => $theme->get_stylesheet(),
       
   261 		);
       
   262 	}
       
   263 
       
   264 	// Check for update on a different schedule, depending on the page.
       
   265 	switch ( current_filter() ) {
       
   266 		case 'load-update-core.php' :
       
   267 			$timeout = 60; // 1 min
       
   268 			break;
       
   269 		case 'load-themes.php' :
       
   270 		case 'load-update.php' :
       
   271 			$timeout = 3600; // 1 hour
       
   272 			break;
       
   273 		default :
       
   274 			$timeout = 43200; // 12 hours
       
   275 	}
       
   276 
       
   277 	$time_not_changed = isset( $last_update->last_checked ) && $timeout > ( time( ) - $last_update->last_checked );
       
   278 
       
   279 	if ( $time_not_changed ) {
       
   280 		$theme_changed = false;
       
   281 		foreach ( $checked as $slug => $v ) {
       
   282 			$update_request->checked[ $slug ] = $v;
       
   283 
       
   284 			if ( !isset( $last_update->checked[ $slug ] ) || strval($last_update->checked[ $slug ]) !== strval($v) )
       
   285 				$theme_changed = true;
   213 		}
   286 		}
   214 	}
   287 
   215 
   288 		if ( isset ( $last_update->response ) && is_array( $last_update->response ) ) {
   216 	$theme_changed = false;
   289 			foreach ( $last_update->response as $slug => $update_details ) {
   217 	foreach ( $checked as $slug => $v ) {
   290 				if ( ! isset($checked[ $slug ]) ) {
   218 		$new_option->checked[ $slug ] = $v;
   291 					$theme_changed = true;
   219 
   292 					break;
   220 		if ( !isset( $current_theme->checked[ $slug ] ) || strval($current_theme->checked[ $slug ]) !== strval($v) )
   293 				}
   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 			}
   294 			}
   230 		}
   295 		}
   231 	}
   296 
   232 
   297 		// Bail if we've checked recently and if nothing has changed
   233 	if( $time_not_changed && !$theme_changed )
   298 		if ( ! $theme_changed )
   234 		return false;
   299 			return false;
       
   300 	}
   235 
   301 
   236 	// Update last_checked for current to prevent multiple blocking requests if request hangs
   302 	// Update last_checked for current to prevent multiple blocking requests if request hangs
   237 	$current_theme->last_checked = time();
   303 	$last_update->last_checked = time();
   238 	set_transient( 'update_themes', $current_theme );
   304 	set_site_transient( 'update_themes', $last_update );
   239 
       
   240 	$current_theme->template = get_option( 'template' );
       
   241 
   305 
   242 	$options = array(
   306 	$options = array(
   243 		'timeout' => ( ( defined('DOING_CRON') && DOING_CRON ) ? 30 : 3),
   307 		'timeout' => ( ( defined('DOING_CRON') && DOING_CRON ) ? 30 : 3),
   244 		'body'			=> array( 'themes' => serialize( $themes ) ),
   308 		'body'			=> array( 'themes' => serialize( $themes ) ),
   245 		'user-agent'	=> 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' )
   309 		'user-agent'	=> 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' )
   246 	);
   310 	);
   247 
   311 
   248 	$raw_response = wp_remote_post( 'http://api.wordpress.org/themes/update-check/1.0/', $options );
   312 	$raw_response = wp_remote_post( 'http://api.wordpress.org/themes/update-check/1.0/', $options );
   249 
   313 
   250 	if( is_wp_error( $raw_response ) )
   314 	if ( is_wp_error( $raw_response ) || 200 != wp_remote_retrieve_response_code( $raw_response ) )
   251 		return false;
   315 		return false;
   252 
   316 
   253 	if( 200 != $raw_response['response']['code'] )
   317 	$new_update = new stdClass;
   254 		return false;
   318 	$new_update->last_checked = time( );
   255 
   319 	$new_update->checked = $checked;
   256 	$response = unserialize( $raw_response['body'] );
   320 
   257 	if( $response ) {
   321 	$response = maybe_unserialize( wp_remote_retrieve_body( $raw_response ) );
   258 		$new_option->checked = $checked;
   322 	if ( is_array( $response ) )
   259 		$new_option->response = $response;
   323 		$new_update->response = $response;
   260 	}
   324 
   261 
   325 	set_site_transient( 'update_themes', $new_update );
   262 	set_transient( 'update_themes', $new_option );
   326 }
       
   327 
       
   328 /*
       
   329  * Collect counts and UI strings for available updates
       
   330  *
       
   331  * @since 3.3.0
       
   332  *
       
   333  * @return array
       
   334  */
       
   335 function wp_get_update_data() {
       
   336 	$counts = array( 'plugins' => 0, 'themes' => 0, 'wordpress' => 0 );
       
   337 
       
   338 	if ( current_user_can( 'update_plugins' ) ) {
       
   339 		$update_plugins = get_site_transient( 'update_plugins' );
       
   340 		if ( ! empty( $update_plugins->response ) )
       
   341 			$counts['plugins'] = count( $update_plugins->response );
       
   342 	}
       
   343 
       
   344 	if ( current_user_can( 'update_themes' ) ) {
       
   345 		$update_themes = get_site_transient( 'update_themes' );
       
   346 		if ( ! empty( $update_themes->response ) )
       
   347 			$counts['themes'] = count( $update_themes->response );
       
   348 	}
       
   349 
       
   350 	if ( function_exists( 'get_core_updates' ) && current_user_can( 'update_core' ) ) {
       
   351 		$update_wordpress = get_core_updates( array('dismissed' => false) );
       
   352 		if ( ! empty( $update_wordpress ) && ! in_array( $update_wordpress[0]->response, array('development', 'latest') ) && current_user_can('update_core') )
       
   353 			$counts['wordpress'] = 1;
       
   354 	}
       
   355 
       
   356 	$counts['total'] = $counts['plugins'] + $counts['themes'] + $counts['wordpress'];
       
   357 	$update_title = array();
       
   358 	if ( $counts['wordpress'] )
       
   359 		$update_title[] = sprintf(__('%d WordPress Update'), $counts['wordpress']);
       
   360 	if ( $counts['plugins'] )
       
   361 		$update_title[] = sprintf(_n('%d Plugin Update', '%d Plugin Updates', $counts['plugins']), $counts['plugins']);
       
   362 	if ( $counts['themes'] )
       
   363 		$update_title[] = sprintf(_n('%d Theme Update', '%d Theme Updates', $counts['themes']), $counts['themes']);
       
   364 
       
   365 	$update_title = ! empty( $update_title ) ? esc_attr( implode( ', ', $update_title ) ) : '';
       
   366 
       
   367 	return array( 'counts' => $counts, 'title' => $update_title );
   263 }
   368 }
   264 
   369 
   265 function _maybe_update_core() {
   370 function _maybe_update_core() {
   266 	global $wp_version;
   371 	include ABSPATH . WPINC . '/version.php'; // include an unmodified $wp_version
   267 
   372 
   268 	$current = get_transient( 'update_core' );
   373 	$current = get_site_transient( 'update_core' );
   269 
   374 
   270 	if ( isset( $current->last_checked ) &&
   375 	if ( isset( $current->last_checked ) &&
   271 		43200 > ( time() - $current->last_checked ) &&
   376 		43200 > ( time() - $current->last_checked ) &&
   272 		isset( $current->version_checked ) &&
   377 		isset( $current->version_checked ) &&
   273 		$current->version_checked == $wp_version )
   378 		$current->version_checked == $wp_version )
   284  *
   389  *
   285  * @since 2.7.0
   390  * @since 2.7.0
   286  * @access private
   391  * @access private
   287  */
   392  */
   288 function _maybe_update_plugins() {
   393 function _maybe_update_plugins() {
   289 	$current = get_transient( 'update_plugins' );
   394 	$current = get_site_transient( 'update_plugins' );
   290 	if ( isset( $current->last_checked ) && 43200 > ( time() - $current->last_checked ) )
   395 	if ( isset( $current->last_checked ) && 43200 > ( time() - $current->last_checked ) )
   291 		return;
   396 		return;
   292 	wp_update_plugins();
   397 	wp_update_plugins();
   293 }
   398 }
   294 
   399 
   300  *
   405  *
   301  * @since 2.7.0
   406  * @since 2.7.0
   302  * @access private
   407  * @access private
   303  */
   408  */
   304 function _maybe_update_themes( ) {
   409 function _maybe_update_themes( ) {
   305 	$current = get_transient( 'update_themes' );
   410 	$current = get_site_transient( 'update_themes' );
   306 	if( isset( $current->last_checked ) && 43200 > ( time( ) - $current->last_checked ) )
   411 	if ( isset( $current->last_checked ) && 43200 > ( time( ) - $current->last_checked ) )
   307 		return;
   412 		return;
   308 
   413 
   309 	wp_update_themes();
   414 	wp_update_themes();
   310 }
   415 }
       
   416 
       
   417 /**
       
   418  * Schedule core, theme, and plugin update checks.
       
   419  *
       
   420  * @since 3.1.0
       
   421  */
       
   422 function wp_schedule_update_checks() {
       
   423 	if ( !wp_next_scheduled('wp_version_check') && !defined('WP_INSTALLING') )
       
   424 		wp_schedule_event(time(), 'twicedaily', 'wp_version_check');
       
   425 
       
   426 	if ( !wp_next_scheduled('wp_update_plugins') && !defined('WP_INSTALLING') )
       
   427 		wp_schedule_event(time(), 'twicedaily', 'wp_update_plugins');
       
   428 
       
   429 	if ( !wp_next_scheduled('wp_update_themes') && !defined('WP_INSTALLING') )
       
   430 		wp_schedule_event(time(), 'twicedaily', 'wp_update_themes');
       
   431 }
       
   432 
       
   433 if ( ( ! is_main_site() && ! is_network_admin() ) || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) )
       
   434 	return;
   311 
   435 
   312 add_action( 'admin_init', '_maybe_update_core' );
   436 add_action( 'admin_init', '_maybe_update_core' );
   313 add_action( 'wp_version_check', 'wp_version_check' );
   437 add_action( 'wp_version_check', 'wp_version_check' );
   314 
   438 
   315 add_action( 'load-plugins.php', 'wp_update_plugins' );
   439 add_action( 'load-plugins.php', 'wp_update_plugins' );
   318 add_action( 'admin_init', '_maybe_update_plugins' );
   442 add_action( 'admin_init', '_maybe_update_plugins' );
   319 add_action( 'wp_update_plugins', 'wp_update_plugins' );
   443 add_action( 'wp_update_plugins', 'wp_update_plugins' );
   320 
   444 
   321 add_action( 'load-themes.php', 'wp_update_themes' );
   445 add_action( 'load-themes.php', 'wp_update_themes' );
   322 add_action( 'load-update.php', 'wp_update_themes' );
   446 add_action( 'load-update.php', 'wp_update_themes' );
       
   447 add_action( 'load-update-core.php', 'wp_update_themes' );
   323 add_action( 'admin_init', '_maybe_update_themes' );
   448 add_action( 'admin_init', '_maybe_update_themes' );
   324 add_action( 'wp_update_themes', 'wp_update_themes' );
   449 add_action( 'wp_update_themes', 'wp_update_themes' );
   325 
   450 
   326 if ( !wp_next_scheduled('wp_version_check') && !defined('WP_INSTALLING') )
   451 add_action('init', 'wp_schedule_update_checks');
   327 	wp_schedule_event(time(), 'twicedaily', 'wp_version_check');
       
   328 
       
   329 if ( !wp_next_scheduled('wp_update_plugins') && !defined('WP_INSTALLING') )
       
   330 	wp_schedule_event(time(), 'twicedaily', 'wp_update_plugins');
       
   331 
       
   332 if ( !wp_next_scheduled('wp_update_themes') && !defined('WP_INSTALLING') )
       
   333 	wp_schedule_event(time(), 'twicedaily', 'wp_update_themes');
       
   334 
       
   335 ?>