diff --git a/src/wp-includes/class-wp-block-type.php b/src/wp-includes/class-wp-block-type.php index 528a5fb88fc3a..a252894a853e2 100644 --- a/src/wp-includes/class-wp-block-type.php +++ b/src/wp-includes/class-wp-block-type.php @@ -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. * @@ -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; } @@ -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; + } }