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
This commit is contained in:
parent
918610fb88
commit
38cea1e659
|
@ -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' ) );
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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'];
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue