Changeset 45265
- Timestamp:
- 04/24/2019 09:38:21 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/blocks.php
r45159 r45265 126 126 */ 127 127 function excerpt_remove_blocks( $content ) { 128 $allowed_ blocks = array(128 $allowed_inner_blocks = array( 129 129 // Classic blocks have their blockName set to null. 130 130 null, 131 'core/columns',132 131 'core/freeform', 133 132 'core/heading', … … 142 141 'core/verse', 143 142 ); 143 144 $allowed_blocks = array_merge( $allowed_inner_blocks, array( 'core/columns' ) ); 145 144 146 /** 145 147 * Filters the list of blocks that can contribute to the excerpt. … … 155 157 $blocks = parse_blocks( $content ); 156 158 $output = ''; 159 157 160 foreach ( $blocks as $block ) { 158 161 if ( in_array( $block['blockName'], $allowed_blocks, true ) ) { 162 if ( ! empty( $block['innerBlocks'] ) ) { 163 if ( 'core/columns' === $block['blockName'] ) { 164 $output .= _excerpt_render_inner_columns_blocks( $block, $allowed_inner_blocks ); 165 continue; 166 } 167 168 // Skip the block if it has disallowed or nested inner blocks. 169 foreach ( $block['innerBlocks'] as $inner_block ) { 170 if ( 171 ! in_array( $inner_block['blockName'], $allowed_inner_blocks, true ) || 172 ! empty( $inner_block['innerBlocks'] ) 173 ) { 174 continue 2; 175 } 176 } 177 } 178 159 179 $output .= render_block( $block ); 160 180 } 161 181 } 162 return $output; 182 183 return $output; 184 } 185 186 /** 187 * Render inner blocks from the `core/columns` block for generating an excerpt. 188 * 189 * @since 5.2.0 190 * @access private 191 * 192 * @param array $columns The parsed columns block. 193 * @param array $allowed_blocks The list of allowed inner blocks. 194 * @return string The rendered inner blocks. 195 */ 196 function _excerpt_render_inner_columns_blocks( $columns, $allowed_blocks ) { 197 $output = ''; 198 199 foreach ( $columns['innerBlocks'] as $column ) { 200 foreach ( $column['innerBlocks'] as $inner_block ) { 201 if ( in_array( $inner_block['blockName'], $allowed_blocks, true ) && empty( $inner_block['innerBlocks'] ) ) { 202 $output .= render_block( $inner_block ); 203 } 204 } 205 } 206 207 return $output; 163 208 } 164 209
Note: See TracChangeset
for help on using the changeset viewer.