Ticket #25527: 25527.3.diff
File 25527.3.diff, 4.5 KB (added by , 11 years ago) |
---|
-
src/wp-includes/class-oembed.php
26 26 * @uses apply_filters() Filters a list of pre-defined oEmbed providers. 27 27 */ 28 28 function __construct() { 29 // List out some popular sites that support oEmbed. 30 // The WP_Embed class disables discovery for non-unfiltered_html users, so only providers in this array will be used for them. 31 // Add to this list using the wp_oembed_add_provider() function (see its PHPDoc for details). 32 $this->providers = apply_filters( 'oembed_providers', array( 29 $providers = array( 33 30 '#https?://(www\.)?youtube\.com/watch.*#i' => array( 'http://www.youtube.com/oembed', true ), 34 31 'http://youtu.be/*' => array( 'http://www.youtube.com/oembed', false ), 35 32 'http://blip.tv/*' => array( 'http://blip.tv/oembed/', false ), … … 56 53 '#https?://(www\.)?rdio\.com/.*#i' => array( 'http://www.rdio.com/api/oembed/', true ), 57 54 '#https?://rd\.io/x/.*#i' => array( 'http://www.rdio.com/api/oembed/', true ), 58 55 '#https?://(open|play)\.spotify\.com/.*#i' => array( 'https://embed.spotify.com/oembed/', true ), 59 ) ); 56 ); 57 /** 58 * Filter the list of oEmbed providers. 59 * 60 * Discovery is disabled for users lacking the unfiltered_html capability. 61 * Only providers in this array will be used for those users. 62 * 63 * @see wp_oembed_add_provider() 64 * 65 * @since 2.9.0 66 * 67 * @param array $providers An array of popular oEmbed providers. 68 */ 69 $this->providers = apply_filters( 'oembed_providers', $providers ); 60 70 61 71 // Fix any embeds that contain new lines in the middle of the HTML which breaks wpautop(). 62 72 add_filter( 'oembed_dataparse', array($this, '_strip_newlines'), 10, 3 ); … … 100 110 if ( !$provider || false === $data = $this->fetch( $provider, $url, $args ) ) 101 111 return false; 102 112 113 /** 114 * Filter the HTML returned by the oEmbed provider. 115 * 116 * @since 2.9.0 117 * 118 * @param string $data The returned oEmbed HTML. 119 * @param string $url URL of the content to be embedded. 120 * @param array $args Optional arguments, usually passed from a shortcode. 121 */ 103 122 return apply_filters( 'oembed_result', $this->data2html( $data, $url ), $url, $args ); 104 123 } 105 124 … … 115 134 // Fetch URL content 116 135 if ( $html = wp_remote_retrieve_body( wp_safe_remote_get( $url ) ) ) { 117 136 118 // <link> types that contain oEmbed provider URLs 137 /** 138 * Filter the link types that contain oEmbed provider URLs. 139 * 140 * @since 2.9.0 141 * 142 * @param array $format Array of oEmbed link types. Accepts 'application/json+oembed', 143 * 'text/xml+oembed', and 'application/xml+oembed' (incorrect, 144 * used by at least Vimeo). 145 */ 119 146 $linktypes = apply_filters( 'oembed_linktypes', array( 120 147 'application/json+oembed' => 'json', 121 148 'text/xml+oembed' => 'xml', 122 'application/xml+oembed' => 'xml', // Incorrect, but used by at least Vimeo149 'application/xml+oembed' => 'xml', 123 150 ) ); 124 151 125 152 // Strip <body> … … 173 200 $provider = add_query_arg( 'maxheight', (int) $args['height'], $provider ); 174 201 $provider = add_query_arg( 'url', urlencode($url), $provider ); 175 202 203 /** 204 * Filter the oEmbed URL to be fetched. 205 * 206 * @since 2.9.0 207 * 208 * @param string $provider URL of the oEmbed provider. 209 * @param string $url URL of the content to be embedded. 210 * @param array $args Optional arguments, usually passed from a shortcode. 211 */ 176 212 $provider = apply_filters( 'oembed_fetch_url', $provider, $url, $args ); 177 213 178 214 foreach( array( 'json', 'xml' ) as $format ) { … … 309 345 $return = false; 310 346 } 311 347 312 // You can use this filter to add support for custom data types or to filter the result 348 /** 349 * Filter the returned oEmbed HTML. 350 * 351 * Use this filter to add support for custom data types, or to filter the result. 352 * 353 * @since 2.9.0 354 * 355 * @param string $return The returned oEmbed HTML. 356 * @param object $data A data object result from an oEmbed provider. 357 * @param string $url The URL of the content to be embedded. 358 */ 313 359 return apply_filters( 'oembed_dataparse', $return, $data, $url ); 314 360 } 315 361