[wp-trac] [WordPress Trac] #45312: parse_blocks return non-existing empty blocks

WordPress Trac noreply at wordpress.org
Fri Apr 19 20:00:02 UTC 2019

#45312: parse_blocks return non-existing empty blocks
 Reporter:  Chouby        |       Owner:  (none)
     Type:  defect (bug)  |      Status:  reopened
 Priority:  normal        |   Milestone:
Component:  Editor        |     Version:  5.0
 Severity:  normal        |  Resolution:
 Keywords:                |     Focuses:

Comment (by leec87):

 Sure, I can show what I'm trying to do, maybe you might be able to give me
 a better idea of doing it.

 You could take a look at https://staging.bandbubble.com/features/, which
 shows you the blocks I'm talking about.

 $blocks = parse_blocks($post->post_content);
 $count = 0;
 foreach($blocks as $feature) { ?>
   <div class="py-5 text-center">
     <div class="container">
       <div class="row align-items-center">
         <div class="col-12 col-md-3 offset-md-1 offset-lg-2 <?php echo
 (++$count%2 ? '' : 'order-md-2'); ?>">
           <?php echo $feature['innerHTML']; ?>
         <div class="col-12 col-md-7 col-lg-5 <?php echo (++$count%2 ? '' :
 'order-md-1'); ?>">
             <?php echo $feature['innerBlocks'][0]['innerContent'][0]; ?>
           <?php echo
 wpautop($feature['innerBlocks'][1]['innerContent'][0]); ?>
 <?php } ?>

 So essentially, a simple if/else statement if the current count is
 divisible by 2, to echo a Bootstrap class that changes the order. The
 effect I'm going for here, is to swap the order of the image and text
 around (in a media/text block).

 This should work fine, if the empty blocks weren't returned by
 parse_blocks() (If I add the CSS class to one of the regular blocks, it
 appears fine, so this should work).

 This should be a nice, simple way to bridge a gap between Wordpress
 blocks, and Bootstrap markup / styling, which is what I'm trying to
 achieve. I could easily hard code this in the page template file, but I
 like being able to edit content in Wordpress.

Ticket URL: <https://core.trac.wordpress.org/ticket/45312#comment:9>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform

More information about the wp-trac mailing list