Make WordPress Core

Changeset 53933

Timestamp:
08/23/2022 05:46:46 PM (2 years ago)
Author:
SergeyBiryukov
Message:

Themes: Add support for Update URI header.

This allows third-party themes to avoid accidentally being overwritten with an update of a theme of a similar name from the WordPress.org Theme Directory.

Additionally, introduce the update_themes_{$hostname} filter, which third-party themes can use to offer updates for a given hostname.

If set, the Update URI header field should be a URI and have a unique hostname.

Some examples include:

  • https://wordpress.org/themes/example-theme/
  • https://example.com/my-theme/
  • my-custom-theme-name

Update URI: false also works, and unless there is code handling the false hostname, the theme will never get an update notification.

If the header is present, the WordPress.org API will currently only return updates for the theme if it matches the following format:

  • https://wordpress.org/themes/{$slug}/
  • w.org/theme/{$slug}

If the header has any other value, the API will not return a result and will ignore the theme for update purposes.

Follow-up to [50921].

Props dd32, meloniq, costdev, audrasjb, DavidAnderson, markjaquith, DrewAPicture, mweichert, design_dolphin, filosofo, sean212, nhuja, JeroenReumkens, infolu, dingdang, joyously, earnjam, williampatton, grapplerulrich, markparnell, apedog, afragen, miqrogroove, rmccue, crazycoders, jdgrimes, damonganto, joostdevalk, jorbin, georgestephanis, khromov, GeekStreetWP, jb510, Rarst, juliobox, Ipstenu, mikejolley, Otto42, gMagicScott, TJNowell, GaryJ, knutsp, mordauk, nvartolomei, aspexi, chriscct7, benoitchantre, ryno267, lev0, gregorlove, dougwollison, leemon, SergeyBiryukov.
See #14179, #23318, #32101.

Location:
trunk
Files:
3 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-theme.php

    r53700 r53933  
    2424     * @since 3.4.0
    2525     * @since 5.4.0 Added `Requires at least` and `Requires PHP` headers.
     26
    2627     * @var string[]
    2728     */
     
    4041        'RequiresWP'  => 'Requires at least',
    4142        'RequiresPHP' => 'Requires PHP',
     43
    4244    );
    4345
     
    845847     * @since 3.4.0
    846848     * @since 5.4.0 Added support for `Requires at least` and `Requires PHP` headers.
     849
    847850     *
    848851     * @param string $header Theme header. Accepts 'Name', 'Description', 'Author', 'Version',
    849      *                       'ThemeURI', 'AuthorURI', 'Status', 'Tags', 'RequiresWP', 'RequiresPHP'.
     852     *                       'ThemeURI', 'AuthorURI', 'Status', 'Tags', 'RequiresWP', 'RequiresPHP',
     853     *                       'UpdateURI'.
    850854     * @param string $value  Value to sanitize.
    851855     * @return string|array An array for Tags header, string otherwise.
     
    897901            case 'RequiresWP':
    898902            case 'RequiresPHP':
     903
    899904                $value = strip_tags( $value );
    900905                break;
  • trunk/src/wp-includes/update.php

    r53753 r53933  
    506506         * @param array       $plugin_data      Plugin headers.
    507507         * @param string      $plugin_file      Plugin filename.
    508          * @param array       $locales          Installed locales to look translations for.
     508         * @param array       $locales          Installed locales to look translations for.
    509509         */
    510510        $update = apply_filters( "update_plugins_{$hostname}", false, $plugin_data, $plugin_file, $locales );
     
    614614            'Author'     => $theme->get( 'Author' ),
    615615            'Author URI' => $theme->get( 'AuthorURI' ),
     616
    616617            'Template'   => $theme->get_template(),
    617618            'Stylesheet' => $theme->get_stylesheet(),
     
    745746    }
    746747
     748
     749
     750
     751
     752
     753
     754
     755
     756
     757
     758
     759
     760
     761
     762
     763
     764
     765
     766
     767
     768
     769
     770
     771
     772
     773
     774
     775
     776
     777
     778
     779
     780
     781
     782
     783
     784
     785
     786
     787
     788
     789
     790
     791
     792
     793
     794
     795
     796
     797
     798
     799
     800
     801
     802
     803
     804
     805
     806
     807
     808
     809
     810
     811
     812
     813
     814
     815
     816
     817
     818
     819
     820
     821
     822
     823
     824
     825
     826
     827
     828
     829
     830
     831
     832
     833
    747834    set_site_transient( 'update_themes', $new_update );
    748835}
  • trunk/tests/phpunit/tests/theme/themeDir.php

    r53916 r53933  
    183183            'Webfonts theme',
    184184            'Empty `fontFace` in theme.json - no webfonts defined',
     185
    185186        );
    186187
  • trunk/tests/phpunit/tests/theme/wpTheme.php

    r53916 r53933  
    406406        );
    407407    }
     408
     409
     410
     411
     412
     413
     414
     415
     416
     417
     418
     419
     420
     421
     422
     423
     424
     425
     426
     427
     428
     429
     430
     431
     432
     433
     434
     435
     436
     437
     438
     439
     440
     441
     442
     443
     444
     445
     446
     447
     448
     449
     450
     451
     452
     453
    408454}
Note: See TracChangeset for help on using the changeset viewer.