Make WordPress Core


Ignore:
Timestamp:
06/22/2026 09:37:59 AM (2 months ago)
Author:
wildworks
Message:

Excerpt: Honor the block visibility metadata in generated excerpts.

When an excerpt is auto-generated, the metadata.blockVisibility attribute was ignored, so blocks marked as hidden still leaked their text into the excerpt even though they are not rendered on the front end.

Skip any block whose metadata.blockVisibility attribute is boolean false, for both top-level blocks and inner blocks.

Props n8finch, ramonopoly, wildworks.
Fixes #65456.

File:
1 edited

Legend:

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

    r62359 r62539  
    22392239
    22402240        foreach ( $blocks as $block ) {
     2241                // Hide the block whenever the value is boolean false, regardless of the
     2242                // block's current visibility support. This prevents blocks that previously
     2243                // supported visibility from unintentionally appearing on the front end
     2244                // after their support was disabled.
     2245                if ( false === ( $block['attrs']['metadata']['blockVisibility'] ?? null ) ) {
     2246                        continue;
     2247                }
     2248
    22412249                if ( in_array( $block['blockName'], $allowed_blocks, true ) ) {
    22422250                        if ( ! empty( $block['innerBlocks'] ) ) {
     
    23002308
    23012309        foreach ( $parsed_block['innerBlocks'] as $inner_block ) {
     2310                // Hide the block whenever the value is boolean false, regardless of the
     2311                // block's current visibility support. This prevents blocks that previously
     2312                // supported visibility from unintentionally appearing on the front end
     2313                // after their support was disabled.
     2314                if ( false === ( $inner_block['attrs']['metadata']['blockVisibility'] ?? null ) ) {
     2315                        continue;
     2316                }
     2317
    23022318                if ( ! in_array( $inner_block['blockName'], $allowed_blocks, true ) ) {
    23032319                        continue;
Note: See TracChangeset for help on using the changeset viewer.