Skip to content

Commit cf60c45

Browse files
committed
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. git-svn-id: https://develop.svn.wordpress.org/trunk@51058 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 9991a80 commit cf60c45

File tree

3 files changed

+20
-14
lines changed

3 files changed

+20
-14
lines changed

src/wp-includes/class-wp-embed.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,15 @@ public function __construct() {
3131
// Hack to get the [embed] shortcode to run before wpautop().
3232
add_filter( 'the_content', array( $this, 'run_shortcode' ), 8 );
3333
add_filter( 'widget_text_content', array( $this, 'run_shortcode' ), 8 );
34+
add_filter( 'widget_block_content', array( $this, 'run_shortcode' ), 8 );
3435

3536
// Shortcode placeholder for strip_shortcodes().
3637
add_shortcode( 'embed', '__return_false' );
3738

3839
// Attempts to embed all URLs in a post.
3940
add_filter( 'the_content', array( $this, 'autoembed' ), 8 );
4041
add_filter( 'widget_text_content', array( $this, 'autoembed' ), 8 );
42+
add_filter( 'widget_block_content', array( $this, 'autoembed' ), 8 );
4143

4244
// After a post is saved, cache oEmbed items via Ajax.
4345
add_action( 'edit_form_advanced', array( $this, 'maybe_run_ajax_cache' ) );

src/wp-includes/default-filters.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,9 @@
214214
add_filter( 'widget_text_content', 'wp_replace_insecure_home_url' );
215215
add_filter( 'widget_text_content', 'do_shortcode', 11 ); // Runs after wpautop(); note that $post global will be null when shortcodes run.
216216

217+
add_filter( 'widget_block_content', 'do_blocks', 9 );
218+
add_filter( 'widget_block_content', 'do_shortcode', 11 );
219+
217220
add_filter( 'wp_get_custom_css', 'wp_replace_insecure_home_url' );
218221

219222
// RSS filters.

src/wp-includes/widgets/class-wp-widget-block.php

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -66,20 +66,21 @@ public function widget( $args, $instance ) {
6666
$args['before_widget']
6767
);
6868

69-
// Handle embeds for block widgets.
70-
//
71-
// When this feature is added to core it may need to be implemented
72-
// differently. WP_Widget_Text is a good reference, that applies a
73-
// filter for its content, which WP_Embed uses in its constructor.
74-
// See https://core.trac.wordpress.org/ticket/51566.
75-
global $wp_embed;
76-
$content = $wp_embed->run_shortcode( $instance['content'] );
77-
$content = $wp_embed->autoembed( $content );
78-
79-
$content = do_blocks( $content );
80-
$content = do_shortcode( $content );
81-
82-
echo $content;
69+
/**
70+
* Filters the content of the Block widget before output.
71+
*
72+
* @since 5.8.0
73+
*
74+
* @param string $content The widget content.
75+
* @param array $instance Array of settings for the current widget.
76+
* @param WP_Widget_Text $widget Current Block widget instance.
77+
*/
78+
echo apply_filters(
79+
'widget_block_content',
80+
$instance['content'],
81+
$instance,
82+
$this
83+
);
8384

8485
echo $args['after_widget'];
8586
}

0 commit comments

Comments
 (0)