@@ -367,26 +367,25 @@ function twenty_twenty_one_print_first_instance_of_block( $block_name, $content
367367 $ content = get_the_content ();
368368 }
369369
370- $ processor = WP_Block_Processor::create ( $ content );
371- $ visit_freeform = in_array ( $ block_name , array ( 'freeform ' , 'core/freeform ' , 'core/* ' ), true );
372- $ freeform_flag = $ visit_freeform ? 'visit-html ' : 'skip-html ' ;
370+ $ processor = new WP_Block_Processor ( $ content );
373371 $ instance_count = 0 ;
374372
375373 if ( str_ends_with ( $ block_name , '* ' ) ) {
376374 // Scan for blocks whose block type matches the prefix.
377375 $ prefix = rtrim ( $ block_name , '* ' );
378376
379- while ( $ instance_count < $ instances && $ processor ->next_delimiter ( $ freeform_flag ) ) {
380- if ( str_starts_with ( $ processor ->get_block_type (), $ prefix ) ) {
377+ while ( $ instance_count < $ instances && $ processor ->next_block ( '* ' ) ) {
378+ $ matched_block_type = $ processor ->get_printable_block_type ();
379+ if ( str_starts_with ( $ matched_block_type , $ prefix ) ) {
381380 $ blocks_content .= render_block ( $ processor ->extract_block () );
381+ ++$ instance_count ;
382382 }
383383 }
384384 } else {
385385 // Scan for blocks of the exact block type.
386- while ( $ instance_count < $ instances && $ processor ->next_delimiter ( $ freeform_flag ) ) {
387- if ( $ processor ->is_block_type ( $ block_name ) ) {
388- $ blocks_content .= render_block ( $ processor ->extract_block () );
389- }
386+ while ( $ instance_count < $ instances && $ processor ->next_block ( $ block_name ) ) {
387+ $ blocks_content .= render_block ( $ processor ->extract_block () );
388+ ++$ instance_count ;
390389 }
391390 }
392391
0 commit comments