Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/wp-includes/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -2648,6 +2648,9 @@ function _restore_wpautop_hook( $content ) {
* @return string The processed content.
*/
function _wp_apply_block_content_filters( $content, $context = '', &$seen_ids = null, $id = null ) {
global $wp_embed;
$content = $wp_embed->autoembed( $content );

$content = shortcode_unautop( $content );
$content = do_shortcode( $content );

Expand All @@ -2667,9 +2670,6 @@ function _wp_apply_block_content_filters( $content, $context = '', &$seen_ids =
$content = convert_smilies( $content );
$content = wp_filter_content_tags( $content, $context );

global $wp_embed;
$content = $wp_embed->autoembed( $content );

return $content;
}

Expand Down
40 changes: 40 additions & 0 deletions tests/phpunit/tests/blocks/wpApplyBlockContentFilters.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,46 @@ static function () {
);
}

/**
* Tests that autoembed runs before do_blocks() so that URLs which only appear
* in a block's rendered output are not turned into embeds.
*
* @ticket 66077
*/
public function test_autoembed_runs_before_do_blocks() {
wp_embed_register_handler(
self::TEST_EMBED_HANDLER,
'#https?://example\.com/apply-block-content-filters#i',
array( $this, 'render_test_embed' )
);

unregister_block_type( self::TEST_BLOCK_NAME );
register_block_type(
self::TEST_BLOCK_NAME,
array(
'render_callback' => static function () {
return "\n\nhttps://example.com/apply-block-content-filters\n\n";
},
)
);

$output = _wp_apply_block_content_filters(
'<!-- wp:tests/apply-block-content-filters /-->',
'test-context'
);

$this->assertStringNotContainsString(
'<div class="apply-block-content-filters-embed">Embedded content</div>',
$output,
'WP_Embed::autoembed() should not process URLs that only appear in a block\'s rendered output.'
);
$this->assertStringContainsString(
'https://example.com/apply-block-content-filters',
$output,
'A URL in a block\'s rendered output should be left as-is.'
);
}

/**
* Tests that seen IDs are set during block rendering and cleared afterward.
*
Expand Down
Loading