WordPress.org

Make WordPress Core

Opened 3 years ago

Last modified 20 months ago

#37597 reopened defect (bug)

served oEmbed from cache even when expired

Reported by: zabatonni Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.0
Component: Embeds Keywords: needs-patch
Focuses: Cc:
PR Number:

Description

There is wrong condition in wp-includes/class-wp-embed.php
Embeds are pulled from cache even if $cached_recently is false = expired.

This condition:

<?php
if ( $this->usecache || $cached_recently ) {

should be changed to:

<?php
if ( $this->usecache && $cached_recently ) {

Change History (9)

#1 @ocean90
3 years ago

  • Version changed from trunk to 4.0

Introduced in [28972].

#2 follow-up: @helen
3 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

That is the intention - an external HTTP request should not be fired on a pageview, so it will pull from cache ($this->usecache) no matter the age. The expiry is to determine whether to refresh an existing cache only when saving a post. Cached oEmbed responses are only refreshed on post save by default, which was the behavior before 4.0 as well.

#3 @zabatonni
3 years ago

ok, i get it now. It's not bug.

I schedule posts with youtube links (sent by artists) which are private in the time of creating post, but they are published few minutes before post is published (music video premiere, movie trailer, ...).
Seems i will have to create some workaround to rebuild cache on post publishing when previous state was draft or schedule.

Thank you for enlightening me :)

#4 @ocean90
3 years ago

#39524 was marked as a duplicate.

#5 @swissspidy
2 years ago

#41297 was marked as a duplicate.

#6 in reply to: ↑ 2 @QantumThemes
2 years ago

  • Keywords needs-patch added
  • Resolution wontfix deleted
  • Status changed from closed to reopened

Replying to helen:

That is the intention - an external HTTP request should not be fired on a pageview, so it will pull from cache ($this->usecache) no matter the age. The expiry is to determine whether to refresh an existing cache only when saving a post. Cached oEmbed responses are only refreshed on post save by default, which was the behavior before 4.0 as well.

Hello everybody!
I perfectly understand the intent of the code, but as matter of fact the oEmbed code is NOT refreshed on page save.

For example, if you embed a YouTube video with some parameters (playlist for example) and Wp generates the oembed meta fields, then you edit the URL, also switch to code and to visual editor to try to refresh the oEmbeds, and then save, the parameters won't still be refreshed.

In the same way, if you embed a video, normal way (putting the URL) and than remove that video and put another, even after saving, the oEmbed hidden fields will still contain the old video parameters, id, url, html embed code and so on.

The only way to edit a previously created post with oembed fields, is to copy the content except the video URL, create a new post, and add the new video, then delete the old one.

As you may understand, this is NOT normal, and the problem persist since years (and about 6 themes developed plus other 50+ websites created for private customers).

For an average user, it is much more usual to copy-paste the wrong video or some useless/unwanted parameters, than to post a "hidden premiere of a hollywood movie" and "schedule a post for the big premiere" which may probably represent the 0.00001 of worldwide users.

At the actual point, no method is provided to manually refresh metas, they don't refresh alone, no fix is provided, and the system is clearly not working as it should.

You can notice that is true because there are lots of people with the same problem online, and the only working solution found till now is to manually regenerate metas.

But this implies handling manually the WP globals, which should not be done by a theme or customer just to have embed working correctly (https://wordpress.stackexchange.com/questions/203537/how-can-i-clear-oembed-caches-for-youtube-on-posts-as-they-are-loaded).

So it would be cool if Helen or anything else would take care of providing a real fix for this (and testing it before publishing and saying it's fixed).

Thanks!

#7 @westonruter
2 years ago

This just came up in the context of #34115, when using a oembed_cache custom post type for caching oEmbed responses for requests made outside the context of a post (such as in a widget).

Discussion: https://github.com/xwp/wordpress-develop/pull/254#issuecomment-330510134

#8 @QantumThemes
2 years ago

Hello @westonruter and thanks for the answer, I understand what you mean, still this represents a wrong behavior as the cache should be refreshed when the content changes and the original "oEmbedded" content is not there anymore.

If this was normal, would mean that accessing to the same data in different ways could provide different results, leaking in consistency.

I don't understand why WP can't simply re-parse the content on save to check if the oembed cache needs refreshing.

Making this operation manually IS possible, but is not what a theme or plugin should do.

What people expects is that you change the data and the content changes. As technicians we can explain whatever tech reason we want, but still is not the correct thing that should happen...
Well, I hope someone will fix it soon.
Thanks!

#9 @SergeyBiryukov
20 months ago

  • Milestone set to Awaiting Review
Note: See TracTickets for help on using tickets.