Skip to content

Commit

Permalink
Register teh newly created style variations.
Browse files Browse the repository at this point in the history
  • Loading branch information
oandregal committed Jun 11, 2024
1 parent 6a197d3 commit f301591
Showing 1 changed file with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,23 @@ protected function prepare_item_for_database( $request ) {
} elseif ( isset( $existing_config['styles'] ) ) {
$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 ( 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 );
if ( ! empty( $new_variations ) ) {
wp_register_block_style_variations_from_theme_json_data( $new_variations );
}
}

if ( isset( $request['settings'] ) ) {
$config['settings'] = $request['settings'];
} elseif ( isset( $existing_config['settings'] ) ) {
Expand Down

0 comments on commit f301591

Please sign in to comment.