Embeds: Improve consistency of update and refresh logic for oEmbed caching between oembed_cache and post meta.

* Allow updating oEmbed cache during `parse-embed` requests for non-post editors (such as widgets).
* Update any existing `oembed_cache` post when `usecache` and TTL has passed.
* Do not overwrite a previously valid cache with `{{unknown}}`.

Props dlh.
See #34115.
Fixes #42310.


git-svn-id: https://develop.svn.wordpress.org/trunk@42009 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Weston Ruter
2017-10-24 23:09:43 +00:00
parent 8d56eff073
commit 18a231bad6
3 changed files with 71 additions and 6 deletions
+28 -6
View File
@@ -284,12 +284,34 @@ class WP_Embed {
kses_remove_filters();
}
wp_insert_post( wp_slash( array(
'post_name' => $key_suffix,
'post_content' => $html ? $html : '{{unknown}}',
'post_status' => 'publish',
'post_type' => 'oembed_cache',
) ) );
$insert_post_args = array(
'post_name' => $key_suffix,
'post_status' => 'publish',
'post_type' => 'oembed_cache',
);
if ( $html ) {
if ( $cached_post_id ) {
wp_update_post( wp_slash( array(
'ID' => $cached_post_id,
'post_content' => $html,
) ) );
} else {
wp_insert_post( wp_slash( array_merge(
$insert_post_args,
array(
'post_content' => $html,
)
) ) );
}
} elseif ( ! $cache ) {
wp_insert_post( wp_slash( array_merge(
$insert_post_args,
array(
'post_content' => '{{unknown}}',
)
) ) );
}
if ( $has_kses ) {
kses_init_filters();