Make WordPress Core


Ignore:
Timestamp:
10/18/2018 11:53:49 AM (6 years ago)
Author:
pento
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.

See #45109.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/5.0/src/wp-includes/class-wp-block-parser.php

    r43751 r43752  
    307307                 */
    308308                $stack_top = array_pop( $this->stack );
    309                 $stack_top->block->innerHTML .= substr( $this->document, $stack_top->prev_offset, $start_offset - $stack_top->prev_offset );
     309
     310                $html = substr( $this->document, $stack_top->prev_offset, $start_offset - $stack_top->prev_offset );
     311                if ( $stack_top->block->innerBlocks ) {
     312                    $stack_top->block->innerBlocks[] = (array) $this->freeform( $html );
     313                } else {
     314                    $stack_top->block->innerHTML = $html;
     315                }
     316
    310317                $stack_top->prev_offset = $start_offset + $token_length;
    311318
     
    441448    function add_inner_block( WP_Block_Parser_Block $block, $token_start, $token_length, $last_offset = null ) {
    442449        $parent = $this->stack[ count( $this->stack ) - 1 ];
    443         $parent->block->innerBlocks[] = $block;
    444         $parent->block->innerHTML .= substr( $this->document, $parent->prev_offset, $token_start - $parent->prev_offset );
     450        $parent->block->innerBlocks[] = (array) $this->freeform( substr( $this->document, $parent->prev_offset, $token_start - $parent->prev_offset ) );
     451        $parent->block->innerBlocks[] = (array) $block;
    445452        $parent->prev_offset = $last_offset ? $last_offset : $token_start + $token_length;
    446453    }
     
    457464        $prev_offset = $stack_top->prev_offset;
    458465
    459         $stack_top->block->innerHTML .= isset( $end_offset )
     466        $html = isset( $end_offset )
    460467            ? substr( $this->document, $prev_offset, $end_offset - $prev_offset )
    461468            : substr( $this->document, $prev_offset );
     469
     470        if ( $stack_top->block->innerBlocks ) {
     471            $stack_top->block->innerBlocks[] = (array) $this->freeform( $html );
     472        } else {
     473            $stack_top->block->innerHTML = $html;
     474        }
    462475
    463476        if ( isset( $stack_top->leading_html_start ) ) {
Note: See TracChangeset for help on using the changeset viewer.