Make WordPress Core

Changeset 62726


Ignore:
Timestamp:
07/14/2026 07:27:27 AM (2 months ago)
Author:
wildworks
Message:

Editor: Add a helper to apply content filters within blocks.

Introduce the private _wp_apply_block_content_filters() function so that blocks rendering full post content, such as Latest Posts, process it through the standard content pipeline with optional recursion protection, instead of outputting raw block markup.

Discussed in: https://github.com/WordPress/wordpress-develop/pull/12421

Props get_dave, wildworks.
See #65586.

File:
1 edited

Legend:

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

    r62707 r62726  
    25692569
    25702570/**
     2571 * Applies standard content filters similar to the 'the_content' filter.
     2572 *
     2573 * This function runs the typical content processing filters that WordPress
     2574 * applies to post content, useful for blocks that render nested content.
     2575 *
     2576 * @since 7.1.0
     2577 * @access private
     2578 *
     2579 * @global WP_Embed $wp_embed WordPress Embed object.
     2580 *
     2581 * @param string      $content  The content to process.
     2582 * @param string      $context  Optional. Context identifier for wp_filter_content_tags().
     2583 *                              Default empty string.
     2584 * @param array|null  $seen_ids Optional. Reference to an array tracking seen IDs for
     2585 *                              recursion prevention. Default null.
     2586 * @param string|null $id       Optional. Unique identifier for this content, used with
     2587 *                              $seen_ids. Default null.
     2588 * @return string The processed content.
     2589 */
     2590function _wp_apply_block_content_filters( $content, $context = '', &$seen_ids = null, $id = null ) {
     2591        $content = shortcode_unautop( $content );
     2592        $content = do_shortcode( $content );
     2593
     2594        if ( null !== $seen_ids && null !== $id ) {
     2595                $seen_ids[ $id ] = true;
     2596        }
     2597
     2598        try {
     2599                $content = do_blocks( $content );
     2600        } finally {
     2601                if ( null !== $seen_ids && null !== $id ) {
     2602                        unset( $seen_ids[ $id ] );
     2603                }
     2604        }
     2605
     2606        $content = wptexturize( $content );
     2607        $content = convert_smilies( $content );
     2608        $content = wp_filter_content_tags( $content, $context );
     2609
     2610        global $wp_embed;
     2611        $content = $wp_embed->autoembed( $content );
     2612
     2613        return $content;
     2614}
     2615
     2616/**
    25712617 * Returns the current version of the block format that the content string is using.
    25722618 *
Note: See TracChangeset for help on using the changeset viewer.