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' ) ); |
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 * |