WordPress.org

Make WordPress Core

Opened 6 weeks ago

Last modified 6 weeks ago

#42825 new defect (bug)

[embed] shortcode - oembed_cache not being updated when $cached_recently is false

Reported by: bobbingwide Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: trunk
Component: Embeds Keywords:
Focuses: Cc:

Description

For my plugin ( oik ) I developed a Shortcode help facility that shows examples of my shortcodes, syntax etc. It also shows examples of the WordPress core shortcodes.
For [embed] it uses a YouTube URL
[embed width="480" src=https://www.youtube.com/watch?v=nH228-XQ-A8]

During PHPUnit testing in multiple environments I found I was getting different results. In one environment the content of oembed_cache was

<iframe width="480" height="360" 
src="https://www.youtube.com/embed/nH228-XQ-A8?feature=oembed" 
frameborder="0" gesture="media" allowfullscreen>
</iframe>

In other environments I was getting a different result.

<iframe width="480" height="360" 
src="https://www.youtube.com/embed/nH228-XQ-A8?feature=oembed" 
frameborder="0" gesture="media" allow="encrypted-media" allowfullscreen>
</iframe>

Note: The shortcode expansion is being performed in wp-admin with no global post.

Trace analysis of the shortcode method in shortcodes/class-wp-embed.php indicates
that the $cached_post_id is being set by find_oembed_post_id, which means that $cache is set to the content. But the post_modified_gmt of the first example is 25th November; so $cached_recently is false.

Since $this->usecache is initially set to true then the $cached_recently logic is ignored and the route taken is to apply the first 'embed_oembed_html' filter then return.

The subsequent updating doesn't kick in.

Partial fix

It doesn't look at all logical but setting $this->usecache=false before the return of $oembed_post_id in find_oembed_post_id partially resolves the problem.

However, since there's no further checking of $cached_recently, this happens every single time. Obviously, more work is needed to update out of date cached items.

This is a follow on to #34115

Change History (2)

#1 @bobbingwide
6 weeks ago

Realised the fix is a lot easier.
Change:

if ( $this->usecache || $cached_recently ) {

to

if ( $this->usecache && $cached_recently ) {

#2 @birgire
6 weeks ago

Related #37597

Looks like that ticket is about the same thing (duplicate?)

ps: I remember hacking something about this here ;-)

Last edited 6 weeks ago by birgire (previous) (diff)
Note: See TracTickets for help on using tickets.