Ticket #17857: 17857.001.patch
File 17857.001.patch, 4.1 KB (added by , 14 years ago) |
---|
-
wp-includes/media.php
1130 1130 * The {@link do_shortcode()} callback function. 1131 1131 * 1132 1132 * Attempts to convert a URL into embed HTML. Starts by checking the URL against the regex of the registered embed handlers. 1133 * If none of the regex matches and it's enabled, then the URL will be given to the {@link WP_oEmbed} class. 1133 * Next, checks the URL against the regex of registered {@link WP_oEmbed} providers if oEmbed discovery is false. 1134 * If none of the regex matches and it's enabled, then the URL will be passed to {@link WP_Embed::parse_oembed()} for oEmbed parsing. 1134 1135 * 1135 * @uses wp_oembed_get()1136 1136 * @uses wp_parse_args() 1137 1137 * @uses wp_embed_defaults() 1138 * @uses author_can() 1139 * @uses _wp_oembed_get_object() 1138 1140 * @uses WP_Embed::maybe_make_link() 1139 * @uses get_option()1140 * @uses current_user_can()1141 * @uses wp_cache_get()1142 * @uses wp_cache_set()1143 * @uses get_post_meta()1144 * @uses update_post_meta()1145 1141 * 1146 1142 * @param array $attr Shortcode attributes. 1147 1143 * @param string $url The URL attempting to be embeded. … … 1171 1167 } 1172 1168 } 1173 1169 1170 // Get post ID 1174 1171 $post_ID = ( !empty($post->ID) ) ? $post->ID : null; 1175 if ( !empty( $this->post_ID) ) // Potentially set by WP_Embed::cache_oembed()1172 if ( !empty( $this->post_ID ) ) // Potentially set by WP_Embed::cache_oembed() 1176 1173 $post_ID = $this->post_ID; 1177 1174 1178 // Unknown URL format. Let oEmbed have a go. 1175 // Let 3rd-party plugins override post ID so they can easily extend the WP_Embed class 1176 $post_ID = apply_filters( 'embed_post_id', $post_ID ); 1177 1178 // Is oEmbed discovery on? 1179 $attr['discover'] = ( apply_filters( 'embed_oembed_discover', false ) && apply_filters( 'embed_oembed_author_can', author_can( $post_ID, 'unfiltered_html' ), $post_ID ) ); 1180 1181 // Set up a new WP oEmbed object to check URL with registered oEmbed providers 1182 require_once( ABSPATH . WPINC . '/class-oembed.php' ); 1183 $oembed_obj = _wp_oembed_get_object(); 1184 1185 // If oEmbed discovery is true, skip oEmbed provider check 1186 $is_oembed_link = false; 1187 if ( !$attr['discover'] ) { 1188 foreach ( (array)$oembed_obj->providers as $provider_matchmask => $provider ) { 1189 $regex = ( $is_regex = $provider[1] ) ? $provider_matchmask : '#' . str_replace( '___wildcard___', '(.+)', preg_quote( str_replace( '*', '___wildcard___', $provider_matchmask ), '#' ) ) . '#i'; 1190 1191 if ( preg_match( $regex, $url ) ) 1192 $is_oembed_link = true; 1193 } 1194 1195 // If url doesn't match a WP oEmbed provider, stop parsing 1196 if ( !$is_oembed_link ) 1197 return $this->maybe_make_link( $url ); 1198 } 1199 1200 return $this->parse_oembed( $post_ID, $url, $attr, $rawattr ); 1201 } 1202 1203 /** 1204 * Attempts to convert a URL into embed HTML. Checks cache first. If no cache, ping oEmbed provider and cache the result. 1205 * URL is passed to the {@link WP_oEmbed} class via {@link wp_oembed_get()}. 1206 * 3rd party plugins not using post types could extend this class and function to grab their own cache. 1207 * 1208 * @uses wp_oembed_get() 1209 * @uses WP_Embed::maybe_make_link() 1210 * @uses get_post_meta() 1211 * @uses update_post_meta() 1212 * @param int $post_id Post ID to do the caching for. 1213 * @param string $url The URL attempting to be embedded. 1214 * @param array $attr Shortcode attributes. 1215 * @param array $rawattr Untouched shortcode attributes. 1216 * @return string The embed HTML on success, otherwise the original URL. 1217 */ 1218 function parse_oembed( $post_ID, $url, $attr, $rawattr ) { 1179 1219 if ( $post_ID ) { 1180 1220 1181 1221 // Check for a cached result (stored in the post meta) … … 1187 1227 if ( '{{unknown}}' === $cache ) 1188 1228 return $this->maybe_make_link( $url ); 1189 1229 1190 if ( !empty( $cache) )1230 if ( !empty( $cache ) ) 1191 1231 return apply_filters( 'embed_oembed_html', $cache, $url, $attr, $post_ID ); 1192 1232 } 1193 1233 1194 1234 // Use oEmbed to get the HTML 1195 $attr['discover'] = ( apply_filters('embed_oembed_discover', false) && author_can( $post_ID, 'unfiltered_html' ) );1196 1235 $html = wp_oembed_get( $url, $attr ); 1197 1236 1198 1237 // Cache the result