Make WordPress Core


Ignore:
Timestamp:
06/06/2024 08:00:08 AM (7 months ago)
Author:
oandregal
Message:

Editor: code quality improvements for theme.json migrate API

Backports https://github.com/WordPress/gutenberg/pull/62305

Follow-up to [58328], #61282.

Props ajlende, oandregal, ramonopoly, mukesh27.
Fixes #61282.

File:
1 edited

Legend:

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

    r58339 r58354  
    3636     *
    3737     * @since 5.9.0
    38      * @since 6.6.0 Migrate up to v3.
     38     * @since 6.6.0 Migrate up to v3 and add $origin parameter.
    3939     *
    4040     * @param array $theme_json The structure to migrate.
    41      *
     41     * @param string $origin    Optional. What source of data this object represents.
     42     *                          One of 'blocks', 'default', 'theme', or 'custom'. Default 'theme'.
    4243     * @return array The structure in the last version.
    4344     */
    44     public static function migrate( $theme_json ) {
     45    public static function migrate( $theme_json, $origin = 'theme' ) {
    4546        if ( ! isset( $theme_json['version'] ) ) {
    4647            $theme_json = array(
     
    5556                // Deliberate fall through. Once migrated to v2, also migrate to v3.
    5657            case 2:
    57                 $theme_json = self::migrate_v2_to_v3( $theme_json );
     58                $theme_json = self::migrate_v2_to_v3( $theme_json, $origin );
    5859        }
    5960
     
    101102     * @since 6.6.0
    102103     *
    103      * @param array $old Data to migrate.
    104      *
     104     * @param array $old     Data to migrate.
     105     * @param string $origin What source of data this object represents.
     106     *                       One of 'blocks', 'default', 'theme', or 'custom'.
    105107     * @return array Data with defaultFontSizes set to false.
    106108     */
    107     private static function migrate_v2_to_v3( $old ) {
     109    private static function migrate_v2_to_v3( $old, $origin ) {
    108110        // Copy everything.
    109111        $new = $old;
     
    116118         * as they should take on the value of the theme origin.
    117119         */
    118         if (
    119             isset( $new['isGlobalStylesUserThemeJSON'] ) &&
    120             true === $new['isGlobalStylesUserThemeJSON']
    121         ) {
     120        if ( 'custom' === $origin ) {
    122121            return $new;
    123122        }
Note: See TracChangeset for help on using the changeset viewer.