Make WordPress Core


Ignore:
Timestamp:
12/13/2018 06:11:10 PM (6 years ago)
Author:
desrosj
Message:

Blocks: Parse blocks when displaying posts.

Posts containing blocks are now correctly handled when displaying on the front end, including dynamic blocks and nested blocks.

Props pento.

Merges [43752] to trunk.

See #45109.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/wp-includes/class-wp-block-parser.php

    r44117 r44118  
    311311                 * block and add it as a new innerBlock to the parent
    312312                 */
    313                 $stack_top                    = array_pop( $this->stack );
    314                 $stack_top->block->innerHTML .= substr( $this->document, $stack_top->prev_offset, $start_offset - $stack_top->prev_offset );
    315                 $stack_top->prev_offset       = $start_offset + $token_length;
     313                $stack_top = array_pop( $this->stack );
     314
     315                $html = substr( $this->document, $stack_top->prev_offset, $start_offset - $stack_top->prev_offset );
     316                if ( $stack_top->block->innerBlocks ) {
     317                    $stack_top->block->innerBlocks[] = (array) $this->freeform( $html );
     318                } else {
     319                    $stack_top->block->innerHTML = $html;
     320                }
     321
     322                $stack_top->prev_offset = $start_offset + $token_length;
    316323
    317324                $this->add_inner_block(
     
    446453    function add_inner_block( WP_Block_Parser_Block $block, $token_start, $token_length, $last_offset = null ) {
    447454        $parent                       = $this->stack[ count( $this->stack ) - 1 ];
    448         $parent->block->innerBlocks[] = $block;
    449         $parent->block->innerHTML    .= substr( $this->document, $parent->prev_offset, $token_start - $parent->prev_offset );
     455        $parent->block->innerBlocks[] = (array) $this->freeform( substr( $this->document, $parent->prev_offset, $token_start - $parent->prev_offset ) );
     456        $parent->block->innerBlocks[] = (array) $block;
    450457        $parent->prev_offset          = $last_offset ? $last_offset : $token_start + $token_length;
    451458    }
     
    462469        $prev_offset = $stack_top->prev_offset;
    463470
    464         $stack_top->block->innerHTML .= isset( $end_offset )
     471        $html = isset( $end_offset )
    465472            ? substr( $this->document, $prev_offset, $end_offset - $prev_offset )
    466473            : substr( $this->document, $prev_offset );
     474
     475        if ( $stack_top->block->innerBlocks ) {
     476            $stack_top->block->innerBlocks[] = (array) $this->freeform( $html );
     477        } else {
     478            $stack_top->block->innerHTML = $html;
     479        }
    467480
    468481        if ( isset( $stack_top->leading_html_start ) ) {
Note: See TracChangeset for help on using the changeset viewer.