Make WordPress Core


Ignore:
Timestamp:
02/01/2021 06:04:36 PM (4 years ago)
Author:
SergeyBiryukov
Message:

Editor: Introduce a dynamic filter for the content of a single block:

render_block_{$this->name}

This complements the existing render_block hook and allows for filtering the content of a specific block without having to use conditionals inside the filter callback.

Props manzoorwani.jk, noisysocks, birgire, johnbillion.
Fixes #46187.

File:
1 edited

Legend:

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

    r49695 r50123  
    242242         * @param array  $block         The full block, including name and attributes.
    243243         */
    244         return apply_filters( 'render_block', $block_content, $this->parsed_block );
     244        $block_content = apply_filters( 'render_block', $block_content, $this->parsed_block );
     245
     246        /**
     247         * Filters the content of a single block.
     248         *
     249         * The dynamic portion of the hook name, `$name`, refers to
     250         * the block name, e.g. "core/paragraph".
     251         *
     252         * @since 5.7.0
     253         *
     254         * @param string $block_content The block content about to be appended.
     255         * @param array  $block         The full block, including name and attributes.
     256         */
     257        $block_content = apply_filters( "render_block_{$this->name}", $block_content, $this->parsed_block );
     258
     259        return $block_content;
    245260    }
    246261
Note: See TracChangeset for help on using the changeset viewer.