Make WordPress Core

Changeset 44553


Ignore:
Timestamp:
01/10/2019 11:15:49 PM (8 years ago)
Author:
pento
Message:

Blocks: Add the pre_render_block and render_block_data filters.

At the start of render_block(), the pre_render_block filter allows the function to be short-circuited, and the render_block_data filter is applied to the $block parameter before it's processed.

Props kkarpieszuk, pento.
Fixes #45451.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/blocks.php

    r44431 r44553  
    176176        global $post;
    177177
     178        /**
     179         * Allows render_block() to be shortcircuited, by returning a non-null value.
     180         *
     181         * @since 5.1.0
     182         *
     183         * @param string $pre_render The pre-rendered content. Default null.
     184         * @param array  $block      The block being rendered.
     185         */
     186        $pre_render = apply_filters( 'pre_render_block', null, $block );
     187        if ( is_null( $pre_render ) ) {
     188                return $pre_render;
     189        }
     190
     191        /**
     192         * Filters the block being rendered in render_block(), before it's processed.
     193         *
     194         * @since 5.1.0
     195         *
     196         * @param array $block The block being rendered.
     197         */
     198        $block = apply_filters( 'render_block_data', $block );
     199
    178200        $block_type    = WP_Block_Type_Registry::get_instance()->get_registered( $block['blockName'] );
    179201        $is_dynamic    = $block['blockName'] && null !== $block_type && $block_type->is_dynamic();
Note: See TracChangeset for help on using the changeset viewer.