Changeset 57246 for trunk/src/wp-includes/block-supports/layout.php
- Timestamp:
- 01/08/2024 06:12:00 AM (9 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/block-supports/layout.php
r57077 r57246 639 639 */ 640 640 $container_class = wp_unique_prefixed_id( 641 'wp-container-' . sanitize_title( $block['blockName'] ) . '- layout-'641 'wp-container-' . sanitize_title( $block['blockName'] ) . '-is-layout-' 642 642 ); 643 643 … … 884 884 } 885 885 886 $replace_regex = sprintf( 886 /* 887 * This filter runs after the layout classnames have been added to the block, so they 888 * have to be removed from the outer wrapper and then added to the inner. 889 */ 890 $layout_classes = array(); 891 $processor = new WP_HTML_Tag_Processor( $block_content ); 892 893 if ( $processor->next_tag( array( 'class_name' => 'wp-block-group' ) ) ) { 894 foreach ( $processor->class_list() as $class_name ) { 895 if ( str_contains( $class_name, 'is-layout-' ) ) { 896 $layout_classes[] = $class_name; 897 $processor->remove_class( $class_name ); 898 } 899 } 900 } 901 902 $content_without_layout_classes = $processor->get_updated_html(); 903 $replace_regex = sprintf( 887 904 '/(^\s*<%1$s\b[^>]*wp-block-group[^>]*>)(.*)(<\/%1$s>\s*$)/ms', 888 905 preg_quote( $tag_name, '/' ) 889 906 ); 890 $updated_content = preg_replace_callback(907 $updated_content = preg_replace_callback( 891 908 $replace_regex, 892 909 static function ( $matches ) { 893 910 return $matches[1] . '<div class="wp-block-group__inner-container">' . $matches[2] . '</div>' . $matches[3]; 894 911 }, 895 $ block_content912 $content_without_layout_classes 896 913 ); 914 915 // Add layout classes to inner wrapper. 916 if ( ! empty( $layout_classes ) ) { 917 $processor = new WP_HTML_Tag_Processor( $updated_content ); 918 if ( $processor->next_tag( array( 'class_name' => 'wp-block-group__inner-container' ) ) ) { 919 foreach ( $layout_classes as $class_name ) { 920 $processor->add_class( $class_name ); 921 } 922 } 923 $updated_content = $processor->get_updated_html(); 924 } 897 925 return $updated_content; 898 926 }
Note: See TracChangeset
for help on using the changeset viewer.