Skip to content

Commit

Permalink
Address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
oandregal committed Jun 12, 2024
1 parent d51c763 commit 10a638a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
4 changes: 3 additions & 1 deletion src/wp-includes/block-supports/block-style-variations.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ function wp_resolve_block_style_variations( $variations ) {
* Block style variations read in via standalone theme.json partials
* need to have their name set to the kebab case version of their title.
*/
$variation_name = $have_named_variations ? $key : _wp_to_kebab_case( $variation['title'] );
$variation_name = $have_named_variations ? $key : _wp_to_kebab_case( $variation['title'] );

foreach ( $supported_blocks as $block_type ) {
// Add block style variation data under current block type.
Expand Down Expand Up @@ -409,6 +409,7 @@ function wp_enqueue_block_style_variation_styles() {
* Registers any block style variations contained within the provided
* theme.json data.
*
* @since 6.6.0
* @access private
*
* @param array $variations Shared block style variations.
Expand Down Expand Up @@ -468,6 +469,7 @@ function wp_register_block_style_variations_from_theme_json_data( $variations )
* - the theme's partials (standalone files in `/styles` that only define block style variations)
* - the user's theme.json (for example, theme style variations the user selected)
*
* @since 6.6.0
* @access private
*/
function wp_register_block_style_variations_from_theme() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ public function update_item_permissions_check( $request ) {
*
* @since 5.9.0
* @since 6.2.0 Added validation of styles.css property.
* @since 6.6.0 Added registration of newly created style variations provided by the user.
*
* @param WP_REST_Request $request Request object.
* @return stdClass|WP_Error Prepared item on success. WP_Error on when the custom CSS is not valid.
Expand Down Expand Up @@ -264,14 +265,16 @@ protected function prepare_item_for_database( $request ) {
$config['styles'] = $existing_config['styles'];
}

// If the incoming request is going to create a new variation
// that is not yet registered, we register it here.
// This is because the variations are registered on init,
// but we want this endpoint to return the new variation immediately:
// if we don't register it, it'll be stripped out of the response
// just in this request (subsequent ones will be ok).
// Take the variations defined in styles.blocks.variations from the incoming request
// that are not part of the $exsting_config.
/*
* If the incoming request is going to create a new variation
* that is not yet registered, we register it here.
* This is because the variations are registered on init,
* but we want this endpoint to return the new variation immediately:
* if we don't register it, it'll be stripped out of the response
* just in this request (subsequent ones will be ok).
* Take the variations defined in styles.blocks.variations from the incoming request
* that are not part of the $exsting_config.
*/
if ( isset( $request['styles']['blocks']['variations'] ) ) {
$existing_variations = isset( $existing_config['styles']['blocks']['variations'] ) ? $existing_config['styles']['blocks']['variations'] : array();
$new_variations = array_diff_key( $request['styles']['blocks']['variations'], $existing_variations );
Expand Down

0 comments on commit 10a638a

Please sign in to comment.