Make WordPress Core


Ignore:
Timestamp:
06/12/2024 07:15:06 AM (2 years ago)
Author:
oandregal
Message:

Editor: register block style variations defined by the theme using the init action.

Props oandregal, aaronrobertshaw, annezazu.

Follow-up to [58264].
See #61312.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-global-styles-controller.php

    r58262 r58394  
    232232     * @since 5.9.0
    233233     * @since 6.2.0 Added validation of styles.css property.
     234     * @since 6.6.0 Added registration of newly created style variations provided by the user.
    234235     *
    235236     * @param WP_REST_Request $request Request object.
     
    264265                $config['styles'] = $existing_config['styles'];
    265266            }
     267
     268            /*
     269             * If the incoming request is going to create a new variation
     270             * that is not yet registered, we register it here.
     271             * This is because the variations are registered on init,
     272             * but we want this endpoint to return the new variation immediately:
     273             * if we don't register it, it'll be stripped out of the response
     274             * just in this request (subsequent ones will be ok).
     275             * Take the variations defined in styles.blocks.variations from the incoming request
     276             * that are not part of the $exsting_config.
     277             */
     278            if ( isset( $request['styles']['blocks']['variations'] ) ) {
     279                $existing_variations = isset( $existing_config['styles']['blocks']['variations'] ) ? $existing_config['styles']['blocks']['variations'] : array();
     280                $new_variations      = array_diff_key( $request['styles']['blocks']['variations'], $existing_variations );
     281                if ( ! empty( $new_variations ) ) {
     282                    wp_register_block_style_variations_from_theme_json_data( $new_variations );
     283                }
     284            }
     285
    266286            if ( isset( $request['settings'] ) ) {
    267287                $config['settings'] = $request['settings'];
Note: See TracChangeset for help on using the changeset viewer.