@@ -349,6 +349,11 @@ function twenty_twenty_one_get_non_latin_css( $type = 'front-end' ) {
349349 );
350350}
351351
352+ /**
353+ * Remove the legacy fallback once the theme’s minimum required version is 6.9.0 or greater.
354+ *
355+ * @see ../style.css “Requires at least: VERSION_NUMBER”
356+ */
352357if ( class_exists ( 'WP_Block_Processor ' ) ) :
353358 /**
354359 * Prints the first instance of a block in the content, and then break away.
@@ -371,20 +376,23 @@ function twenty_twenty_one_print_first_instance_of_block( $block_name, $content
371376 $ processor = new WP_Block_Processor ( $ content );
372377 $ instance_count = 0 ;
373378
374- if ( str_ends_with ( $ block_name , '* ' ) ) {
375- // Scan for blocks whose block type matches the prefix.
376- $ prefix = rtrim ( $ block_name , '* ' );
377-
378- while ( $ instance_count < $ instances && $ processor ->next_block () ) {
379- $ matched_block_type = $ processor ->get_printable_block_type ();
380- if ( str_starts_with ( $ matched_block_type , $ prefix ) ) {
381- $ blocks_content .= render_block ( $ processor ->extract_full_block_and_advance () );
382- ++$ instance_count ;
383- }
384- }
385- } else {
386- // Scan for blocks of the exact block type.
387- while ( $ instance_count < $ instances && $ processor ->next_block ( $ block_name ) ) {
379+ // Scan for blocks whose block type matches the prefix.
380+ $ prefix = rtrim ( $ block_name , '* ' );
381+ $ match_fully = $ prefix === $ block_name ;
382+
383+ // Loop over top-level blocks.
384+ while ( $ processor ->next_block () && $ instance_count < $ instances ) {
385+ if (
386+ 1 === $ processor ->get_depth () &&
387+ /*
388+ * Prefix matches with a wildcard require printing the block name,
389+ * while full block-type matching can be delegated to the processor.
390+ * In each case, the condition only holds when the match is successful.
391+ */
392+ $ match_fully
393+ ? $ processor ->is_block_type ( $ block_name )
394+ : str_starts_with ( $ processor ->get_printable_block_type (), $ prefix )
395+ ) {
388396 $ blocks_content .= render_block ( $ processor ->extract_full_block_and_advance () );
389397 ++$ instance_count ;
390398 }
@@ -402,6 +410,9 @@ function twenty_twenty_one_print_first_instance_of_block( $block_name, $content
402410 /**
403411 * Fallback with legacy function for installations running WordPress <6.9.0.
404412 *
413+ * @todo Remove once this theme’s minimum support version is 6.9.0 or greater.
414+ * @see ../style.css “Requires at least: VERSION_NUMBER”
415+ *
405416 * @ignore
406417 * @private
407418 */
0 commit comments