Make WordPress Core


Ignore:
Timestamp:
09/20/2022 01:10:28 PM (2 years ago)
Author:
audrasjb
Message:

Editor: Backport hooks to filter theme.json data from Gutenberg to 6.1.

This changeset ports the work done in Gutenberg (released in 14.1) to add hooks to filter the theme.json data. Specifically, it adds the following filters: theme_json_default, theme_json_blocks, theme_json_theme, and theme_json_user.

For more details, see the following Gutenberg pull requests:

Props oandregal, czapla, gziolo, bernhard-reiter.
See #56467.

File:
1 edited

Legend:

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

    r54246 r54251  
    138138        $config       = static::read_json_file( __DIR__ . '/theme.json' );
    139139        $config       = static::translate( $config );
     140        /**
     141         * Filters the default data provided by WordPress for global styles & settings.
     142         *
     143         * @since 6.1.0
     144         *
     145         * @param WP_Theme_JSON_Data Class to access and update the underlying data.
     146         */
     147        $theme_json   = apply_filters( 'theme_json_default', new WP_Theme_JSON_Data( $config, 'default' ) );
     148        $config       = $theme_json->get_data();
    140149        static::$core = new WP_Theme_JSON( $config, 'default' );
    141150
     
    173182            $theme_json_data = static::read_json_file( static::get_file_path_from_theme( 'theme.json' ) );
    174183            $theme_json_data = static::translate( $theme_json_data, wp_get_theme()->get( 'TextDomain' ) );
     184            /**
     185             * Filters the data provided by the theme for global styles & settings.
     186             *
     187             * @since 6.1.0
     188             *
     189             * @param WP_Theme_JSON_Data Class to access and update the underlying data.
     190             */
     191            $theme_json      = apply_filters( 'theme_json_theme', new WP_Theme_JSON_Data( $theme_json_data, 'theme' ) );
     192            $theme_json_data = $theme_json->get_data();
    175193            static::$theme   = new WP_Theme_JSON( $theme_json_data );
    176194
     
    258276            }
    259277        }
     278
     279        /**
     280         * Filters the data provided by the blocks for global styles & settings.
     281         *
     282         * @since 6.1.0
     283         *
     284         * @param WP_Theme_JSON_Data Class to access and update the underlying data.
     285         */
     286        $theme_json = apply_filters( 'theme_json_blocks', new WP_Theme_JSON_Data( $config, 'core' ) );
     287        $config     = $theme_json->get_data();
    260288
    261289        // Core here means it's the lower level part of the styles chain.
     
    383411            if ( JSON_ERROR_NONE !== $json_decoding_error ) {
    384412                trigger_error( 'Error when decoding a theme.json schema for user data. ' . json_last_error_msg() );
     413                /**
     414                 * Filters the data provided by the user for global styles & settings.
     415                 *
     416                 * @since 6.1.0
     417                 *
     418                 * @param WP_Theme_JSON_Data Class to access and update the underlying data.
     419                 */
     420                $theme_json = apply_filters( 'theme_json_user', new WP_Theme_JSON_Data( $config, 'custom' ) );
     421                $config     = $theme_json->get_data();
    385422                return new WP_Theme_JSON( $config, 'custom' );
    386423            }
     
    397434            }
    398435        }
     436
     437        /**
     438         * Filters the data provided by the user for global styles & settings.
     439         *
     440         * @since 6.1.0
     441         *
     442         * @param WP_Theme_JSON_Data Class to access and update the underlying data.
     443         */
     444        $theme_json   = apply_filters( 'theme_json_user', new WP_Theme_JSON_Data( $config, 'custom' ) );
     445        $config       = $theme_json->get_data();
    399446        static::$user = new WP_Theme_JSON( $config, 'custom' );
    400447
Note: See TracChangeset for help on using the changeset viewer.