[wp-trac] [WordPress Trac] #42825: [embed] shortcode - oembed_cache not being updated when $cached_recently is false

WordPress Trac noreply at wordpress.org
Thu Dec 7 12:32:05 UTC 2017


#42825: [embed] shortcode  - oembed_cache not being updated when $cached_recently
is false
--------------------------+-----------------------------
 Reporter:  bobbingwide   |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Embeds        |    Version:  trunk
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 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

--
Ticket URL: <https://core.trac.wordpress.org/ticket/42825>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list