Ticket #14759: 14759.patch
File 14759.patch, 4.0 KB (added by , 10 years ago) |
---|
-
media.php
1024 1024 * 1025 1025 * @param string $url The URL that should be embedded. 1026 1026 * @param array $args Additional arguments and parameters. 1027 * @param bool $use_cache Use a cached value if available. 1027 1028 * @return bool|string False on failure or the embed HTML on success. 1028 1029 */ 1029 function wp_oembed_get( $url, $args = '' ) {1030 function wp_oembed_get( $url, $args = '', $use_cache = true ) { 1030 1031 require_once( ABSPATH . WPINC . '/class-oembed.php' ); 1031 1032 $oembed = _wp_oembed_get_object(); 1032 return $oembed->get_html( $url, $args );1033 return $oembed->get_html( $url, $args, $use_cache ); 1033 1034 } 1034 1035 1035 1036 /** -
class-oembed.php
66 66 * 67 67 * @param string $url The URL to the content that should be attempted to be embedded. 68 68 * @param array $args Optional arguments. Usually passed from a shortcode. 69 * @param bool $use_cache Use a cached value if available. 69 70 * @return bool|string False on failure, otherwise the UNSANITIZED (and potentially unsafe) HTML that should be used to embed. 70 71 */ 71 function get_html( $url, $args = '' ) { 72 function get_html( $url, $args = '', $use_cache = true ) { 73 74 // Check for a cached result (stored in the post meta) 75 $cachekey = '_oembed_' . md5( $url . serialize( $attr ) ); 76 77 if ( $use_cache ) { 78 $cache = get_transient( $cachekey ); 79 80 if ( ! empty( $cache ) ) 81 return $cache; 82 83 } 84 72 85 $provider = false; 73 86 74 87 if ( !isset($args['discover']) ) … … 92 105 if ( !$provider && $args['discover'] ) 93 106 $provider = $this->discover( $url ); 94 107 95 if ( !$provider || false === $data = $this->fetch( $provider, $url, $args ) ) 96 return false; 108 if ( !$provider || false === $data = $this->fetch( $provider, $url, $args ) ) { 109 // Cache failures. 110 set_transient( $cachekey, '{{unknown}}', 12 * HOUR_IN_SECONDS ); 111 return '{{unknown}}'; 112 } 97 113 98 return apply_filters( 'oembed_result', $this->data2html( $data, $url ), $url, $args ); 114 $html = apply_filters( 'oembed_result', $this->data2html( $data, $url ), $url, $args ); 115 $expiry_time = ! empty ( $data->cache_age ) ? (int) $data->cache_age : 30 * DAY_IN_SECONDS; 116 set_transient( $cachekey, $html, $expiry_time ); 117 118 return $html; 99 119 } 100 120 101 121 /** -
class-wp-embed.php
165 165 // Unknown URL format. Let oEmbed have a go. 166 166 if ( $post_ID ) { 167 167 168 // Check for a cached result (stored in the post meta)169 $cachekey = '_oembed_' . md5( $url . serialize( $attr ) );170 if ( $this->usecache ) {171 $cache = get_post_meta( $post_ID, $cachekey, true );172 173 // Failures are cached174 if ( '{{unknown}}' === $cache )175 return $this->maybe_make_link( $url );176 177 if ( ! empty( $cache ) )178 return apply_filters( 'embed_oembed_html', $cache, $url, $attr, $post_ID );179 }180 181 168 // Use oEmbed to get the HTML 182 169 $attr['discover'] = ( apply_filters('embed_oembed_discover', false) && author_can( $post_ID, 'unfiltered_html' ) ); 183 $html = wp_oembed_get( $url, $attr );170 $html = wp_oembed_get( $url, $attr, $this->usecache ); 184 171 185 // Cache the result 186 $cache = ( $html ) ? $html : '{{unknown}}'; 187 update_post_meta( $post_ID, $cachekey, $cache ); 172 // If there was a result, return it 173 if ( $html ) { 174 // Failures 175 if ( '{{unknown}}' === $html ) 176 return $this->maybe_make_link( $url ); 188 177 189 // If there was a result, return it190 if ( $html )191 178 return apply_filters( 'embed_oembed_html', $html, $url, $attr, $post_ID ); 179 } 192 180 } 193 181 194 182 // Still unknown