Skip to content

Commit

Permalink
Try moving stabilization to after the filter is run
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewserong committed Jul 26, 2024
1 parent 7521f6a commit 76ceb8d
Showing 1 changed file with 39 additions and 23 deletions.
62 changes: 39 additions & 23 deletions src/wp-includes/class-wp-block-type.php
Original file line number Diff line number Diff line change
Expand Up @@ -579,29 +579,6 @@ public function set_props( $args ) {
}
}

// Stabilize experimental block supports.
if ( isset( $args['supports'] ) && is_array( $args['supports'] ) ) {
foreach ( $this->stabilized_supports as $feature => $mapping ) {
if ( isset( $args['supports'][ $feature ] ) ) {
if ( is_array( $mapping ) ) {
foreach ( $mapping as $old => $new ) {
if (
isset( $args['supports'][ $feature ][ $old ] ) &&
! isset( $args['supports'][ $feature ][ $new ] )
) {
$args['supports'][ $feature ][ $new ] = $args['supports'][ $feature ][ $old ];
}
}
} elseif (
is_string( $mapping ) &&
! isset( $args['supports'][ $mapping ] )
) {
$args['supports'][ $mapping ] = $args['supports'][ $feature ];
}
}
}
}

/**
* Filters the arguments for registering a block type.
*
Expand All @@ -612,6 +589,11 @@ public function set_props( $args ) {
*/
$args = apply_filters( 'register_block_type_args', $args, $this->name );

// Stabilize experimental block supports.
if ( isset( $args['supports'] ) && is_array( $args['supports'] ) ) {
$args['supports'] = $this->stabilize_supports( $args['supports'] );
}

foreach ( $args as $property_name => $property_value ) {
$this->$property_name = $property_value;
}
Expand Down Expand Up @@ -674,4 +656,38 @@ public function get_uses_context() {
*/
return apply_filters( 'get_block_type_uses_context', $this->uses_context, $this );
}

/**
* Stabilize experimental block supports. This method transforms experimental
* block supports into their stable counterparts, by renaming the keys to the
* stable versions.
*
* @since 6.7.0
*
* @param array $supports The block supports array from within the block type arguments.
* @return array The stabilized block supports array.
*/
private function stabilize_supports( $supports ) {
foreach ( $this->stabilized_supports as $feature => $mapping ) {
if ( isset( $supports[ $feature ] ) ) {
if ( is_array( $mapping ) ) {
foreach ( $mapping as $old => $new ) {
if (
isset( $supports[ $feature ][ $old ] ) &&
! isset( $supports[ $feature ][ $new ] )
) {
$supports[ $feature ][ $new ] = $supports[ $feature ][ $old ];
}
}
} elseif (
is_string( $mapping ) &&
! isset( $supports[ $mapping ] )
) {
$supports[ $mapping ] = $supports[ $feature ];
}
}
}

return $supports;
}
}

0 comments on commit 76ceb8d

Please sign in to comment.