Ticket #14759: 14759.2.diff
File 14759.2.diff, 2.9 KB (added by , 9 years ago) |
---|
-
wp-admin/includes/ajax-actions.php
function wp_ajax_imgedit_preview() { 208 208 * @since 3.1.0 209 209 */ 210 210 function wp_ajax_oembed_cache() { 211 global $wp_embed; 212 213 $return = ( $wp_embed->cache_oembed( $_GET['post'] ) ) ? '1' : '0'; 214 wp_die( $return ); 211 $GLOBALS['wp_embed']->cache_oembed( $_GET['post'] ); 212 wp_die( 0 ); 215 213 } 216 214 217 215 /** -
wp-includes/class-wp-embed.php
class WP_Embed { 25 25 // Attempts to embed all URLs in a post 26 26 add_filter( 'the_content', array( $this, 'autoembed' ), 8 ); 27 27 28 // When a post is saved, invalidate the oEmbed cache29 add_action( 'pre_post_update', array( $this, 'delete_oembed_caches' ) );30 31 28 // After a post is saved, cache oEmbed items via AJAX 32 29 add_action( 'edit_form_advanced', array( $this, 'maybe_run_ajax_cache' ) ); 33 30 } … … class WP_Embed { 186 183 if ( $post_ID ) { 187 184 188 185 // Check for a cached result (stored in the post meta) 189 $cachekey = '_oembed_' . md5( $url . serialize( $attr ) ); 190 if ( $this->usecache ) { 191 $cache = get_post_meta( $post_ID, $cachekey, true ); 192 193 // Failures are cached 186 $key_suffix = md5( $url . serialize( $attr ) ); 187 $cachekey = '_oembed_' . $key_suffix; 188 $cachekey_time = '_oembed_time_' . $key_suffix; 189 $ttl = apply_filters( 'oembed_ttl', DAY_IN_SECONDS, $url, $attr, $post_ID ); 190 $cache = get_post_meta( $post_ID, $cachekey, true ); 191 $cache_time = get_post_meta( $post_ID, $cachekey_time, true ); 192 if ( ! $cache_time ) { 193 $cache_time = 0; 194 } 195 $cached_recently = ( time() - $cache_time ) < $ttl; 196 if ( $this->usecache || $cached_recently ) { 197 // Failures are cached. Serve one if we're using the cache. 194 198 if ( '{{unknown}}' === $cache ) 195 199 return $this->maybe_make_link( $url ); 196 200 197 if ( ! empty( $cache ) ) 201 if ( ! empty( $cache ) ) { 198 202 /** 199 203 * Filter the cached oEmbed HTML. 200 204 * … … class WP_Embed { 208 212 * @param int $post_ID Post ID. 209 213 */ 210 214 return apply_filters( 'embed_oembed_html', $cache, $url, $attr, $post_ID ); 215 } 211 216 } 212 217 213 218 /** … … class WP_Embed { 224 229 // Use oEmbed to get the HTML 225 230 $html = wp_oembed_get( $url, $attr ); 226 231 227 // Cache the result 228 $cache = ( $html ) ? $html : '{{unknown}}'; 229 update_post_meta( $post_ID, $cachekey, $cache ); 232 // Maybe cache the result 233 if ( $html ) { 234 update_post_meta( $post_ID, $cachekey, $html ); 235 update_post_meta( $post_ID, $cachekey_time, time() ); 236 } elseif ( ! $cache ) { 237 update_post_meta( $post_ID, $cachekey, '{{unknown}}' ); 238 } 230 239 231 240 // If there was a result, return it 232 241 if ( $html ) {