Make WordPress Core

Ticket #14179: 14179-UpdateURI-header-refresh.diff

File 14179-UpdateURI-header-refresh.diff, 5.2 KB (added by costdev, 2 years ago)

Refresh against trunk.

  • src/wp-includes/class-wp-theme.php

    diff --git a/src/wp-includes/class-wp-theme.php b/src/wp-includes/class-wp-theme.php
    index cef5b034c6..faa6cdfbcd 100644
    a b final class WP_Theme implements ArrayAccess { 
    2323         *
    2424         * @since 3.4.0
    2525         * @since 5.4.0 Added `Requires at least` and `Requires PHP` headers.
     26         * @since 6.0.0 Added support for `Update URI` header.
    2627         * @var string[]
    2728         */
    2829        private static $file_headers = array(
    final class WP_Theme implements ArrayAccess { 
    3940                'DomainPath'  => 'Domain Path',
    4041                'RequiresWP'  => 'Requires at least',
    4142                'RequiresPHP' => 'Requires PHP',
     43                'UpdateURI'   => 'Update URI',
    4244        );
    4345
    4446        /**
    final class WP_Theme implements ArrayAccess { 
    894896                        case 'Version':
    895897                        case 'RequiresWP':
    896898                        case 'RequiresPHP':
     899                        case 'UpdateURI':
    897900                                $value = strip_tags( $value );
    898901                                break;
    899902                }
  • src/wp-includes/update.php

    diff --git a/src/wp-includes/update.php b/src/wp-includes/update.php
    index a18a81e477..2f01cdeb7e 100644
    a b function wp_update_themes( $extra_stats = array() ) { 
    577577                        'Version'    => $theme->get( 'Version' ),
    578578                        'Author'     => $theme->get( 'Author' ),
    579579                        'Author URI' => $theme->get( 'AuthorURI' ),
     580                        'UpdateURI'  => $theme->get( 'UpdateURI' ),
    580581                        'Template'   => $theme->get_template(),
    581582                        'Stylesheet' => $theme->get_stylesheet(),
    582583                );
    function wp_update_themes( $extra_stats = array() ) { 
    708709                $new_update->translations = $response['translations'];
    709710        }
    710711
     712        // Support updates for any themes using the `Update URI` header field.
     713        foreach ( $themes as $theme_stylesheet => $theme_data ) {
     714                if ( ! $theme_data['UpdateURI'] || isset( $new_update->response[ $theme_stylesheet ] ) ) {
     715                        continue;
     716                }
     717
     718                $hostname = wp_parse_url( esc_url_raw( $theme_data['UpdateURI'] ), PHP_URL_HOST );
     719
     720                /**
     721                 * Filters the update response for a given theme hostname.
     722                 *
     723                 * The dynamic portion of the hook name, `$hostname`, refers to the hostname
     724                 * of the URI specified in the `Update URI` header field.
     725                 *
     726                 * @since 6.0.0
     727                 *
     728                 * @param array|false $update {
     729                 *     The theme update data with the latest details. Default false.
     730                 *
     731                 *     @type string $id           Optional. ID of the theme for update purposes, should be a URI
     732                 *                                specified in the `Update URI` header field.
     733                 *     @type string $theme        Directory name of the theme.
     734                 *     @type string $version      The version of the theme.
     735                 *     @type string $url          The URL for details of the theme.
     736                 *     @type string $package      Optional. The update ZIP for the theme.
     737                 *     @type string $tested       Optional. The version of WordPress the theme is tested against.
     738                 *     @type string $requires_php Optional. The version of PHP which the theme requires.
     739                 *     @type bool   $autoupdate   Optional. Whether the theme should automatically update.
     740                 *     @type array  $translations {
     741                 *         Optional. List of translation updates for the theme.
     742                 *
     743                 *         @type string $language   The language the translation update is for.
     744                 *         @type string $version    The version of the theme this translation is for.
     745                 *                                  This is not the version of the language file.
     746                 *         @type string $updated    The update timestamp of the translation file.
     747                 *                                  Should be a date in the `YYYY-MM-DD HH:MM:SS` format.
     748                 *         @type string $package    The ZIP location containing the translation update.
     749                 *         @type string $autoupdate Whether the translation should be automatically installed.
     750                 *     }
     751                 * }
     752                 * @param array       $theme_data       Theme headers.
     753                 * @param string      $theme_stylesheet Theme stylesheet.
     754                 * @param array       $locales          Installed locales to look translations for.
     755                 */
     756                $update = apply_filters( "update_themes_{$hostname}", false, $theme_data, $theme_stylesheet, $locales );
     757
     758                if ( ! $update ) {
     759                        continue;
     760                }
     761
     762                $update = (object) $update;
     763
     764                // Is it valid? We require at least a version.
     765                if ( ! isset( $update->version ) ) {
     766                        continue;
     767                }
     768
     769                // These should remain constant.
     770                $update->id = $theme_data['UpdateURI'];
     771
     772                // WordPress needs the version field specified as 'new_version'.
     773                if ( ! isset( $update->new_version ) ) {
     774                        $update->new_version = $update->version;
     775                }
     776
     777                // Handle any translation updates.
     778                if ( ! empty( $update->translations ) ) {
     779                        foreach ( $update->translations as $translation ) {
     780                                if ( isset( $translation['language'], $translation['package'] ) ) {
     781                                        $translation['type'] = 'theme';
     782                                        $translation['slug'] = isset( $update->theme ) ? $update->theme : $update->id;
     783
     784                                        $new_update->translations[] = $translation;
     785                                }
     786                        }
     787                }
     788
     789                unset( $new_update->no_update[ $theme_stylesheet ], $new_update->response[ $theme_stylesheet ] );
     790
     791                if ( version_compare( $update->new_version, $theme_data['Version'], '>' ) ) {
     792                        $new_update->response[ $theme_stylesheet ] = (array) $update;
     793                } else {
     794                        $new_update->no_update[ $theme_stylesheet ] = (array) $update;
     795                }
     796        }
     797
    711798        set_site_transient( 'update_themes', $new_update );
    712799}
    713800