Make WordPress Core


Ignore:
Timestamp:
06/06/2024 08:00:08 AM (21 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.php

    r58339 r58354  
    748748     * @param array  $theme_json A structure that follows the theme.json schema.
    749749     * @param string $origin     Optional. What source of data this object represents.
    750      *                           One of 'default', 'theme', or 'custom'. Default 'theme'.
     750     *                           One of 'blocks', 'default', 'theme', or 'custom'. Default 'theme'.
    751751     */
    752752    public function __construct( $theme_json = array( 'version' => WP_Theme_JSON::LATEST_SCHEMA ), $origin = 'theme' ) {
     
    755755        }
    756756
    757         $this->theme_json    = WP_Theme_JSON_Schema::migrate( $theme_json );
     757        $this->theme_json    = WP_Theme_JSON_Schema::migrate( $theme_json, $origin );
    758758        $valid_block_names   = array_keys( static::get_blocks_metadata() );
    759759        $valid_element_names = array_keys( static::ELEMENTS );
     
    32433243     * @since 5.9.0
    32443244     * @since 6.3.2 Preserves global styles block variations when securing styles.
    3245      * @since 6.6.0 Updated to allow variation element styles.
     3245     * @since 6.6.0 Updated to allow variation element styles and $origin parameter.
    32463246     *
    32473247     * @param array $theme_json Structure to sanitize.
     3248     * @param string $origin    Optional. What source of data this object represents.
     3249     *                          One of 'blocks', 'default', 'theme', or 'custom'. Default 'theme'.
    32483250     * @return array Sanitized structure.
    32493251     */
    3250     public static function remove_insecure_properties( $theme_json ) {
     3252    public static function remove_insecure_properties( $theme_json, $origin = 'theme' ) {
     3253        if ( ! in_array( $origin, static::VALID_ORIGINS, true ) ) {
     3254            $origin = 'theme';
     3255        }
     3256
    32513257        $sanitized = array();
    32523258
    3253         $theme_json = WP_Theme_JSON_Schema::migrate( $theme_json );
     3259        $theme_json = WP_Theme_JSON_Schema::migrate( $theme_json, $origin );
    32543260
    32553261        $valid_block_names   = array_keys( static::get_blocks_metadata() );
Note: See TracChangeset for help on using the changeset viewer.