[wp-trac] [WordPress Trac] #40926: the_content filter does not run wp_oembed_get() unless there is a global post
WordPress Trac
noreply at wordpress.org
Mon Jun 5 19:00:20 UTC 2017
#40926: the_content filter does not run wp_oembed_get() unless there is a global
post
--------------------------+-----------------------------
Reporter: GunGeekATX | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Embeds | Version: 4.7.5
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
While working through a custom REST API endpoint, I found that
`the_content` filter does not process oEmbeds unless there is a global
post set. In class WP_Embed, down in the `shortcode()` function, it first
checks for known handlers, then passes it off to `wp_oembed_get()`, but
only first after checking for a cached oEmbed for the current post. If
there is no global post currently set, the oEmbed processing does not
happen.
Theoretically, calling something like this should create the oEmbed HTML
for Matt's State of the World 2016 video.
{{{
$html = apply_filters( 'the_content',
'https://www.youtube.com/watch?v=Nl6U7UotA-M' );
}}}
But if there is no global post set, it just returns it in <p> tags
{{{
<p>https://www.youtube.com/watch?v=Nl6U7UotA-M</p>
}}}
In my case, since I was working with posts, I was able to call
`setup_postdata()` before creating the custom response to get around this.
In cases where there isn't a global post, such as content stored in the
options table, something global for a theme, content fetched from an
external source, etc., it would be handy to still be able to process
oEmbeds.
Not exactly sure the best way to refactor that bit of code would be.
Allowing these to be cached as a transient when there is no global post
would fix the issue, but that could create a lot of outdated rows in the
options table.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/40926>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list