wp/wp-includes/update.php
changeset 18 be944660c56a
parent 16 a86126ab1dd4
child 19 3d72ae0968f4
equal deleted inserted replaced
17:34716fd837a4 18:be944660c56a
   103 		'multisite_enabled'  => $multisite_enabled,
   103 		'multisite_enabled'  => $multisite_enabled,
   104 		'initial_db_version' => get_site_option( 'initial_db_version' ),
   104 		'initial_db_version' => get_site_option( 'initial_db_version' ),
   105 	);
   105 	);
   106 
   106 
   107 	/**
   107 	/**
   108 	 * Filter the query arguments sent as part of the core version check.
   108 	 * Filters the query arguments sent as part of the core version check.
   109 	 *
   109 	 *
   110 	 * WARNING: Changing this data may result in your site not receiving security updates.
   110 	 * WARNING: Changing this data may result in your site not receiving security updates.
   111 	 * Please exercise extreme caution.
   111 	 * Please exercise extreme caution.
   112 	 *
   112 	 *
   113 	 * @since 4.9.0
   113 	 * @since 4.9.0
   132 		'translations' => wp_json_encode( $translations ),
   132 		'translations' => wp_json_encode( $translations ),
   133 	);
   133 	);
   134 
   134 
   135 	if ( is_array( $extra_stats ) ) {
   135 	if ( is_array( $extra_stats ) ) {
   136 		$post_body = array_merge( $post_body, $extra_stats );
   136 		$post_body = array_merge( $post_body, $extra_stats );
       
   137 	}
       
   138 
       
   139 	// Allow for WP_AUTO_UPDATE_CORE to specify beta/RC/development releases.
       
   140 	if ( defined( 'WP_AUTO_UPDATE_CORE' )
       
   141 		&& in_array( WP_AUTO_UPDATE_CORE, array( 'beta', 'rc', 'development', 'branch-development' ), true )
       
   142 	) {
       
   143 		$query['channel'] = WP_AUTO_UPDATE_CORE;
   137 	}
   144 	}
   138 
   145 
   139 	$url      = 'http://api.wordpress.org/core/version-check/1.7/?' . http_build_query( $query, null, '&' );
   146 	$url      = 'http://api.wordpress.org/core/version-check/1.7/?' . http_build_query( $query, null, '&' );
   140 	$http_url = $url;
   147 	$http_url = $url;
   141 	$ssl      = wp_http_supports( array( 'ssl' ) );
   148 	$ssl      = wp_http_supports( array( 'ssl' ) );
   287 
   294 
   288 	if ( ! is_object( $current ) ) {
   295 	if ( ! is_object( $current ) ) {
   289 		$current = new stdClass;
   296 		$current = new stdClass;
   290 	}
   297 	}
   291 
   298 
   292 	$new_option               = new stdClass;
   299 	$updates               = new stdClass;
   293 	$new_option->last_checked = time();
   300 	$updates->last_checked = time();
       
   301 	$updates->response     = array();
       
   302 	$updates->translations = array();
       
   303 	$updates->no_update    = array();
   294 
   304 
   295 	$doing_cron = wp_doing_cron();
   305 	$doing_cron = wp_doing_cron();
   296 
   306 
   297 	// Check for update on a different schedule, depending on the page.
   307 	// Check for update on a different schedule, depending on the page.
   298 	switch ( current_filter() ) {
   308 	switch ( current_filter() ) {
   318 
   328 
   319 	if ( $time_not_changed && ! $extra_stats ) {
   329 	if ( $time_not_changed && ! $extra_stats ) {
   320 		$plugin_changed = false;
   330 		$plugin_changed = false;
   321 
   331 
   322 		foreach ( $plugins as $file => $p ) {
   332 		foreach ( $plugins as $file => $p ) {
   323 			$new_option->checked[ $file ] = $p['Version'];
   333 			$updates->checked[ $file ] = $p['Version'];
   324 
   334 
   325 			if ( ! isset( $current->checked[ $file ] ) || strval( $current->checked[ $file ] ) !== strval( $p['Version'] ) ) {
   335 			if ( ! isset( $current->checked[ $file ] ) || (string) $current->checked[ $file ] !== (string) $p['Version'] ) {
   326 				$plugin_changed = true;
   336 				$plugin_changed = true;
   327 			}
   337 			}
   328 		}
   338 		}
   329 
   339 
   330 		if ( isset( $current->response ) && is_array( $current->response ) ) {
   340 		if ( isset( $current->response ) && is_array( $current->response ) ) {
   409 		return;
   419 		return;
   410 	}
   420 	}
   411 
   421 
   412 	$response = json_decode( wp_remote_retrieve_body( $raw_response ), true );
   422 	$response = json_decode( wp_remote_retrieve_body( $raw_response ), true );
   413 
   423 
   414 	foreach ( $response['plugins'] as &$plugin ) {
   424 	if ( $response && is_array( $response ) ) {
   415 		$plugin = (object) $plugin;
   425 		$updates->response     = $response['plugins'];
   416 
   426 		$updates->translations = $response['translations'];
   417 		if ( isset( $plugin->compatibility ) ) {
   427 		$updates->no_update    = $response['no_update'];
   418 			$plugin->compatibility = (object) $plugin->compatibility;
   428 	}
   419 
   429 
   420 			foreach ( $plugin->compatibility as &$data ) {
   430 	// Support updates for any plugins using the `Update URI` header field.
   421 				$data = (object) $data;
   431 	foreach ( $plugins as $plugin_file => $plugin_data ) {
       
   432 		if ( ! $plugin_data['UpdateURI'] || isset( $updates->response[ $plugin_file ] ) ) {
       
   433 			continue;
       
   434 		}
       
   435 
       
   436 		$hostname = wp_parse_url( esc_url_raw( $plugin_data['UpdateURI'] ), PHP_URL_HOST );
       
   437 
       
   438 		/**
       
   439 		 * Filters the update response for a given plugin hostname.
       
   440 		 *
       
   441 		 * The dynamic portion of the hook name, `$hostname`, refers to the hostname
       
   442 		 * of the URI specified in the `Update URI` header field.
       
   443 		 *
       
   444 		 * @since 5.8.0
       
   445 		 *
       
   446 		 * @param array|false $update {
       
   447 		 *     The plugin update data with the latest details. Default false.
       
   448 		 *
       
   449 		 *     @type string $id           Optional. ID of the plugin for update purposes, should be a URI
       
   450 		 *                                specified in the `Update URI` header field.
       
   451 		 *     @type string $slug         Slug of the plugin.
       
   452 		 *     @type string $version      The version of the plugin.
       
   453 		 *     @type string $url          The URL for details of the plugin.
       
   454 		 *     @type string $package      Optional. The update ZIP for the plugin.
       
   455 		 *     @type string $tested       Optional. The version of WordPress the plugin is tested against.
       
   456 		 *     @type string $requires_php Optional. The version of PHP which the plugin requires.
       
   457 		 *     @type bool   $autoupdate   Optional. Whether the plugin should automatically update.
       
   458 		 *     @type array  $icons        Optional. Array of plugin icons.
       
   459 		 *     @type array  $banners      Optional. Array of plugin banners.
       
   460 		 *     @type array  $banners_rtl  Optional. Array of plugin RTL banners.
       
   461 		 *     @type array  $translations {
       
   462 		 *         Optional. List of translation updates for the plugin.
       
   463 		 *
       
   464 		 *         @type string $language   The language the translation update is for.
       
   465 		 *         @type string $version    The version of the plugin this translation is for.
       
   466 		 *                                  This is not the version of the language file.
       
   467 		 *         @type string $updated    The update timestamp of the translation file.
       
   468 		 *                                  Should be a date in the `YYYY-MM-DD HH:MM:SS` format.
       
   469 		 *         @type string $package    The ZIP location containing the translation update.
       
   470 		 *         @type string $autoupdate Whether the translation should be automatically installed.
       
   471 		 *     }
       
   472 		 * }
       
   473 		 * @param array       $plugin_data      Plugin headers.
       
   474 		 * @param string      $plugin_file      Plugin filename.
       
   475 		 * @param array       $locales          Installed locales to look translations for.
       
   476 		 */
       
   477 		$update = apply_filters( "update_plugins_{$hostname}", false, $plugin_data, $plugin_file, $locales );
       
   478 
       
   479 		if ( ! $update ) {
       
   480 			continue;
       
   481 		}
       
   482 
       
   483 		$update = (object) $update;
       
   484 
       
   485 		// Is it valid? We require at least a version.
       
   486 		if ( ! isset( $update->version ) ) {
       
   487 			continue;
       
   488 		}
       
   489 
       
   490 		// These should remain constant.
       
   491 		$update->id     = $plugin_data['UpdateURI'];
       
   492 		$update->plugin = $plugin_file;
       
   493 
       
   494 		// WordPress needs the version field specified as 'new_version'.
       
   495 		if ( ! isset( $update->new_version ) ) {
       
   496 			$update->new_version = $update->version;
       
   497 		}
       
   498 
       
   499 		// Handle any translation updates.
       
   500 		if ( ! empty( $update->translations ) ) {
       
   501 			foreach ( $update->translations as $translation ) {
       
   502 				if ( isset( $translation['language'], $translation['package'] ) ) {
       
   503 					$translation['type'] = 'plugin';
       
   504 					$translation['slug'] = isset( $update->slug ) ? $update->slug : $update->id;
       
   505 
       
   506 					$updates->translations[] = $translation;
       
   507 				}
   422 			}
   508 			}
   423 		}
   509 		}
   424 	}
   510 
   425 
   511 		unset( $updates->no_update[ $plugin_file ], $updates->response[ $plugin_file ] );
   426 	unset( $plugin, $data );
   512 
   427 
   513 		if ( version_compare( $update->new_version, $plugin_data['Version'], '>' ) ) {
   428 	foreach ( $response['no_update'] as &$plugin ) {
   514 			$updates->response[ $plugin_file ] = $update;
   429 		$plugin = (object) $plugin;
   515 		} else {
   430 	}
   516 			$updates->no_update[ $plugin_file ] = $update;
   431 
   517 		}
   432 	unset( $plugin );
   518 	}
   433 
   519 
   434 	if ( is_array( $response ) ) {
   520 	$sanitize_plugin_update_payload = function( &$item ) {
   435 		$new_option->response     = $response['plugins'];
   521 		$item = (object) $item;
   436 		$new_option->translations = $response['translations'];
   522 
   437 		// TODO: Perhaps better to store no_update in a separate transient with an expiry?
   523 		unset( $item->translations, $item->compatibility );
   438 		$new_option->no_update = $response['no_update'];
   524 
   439 	} else {
   525 		return $item;
   440 		$new_option->response     = array();
   526 	};
   441 		$new_option->translations = array();
   527 
   442 		$new_option->no_update    = array();
   528 	array_walk( $updates->response, $sanitize_plugin_update_payload );
   443 	}
   529 	array_walk( $updates->no_update, $sanitize_plugin_update_payload );
   444 
   530 
   445 	set_site_transient( 'update_plugins', $new_option );
   531 	set_site_transient( 'update_plugins', $updates );
   446 }
   532 }
   447 
   533 
   448 /**
   534 /**
   449  * Checks for available updates to themes based on the latest versions hosted on WordPress.org.
   535  * Checks for available updates to themes based on the latest versions hosted on WordPress.org.
   450  *
   536  *
   525 
   611 
   526 	if ( $time_not_changed && ! $extra_stats ) {
   612 	if ( $time_not_changed && ! $extra_stats ) {
   527 		$theme_changed = false;
   613 		$theme_changed = false;
   528 
   614 
   529 		foreach ( $checked as $slug => $v ) {
   615 		foreach ( $checked as $slug => $v ) {
   530 			if ( ! isset( $last_update->checked[ $slug ] ) || strval( $last_update->checked[ $slug ] ) !== strval( $v ) ) {
   616 			if ( ! isset( $last_update->checked[ $slug ] ) || (string) $last_update->checked[ $slug ] !== (string) $v ) {
   531 				$theme_changed = true;
   617 				$theme_changed = true;
   532 			}
   618 			}
   533 		}
   619 		}
   534 
   620 
   535 		if ( isset( $last_update->response ) && is_array( $last_update->response ) ) {
   621 		if ( isset( $last_update->response ) && is_array( $last_update->response ) ) {