Changeset 28972
- Timestamp:
- 07/03/2014 04:44:15 PM (10 years ago)
- Location:
- trunk/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/ajax-actions.php
r28919 r28972 226 226 */ 227 227 function wp_ajax_oembed_cache() { 228 global $wp_embed; 229 230 $return = ( $wp_embed->cache_oembed( $_GET['post'] ) ) ? '1' : '0'; 231 wp_die( $return ); 228 $GLOBALS['wp_embed']->cache_oembed( $_GET['post'] ); 229 wp_die( 0 ); 232 230 } 233 231 -
trunk/src/wp-includes/class-wp-embed.php
r28923 r28972 32 32 add_filter( 'the_content', array( $this, 'autoembed' ), 8 ); 33 33 34 // When a post is saved, invalidate the oEmbed cache35 add_action( 'pre_post_update', array( $this, 'delete_oembed_caches' ) );36 37 34 // After a post is saved, cache oEmbed items via AJAX 38 35 add_action( 'edit_form_advanced', array( $this, 'maybe_run_ajax_cache' ) ); … … 79 76 $post = get_post(); 80 77 81 if ( ! $post || empty( $_GET['message']) || 1 != $_GET['message'])78 if ( ! $post || empty( $_GET['message'] ) ) 82 79 return; 83 80 … … 193 190 194 191 // Check for a cached result (stored in the post meta) 195 $cachekey = '_oembed_' . md5( $url . serialize( $attr ) ); 196 if ( $this->usecache ) { 197 $cache = get_post_meta( $post_ID, $cachekey, true ); 198 199 // Failures are cached 192 $key_suffix = md5( $url . serialize( $attr ) ); 193 $cachekey = '_oembed_' . $key_suffix; 194 $cachekey_time = '_oembed_time_' . $key_suffix; 195 196 /** 197 * Filter the oEmbed TTL (time to live). 198 * 199 * @since 4.0.0 200 * 201 * @param string $url The attempted embed URL. 202 * @param array $attr An array of shortcode attributes. 203 * @param int $post_ID Post ID. 204 */ 205 $ttl = apply_filters( 'oembed_ttl', DAY_IN_SECONDS, $url, $attr, $post_ID ); 206 207 $cache = get_post_meta( $post_ID, $cachekey, true ); 208 $cache_time = get_post_meta( $post_ID, $cachekey_time, true ); 209 210 if ( ! $cache_time ) { 211 $cache_time = 0; 212 } 213 214 $cached_recently = ( time() - $cache_time ) < $ttl; 215 216 if ( $this->usecache || $cached_recently ) { 217 // Failures are cached. Serve one if we're using the cache. 200 218 if ( '{{unknown}}' === $cache ) 201 219 return $this->maybe_make_link( $url ); 202 220 203 if ( ! empty( $cache ) ) 221 if ( ! empty( $cache ) ) { 204 222 /** 205 223 * Filter the cached oEmbed HTML. … … 215 233 */ 216 234 return apply_filters( 'embed_oembed_html', $cache, $url, $attr, $post_ID ); 235 } 217 236 } 218 237 … … 231 250 $html = wp_oembed_get( $url, $attr ); 232 251 233 // Cache the result 234 $cache = ( $html ) ? $html : '{{unknown}}'; 235 update_post_meta( $post_ID, $cachekey, $cache ); 252 // Maybe cache the result 253 if ( $html ) { 254 update_post_meta( $post_ID, $cachekey, $html ); 255 update_post_meta( $post_ID, $cachekey_time, time() ); 256 } elseif ( ! $cache ) { 257 update_post_meta( $post_ID, $cachekey, '{{unknown}}' ); 258 } 236 259 237 260 // If there was a result, return it … … 247 270 248 271 /** 249 * Delete all oEmbed caches. 272 * Delete all oEmbed caches. Unused by core as of 4.0.0. 250 273 * 251 274 * @param int $post_ID Post ID to delete the caches for.
Note: See TracChangeset
for help on using the changeset viewer.