This repository has been archived by the owner on Aug 24, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Embeds in new text widget #141
Labels
Comments
Ideally yes, but we cannot currently process embeds in the content due to embeds requiring a post context due to the need to cache in postmeta. If we do support embeds we'd have to limit to those which are handled internally, not any that requiring external requests (and this caching). |
A proof of concept to allow embeds: diff --git a/wp-includes/widgets/class-wp-widget-visual-text.php b/wp-includes/widgets/class-wp-widget-visual-text.php
index 8509aea..077b57a 100644
--- a/wp-includes/widgets/class-wp-widget-visual-text.php
+++ b/wp-includes/widgets/class-wp-widget-visual-text.php
@@ -64,6 +64,22 @@ class WP_Widget_Visual_Text extends WP_Widget_Text {
if ( isset( $instance['filter'] ) ) {
if ( 'content' === $instance['filter'] ) {
+ add_filter( 'embed_oembed_discover', '__return_false', 100 );
+
+ /**
+ * @var WP_Embed $wp_embed
+ */
+ global $wp_embed;
+
+ $using_cache = $wp_embed->usecache;
+ $wp_embed->usecache = false;
+
+ // Hack to get the [embed] shortcode to run before wpautop()
+ add_filter( 'widget_text_content', array( $wp_embed, 'run_shortcode' ), 8 );
+
+ // Attempts to embed all URLs in a post
+ add_filter( 'widget_text_content', array( $wp_embed, 'autoembed' ), 8 );
+
/**
* Filters the content of the Text widget to apply changes expected from the visual (TinyMCE) editor.
*
@@ -75,7 +91,12 @@ class WP_Widget_Visual_Text extends WP_Widget_Text {
* @param array $instance Array of settings for the current widget.
* @param WP_Widget_Text $this Current Text widget instance.
*/
- $text = apply_filters( 'widget_text_content', $widget_text, $instance, $this );
+ $text = apply_filters( 'widget_text_content', $text, $instance, $this );
+
+ remove_filter( 'widget_text_content', array( $wp_embed, 'autoembed' ), 8 );
+ remove_filter( 'widget_text_content', array( $wp_embed, 'run_shortcode' ), 8 );
+ remove_filter( 'embed_oembed_discover', '__return_false', 100 );
+ $wp_embed->usecache = $using_cache;
} elseif ( $instance['filter'] ) {
$text = wpautop( $text ); // Back-compat for instances prior to 4.8. Note that discovery and caching are disabled since postmeta caching cannot be relied upon. If you try the patch you'll immediately notice a couple things:
|
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Should embeds work in new text widget in the same way as in post?
For example youtube link in it's own line would show the video.
The text was updated successfully, but these errors were encountered: