From 38cea1e6591343a2ab19bb14ba68ca9467fe644a Mon Sep 17 00:00:00 2001 From: noisysocks Date: Wed, 2 Jun 2021 01:18:57 +0000 Subject: [PATCH] Widget block: Add `widget_block_content` filter Adds a new 'widget_block_content' filter to the widget block and hooks `run_shortcode`, `autoembed`, `do_blocks`, and `do_shortcode` into it by default. This is simlar to `widget_text_content.` Fixes #51566. Props talldanwp. Built from https://develop.svn.wordpress.org/trunk@51058 git-svn-id: http://core.svn.wordpress.org/trunk@50667 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-wp-embed.php | 2 ++ wp-includes/default-filters.php | 3 ++ wp-includes/version.php | 2 +- wp-includes/widgets/class-wp-widget-block.php | 29 ++++++++++--------- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/wp-includes/class-wp-embed.php b/wp-includes/class-wp-embed.php index aff25412c3..4b189f9334 100644 --- a/wp-includes/class-wp-embed.php +++ b/wp-includes/class-wp-embed.php @@ -31,6 +31,7 @@ class WP_Embed { // Hack to get the [embed] shortcode to run before wpautop(). add_filter( 'the_content', array( $this, 'run_shortcode' ), 8 ); add_filter( 'widget_text_content', array( $this, 'run_shortcode' ), 8 ); + add_filter( 'widget_block_content', array( $this, 'run_shortcode' ), 8 ); // Shortcode placeholder for strip_shortcodes(). add_shortcode( 'embed', '__return_false' ); @@ -38,6 +39,7 @@ class WP_Embed { // Attempts to embed all URLs in a post. add_filter( 'the_content', array( $this, 'autoembed' ), 8 ); add_filter( 'widget_text_content', array( $this, 'autoembed' ), 8 ); + add_filter( 'widget_block_content', array( $this, 'autoembed' ), 8 ); // After a post is saved, cache oEmbed items via Ajax. add_action( 'edit_form_advanced', array( $this, 'maybe_run_ajax_cache' ) ); diff --git a/wp-includes/default-filters.php b/wp-includes/default-filters.php index d2a89ed4d1..8663196248 100644 --- a/wp-includes/default-filters.php +++ b/wp-includes/default-filters.php @@ -214,6 +214,9 @@ add_filter( 'widget_text_content', 'wp_filter_content_tags' ); add_filter( 'widget_text_content', 'wp_replace_insecure_home_url' ); add_filter( 'widget_text_content', 'do_shortcode', 11 ); // Runs after wpautop(); note that $post global will be null when shortcodes run. +add_filter( 'widget_block_content', 'do_blocks', 9 ); +add_filter( 'widget_block_content', 'do_shortcode', 11 ); + add_filter( 'wp_get_custom_css', 'wp_replace_insecure_home_url' ); // RSS filters. diff --git a/wp-includes/version.php b/wp-includes/version.php index f8a29a00c5..a926708118 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.8-alpha-51057'; +$wp_version = '5.8-alpha-51058'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. diff --git a/wp-includes/widgets/class-wp-widget-block.php b/wp-includes/widgets/class-wp-widget-block.php index 4c5abb38a4..b191bfaf31 100644 --- a/wp-includes/widgets/class-wp-widget-block.php +++ b/wp-includes/widgets/class-wp-widget-block.php @@ -66,20 +66,21 @@ class WP_Widget_Block extends WP_Widget { $args['before_widget'] ); - // Handle embeds for block widgets. - // - // When this feature is added to core it may need to be implemented - // differently. WP_Widget_Text is a good reference, that applies a - // filter for its content, which WP_Embed uses in its constructor. - // See https://core.trac.wordpress.org/ticket/51566. - global $wp_embed; - $content = $wp_embed->run_shortcode( $instance['content'] ); - $content = $wp_embed->autoembed( $content ); - - $content = do_blocks( $content ); - $content = do_shortcode( $content ); - - echo $content; + /** + * Filters the content of the Block widget before output. + * + * @since 5.8.0 + * + * @param string $content The widget content. + * @param array $instance Array of settings for the current widget. + * @param WP_Widget_Text $widget Current Block widget instance. + */ + echo apply_filters( + 'widget_block_content', + $instance['content'], + $instance, + $this + ); echo $args['after_widget']; }