Edit File by line
/home/barbar84/www/wp-inclu...
File: class-wp-oembed.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* API for fetching the HTML to embed remote content based on a provided URL
[2] Fix | Delete
*
[3] Fix | Delete
* Used internally by the WP_Embed class, but is designed to be generic.
[4] Fix | Delete
*
[5] Fix | Delete
* @link https://wordpress.org/support/article/embeds/
[6] Fix | Delete
* @link http://oembed.com/
[7] Fix | Delete
*
[8] Fix | Delete
* @package WordPress
[9] Fix | Delete
* @subpackage oEmbed
[10] Fix | Delete
*/
[11] Fix | Delete
[12] Fix | Delete
/**
[13] Fix | Delete
* Core class used to implement oEmbed functionality.
[14] Fix | Delete
*
[15] Fix | Delete
* @since 2.9.0
[16] Fix | Delete
*/
[17] Fix | Delete
class WP_oEmbed {
[18] Fix | Delete
[19] Fix | Delete
/**
[20] Fix | Delete
* A list of oEmbed providers.
[21] Fix | Delete
*
[22] Fix | Delete
* @since 2.9.0
[23] Fix | Delete
* @var array
[24] Fix | Delete
*/
[25] Fix | Delete
public $providers = array();
[26] Fix | Delete
[27] Fix | Delete
/**
[28] Fix | Delete
* A list of an early oEmbed providers.
[29] Fix | Delete
*
[30] Fix | Delete
* @since 4.0.0
[31] Fix | Delete
* @var array
[32] Fix | Delete
*/
[33] Fix | Delete
public static $early_providers = array();
[34] Fix | Delete
[35] Fix | Delete
/**
[36] Fix | Delete
* A list of private/protected methods, used for backward compatibility.
[37] Fix | Delete
*
[38] Fix | Delete
* @since 4.2.0
[39] Fix | Delete
* @var array
[40] Fix | Delete
*/
[41] Fix | Delete
private $compat_methods = array( '_fetch_with_format', '_parse_json', '_parse_xml', '_parse_xml_body' );
[42] Fix | Delete
[43] Fix | Delete
/**
[44] Fix | Delete
* Constructor.
[45] Fix | Delete
*
[46] Fix | Delete
* @since 2.9.0
[47] Fix | Delete
*/
[48] Fix | Delete
public function __construct() {
[49] Fix | Delete
$host = urlencode( home_url() );
[50] Fix | Delete
$providers = array(
[51] Fix | Delete
'#https?://((m|www)\.)?youtube\.com/watch.*#i' => array( 'https://www.youtube.com/oembed', true ),
[52] Fix | Delete
'#https?://((m|www)\.)?youtube\.com/playlist.*#i' => array( 'https://www.youtube.com/oembed', true ),
[53] Fix | Delete
'#https?://youtu\.be/.*#i' => array( 'https://www.youtube.com/oembed', true ),
[54] Fix | Delete
'#https?://(.+\.)?vimeo\.com/.*#i' => array( 'https://vimeo.com/api/oembed.{format}', true ),
[55] Fix | Delete
'#https?://(www\.)?dailymotion\.com/.*#i' => array( 'https://www.dailymotion.com/services/oembed', true ),
[56] Fix | Delete
'#https?://dai\.ly/.*#i' => array( 'https://www.dailymotion.com/services/oembed', true ),
[57] Fix | Delete
'#https?://(www\.)?flickr\.com/.*#i' => array( 'https://www.flickr.com/services/oembed/', true ),
[58] Fix | Delete
'#https?://flic\.kr/.*#i' => array( 'https://www.flickr.com/services/oembed/', true ),
[59] Fix | Delete
'#https?://(.+\.)?smugmug\.com/.*#i' => array( 'https://api.smugmug.com/services/oembed/', true ),
[60] Fix | Delete
'#https?://(www\.)?scribd\.com/(doc|document)/.*#i' => array( 'https://www.scribd.com/services/oembed', true ),
[61] Fix | Delete
'#https?://wordpress\.tv/.*#i' => array( 'https://wordpress.tv/oembed/', true ),
[62] Fix | Delete
'#https?://(.+\.)?polldaddy\.com/.*#i' => array( 'https://api.crowdsignal.com/oembed', true ),
[63] Fix | Delete
'#https?://poll\.fm/.*#i' => array( 'https://api.crowdsignal.com/oembed', true ),
[64] Fix | Delete
'#https?://(.+\.)?survey\.fm/.*#i' => array( 'https://api.crowdsignal.com/oembed', true ),
[65] Fix | Delete
'#https?://(www\.)?twitter\.com/\w{1,15}/status(es)?/.*#i' => array( 'https://publish.twitter.com/oembed', true ),
[66] Fix | Delete
'#https?://(www\.)?twitter\.com/\w{1,15}$#i' => array( 'https://publish.twitter.com/oembed', true ),
[67] Fix | Delete
'#https?://(www\.)?twitter\.com/\w{1,15}/likes$#i' => array( 'https://publish.twitter.com/oembed', true ),
[68] Fix | Delete
'#https?://(www\.)?twitter\.com/\w{1,15}/lists/.*#i' => array( 'https://publish.twitter.com/oembed', true ),
[69] Fix | Delete
'#https?://(www\.)?twitter\.com/\w{1,15}/timelines/.*#i' => array( 'https://publish.twitter.com/oembed', true ),
[70] Fix | Delete
'#https?://(www\.)?twitter\.com/i/moments/.*#i' => array( 'https://publish.twitter.com/oembed', true ),
[71] Fix | Delete
'#https?://(www\.)?soundcloud\.com/.*#i' => array( 'https://soundcloud.com/oembed', true ),
[72] Fix | Delete
'#https?://(.+?\.)?slideshare\.net/.*#i' => array( 'https://www.slideshare.net/api/oembed/2', true ),
[73] Fix | Delete
'#https?://(open|play)\.spotify\.com/.*#i' => array( 'https://embed.spotify.com/oembed/', true ),
[74] Fix | Delete
'#https?://(.+\.)?imgur\.com/.*#i' => array( 'https://api.imgur.com/oembed', true ),
[75] Fix | Delete
'#https?://(www\.)?meetu(\.ps|p\.com)/.*#i' => array( 'https://api.meetup.com/oembed', true ),
[76] Fix | Delete
'#https?://(www\.)?issuu\.com/.+/docs/.+#i' => array( 'https://issuu.com/oembed_wp', true ),
[77] Fix | Delete
'#https?://(www\.)?mixcloud\.com/.*#i' => array( 'https://www.mixcloud.com/oembed', true ),
[78] Fix | Delete
'#https?://(www\.|embed\.)?ted\.com/talks/.*#i' => array( 'https://www.ted.com/services/v1/oembed.{format}', true ),
[79] Fix | Delete
'#https?://(www\.)?(animoto|video214)\.com/play/.*#i' => array( 'https://animoto.com/oembeds/create', true ),
[80] Fix | Delete
'#https?://(.+)\.tumblr\.com/post/.*#i' => array( 'https://www.tumblr.com/oembed/1.0', true ),
[81] Fix | Delete
'#https?://(www\.)?kickstarter\.com/projects/.*#i' => array( 'https://www.kickstarter.com/services/oembed', true ),
[82] Fix | Delete
'#https?://kck\.st/.*#i' => array( 'https://www.kickstarter.com/services/oembed', true ),
[83] Fix | Delete
'#https?://cloudup\.com/.*#i' => array( 'https://cloudup.com/oembed', true ),
[84] Fix | Delete
'#https?://(www\.)?reverbnation\.com/.*#i' => array( 'https://www.reverbnation.com/oembed', true ),
[85] Fix | Delete
'#https?://videopress\.com/v/.*#' => array( 'https://public-api.wordpress.com/oembed/?for=' . $host, true ),
[86] Fix | Delete
'#https?://(www\.)?reddit\.com/r/[^/]+/comments/.*#i' => array( 'https://www.reddit.com/oembed', true ),
[87] Fix | Delete
'#https?://(www\.)?speakerdeck\.com/.*#i' => array( 'https://speakerdeck.com/oembed.{format}', true ),
[88] Fix | Delete
'#https?://(www\.)?screencast\.com/.*#i' => array( 'https://api.screencast.com/external/oembed', true ),
[89] Fix | Delete
'#https?://([a-z0-9-]+\.)?amazon\.(com|com\.mx|com\.br|ca)/.*#i' => array( 'https://read.amazon.com/kp/api/oembed', true ),
[90] Fix | Delete
'#https?://([a-z0-9-]+\.)?amazon\.(co\.uk|de|fr|it|es|in|nl|ru)/.*#i' => array( 'https://read.amazon.co.uk/kp/api/oembed', true ),
[91] Fix | Delete
'#https?://([a-z0-9-]+\.)?amazon\.(co\.jp|com\.au)/.*#i' => array( 'https://read.amazon.com.au/kp/api/oembed', true ),
[92] Fix | Delete
'#https?://([a-z0-9-]+\.)?amazon\.cn/.*#i' => array( 'https://read.amazon.cn/kp/api/oembed', true ),
[93] Fix | Delete
'#https?://(www\.)?a\.co/.*#i' => array( 'https://read.amazon.com/kp/api/oembed', true ),
[94] Fix | Delete
'#https?://(www\.)?amzn\.to/.*#i' => array( 'https://read.amazon.com/kp/api/oembed', true ),
[95] Fix | Delete
'#https?://(www\.)?amzn\.eu/.*#i' => array( 'https://read.amazon.co.uk/kp/api/oembed', true ),
[96] Fix | Delete
'#https?://(www\.)?amzn\.in/.*#i' => array( 'https://read.amazon.in/kp/api/oembed', true ),
[97] Fix | Delete
'#https?://(www\.)?amzn\.asia/.*#i' => array( 'https://read.amazon.com.au/kp/api/oembed', true ),
[98] Fix | Delete
'#https?://(www\.)?z\.cn/.*#i' => array( 'https://read.amazon.cn/kp/api/oembed', true ),
[99] Fix | Delete
'#https?://www\.someecards\.com/.+-cards/.+#i' => array( 'https://www.someecards.com/v2/oembed/', true ),
[100] Fix | Delete
'#https?://www\.someecards\.com/usercards/viewcard/.+#i' => array( 'https://www.someecards.com/v2/oembed/', true ),
[101] Fix | Delete
'#https?://some\.ly\/.+#i' => array( 'https://www.someecards.com/v2/oembed/', true ),
[102] Fix | Delete
'#https?://(www\.)?tiktok\.com/.*/video/.*#i' => array( 'https://www.tiktok.com/oembed', true ),
[103] Fix | Delete
);
[104] Fix | Delete
[105] Fix | Delete
if ( ! empty( self::$early_providers['add'] ) ) {
[106] Fix | Delete
foreach ( self::$early_providers['add'] as $format => $data ) {
[107] Fix | Delete
$providers[ $format ] = $data;
[108] Fix | Delete
}
[109] Fix | Delete
}
[110] Fix | Delete
[111] Fix | Delete
if ( ! empty( self::$early_providers['remove'] ) ) {
[112] Fix | Delete
foreach ( self::$early_providers['remove'] as $format ) {
[113] Fix | Delete
unset( $providers[ $format ] );
[114] Fix | Delete
}
[115] Fix | Delete
}
[116] Fix | Delete
[117] Fix | Delete
self::$early_providers = array();
[118] Fix | Delete
[119] Fix | Delete
/**
[120] Fix | Delete
* Filters the list of sanctioned oEmbed providers.
[121] Fix | Delete
*
[122] Fix | Delete
* Since WordPress 4.4, oEmbed discovery is enabled for all users and allows embedding of sanitized
[123] Fix | Delete
* iframes. The providers in this list are sanctioned, meaning they are trusted and allowed to
[124] Fix | Delete
* embed any content, such as iframes, videos, JavaScript, and arbitrary HTML.
[125] Fix | Delete
*
[126] Fix | Delete
* Supported providers:
[127] Fix | Delete
*
[128] Fix | Delete
* | Provider | Flavor | Since |
[129] Fix | Delete
* | ------------ | ----------------------------------------- | ------- |
[130] Fix | Delete
* | Dailymotion | dailymotion.com | 2.9.0 |
[131] Fix | Delete
* | Flickr | flickr.com | 2.9.0 |
[132] Fix | Delete
* | Scribd | scribd.com | 2.9.0 |
[133] Fix | Delete
* | Vimeo | vimeo.com | 2.9.0 |
[134] Fix | Delete
* | WordPress.tv | wordpress.tv | 2.9.0 |
[135] Fix | Delete
* | YouTube | youtube.com/watch | 2.9.0 |
[136] Fix | Delete
* | Crowdsignal | polldaddy.com | 3.0.0 |
[137] Fix | Delete
* | SmugMug | smugmug.com | 3.0.0 |
[138] Fix | Delete
* | YouTube | youtu.be | 3.0.0 |
[139] Fix | Delete
* | Twitter | twitter.com | 3.4.0 |
[140] Fix | Delete
* | Slideshare | slideshare.net | 3.5.0 |
[141] Fix | Delete
* | SoundCloud | soundcloud.com | 3.5.0 |
[142] Fix | Delete
* | Dailymotion | dai.ly | 3.6.0 |
[143] Fix | Delete
* | Flickr | flic.kr | 3.6.0 |
[144] Fix | Delete
* | Spotify | spotify.com | 3.6.0 |
[145] Fix | Delete
* | Imgur | imgur.com | 3.9.0 |
[146] Fix | Delete
* | Meetup.com | meetup.com | 3.9.0 |
[147] Fix | Delete
* | Meetup.com | meetu.ps | 3.9.0 |
[148] Fix | Delete
* | Animoto | animoto.com | 4.0.0 |
[149] Fix | Delete
* | Animoto | video214.com | 4.0.0 |
[150] Fix | Delete
* | Issuu | issuu.com | 4.0.0 |
[151] Fix | Delete
* | Mixcloud | mixcloud.com | 4.0.0 |
[152] Fix | Delete
* | Crowdsignal | poll.fm | 4.0.0 |
[153] Fix | Delete
* | TED | ted.com | 4.0.0 |
[154] Fix | Delete
* | YouTube | youtube.com/playlist | 4.0.0 |
[155] Fix | Delete
* | Tumblr | tumblr.com | 4.2.0 |
[156] Fix | Delete
* | Kickstarter | kickstarter.com | 4.2.0 |
[157] Fix | Delete
* | Kickstarter | kck.st | 4.2.0 |
[158] Fix | Delete
* | Cloudup | cloudup.com | 4.3.0 |
[159] Fix | Delete
* | ReverbNation | reverbnation.com | 4.4.0 |
[160] Fix | Delete
* | VideoPress | videopress.com | 4.4.0 |
[161] Fix | Delete
* | Reddit | reddit.com | 4.4.0 |
[162] Fix | Delete
* | Speaker Deck | speakerdeck.com | 4.4.0 |
[163] Fix | Delete
* | Twitter | twitter.com/timelines | 4.5.0 |
[164] Fix | Delete
* | Twitter | twitter.com/moments | 4.5.0 |
[165] Fix | Delete
* | Twitter | twitter.com/user | 4.7.0 |
[166] Fix | Delete
* | Twitter | twitter.com/likes | 4.7.0 |
[167] Fix | Delete
* | Twitter | twitter.com/lists | 4.7.0 |
[168] Fix | Delete
* | Screencast | screencast.com | 4.8.0 |
[169] Fix | Delete
* | Amazon | amazon.com (com.mx, com.br, ca) | 4.9.0 |
[170] Fix | Delete
* | Amazon | amazon.de (fr, it, es, in, nl, ru, co.uk) | 4.9.0 |
[171] Fix | Delete
* | Amazon | amazon.co.jp (com.au) | 4.9.0 |
[172] Fix | Delete
* | Amazon | amazon.cn | 4.9.0 |
[173] Fix | Delete
* | Amazon | a.co | 4.9.0 |
[174] Fix | Delete
* | Amazon | amzn.to (eu, in, asia) | 4.9.0 |
[175] Fix | Delete
* | Amazon | z.cn | 4.9.0 |
[176] Fix | Delete
* | Someecards | someecards.com | 4.9.0 |
[177] Fix | Delete
* | Someecards | some.ly | 4.9.0 |
[178] Fix | Delete
* | Crowdsignal | survey.fm | 5.1.0 |
[179] Fix | Delete
* | TikTok | tiktok.com | 5.4.0 |
[180] Fix | Delete
*
[181] Fix | Delete
* No longer supported providers:
[182] Fix | Delete
*
[183] Fix | Delete
* | Provider | Flavor | Since | Removed |
[184] Fix | Delete
* | ------------ | -------------------- | --------- | --------- |
[185] Fix | Delete
* | Qik | qik.com | 2.9.0 | 3.9.0 |
[186] Fix | Delete
* | Viddler | viddler.com | 2.9.0 | 4.0.0 |
[187] Fix | Delete
* | Revision3 | revision3.com | 2.9.0 | 4.2.0 |
[188] Fix | Delete
* | Blip | blip.tv | 2.9.0 | 4.4.0 |
[189] Fix | Delete
* | Rdio | rdio.com | 3.6.0 | 4.4.1 |
[190] Fix | Delete
* | Rdio | rd.io | 3.6.0 | 4.4.1 |
[191] Fix | Delete
* | Vine | vine.co | 4.1.0 | 4.9.0 |
[192] Fix | Delete
* | Photobucket | photobucket.com | 2.9.0 | 5.1.0 |
[193] Fix | Delete
* | Funny or Die | funnyordie.com | 3.0.0 | 5.1.0 |
[194] Fix | Delete
* | CollegeHumor | collegehumor.com | 4.0.0 | 5.3.1 |
[195] Fix | Delete
* | Hulu | hulu.com | 2.9.0 | 5.5.0 |
[196] Fix | Delete
* | Instagram | instagram.com | 3.5.0 | 5.5.2 |
[197] Fix | Delete
* | Instagram | instagr.am | 3.5.0 | 5.5.2 |
[198] Fix | Delete
* | Instagram TV | instagram.com | 5.1.0 | 5.5.2 |
[199] Fix | Delete
* | Instagram TV | instagr.am | 5.1.0 | 5.5.2 |
[200] Fix | Delete
* | Facebook | facebook.com | 4.7.0 | 5.5.2 |
[201] Fix | Delete
*
[202] Fix | Delete
* @see wp_oembed_add_provider()
[203] Fix | Delete
*
[204] Fix | Delete
* @since 2.9.0
[205] Fix | Delete
*
[206] Fix | Delete
* @param array[] $providers An array of arrays containing data about popular oEmbed providers.
[207] Fix | Delete
*/
[208] Fix | Delete
$this->providers = apply_filters( 'oembed_providers', $providers );
[209] Fix | Delete
[210] Fix | Delete
// Fix any embeds that contain new lines in the middle of the HTML which breaks wpautop().
[211] Fix | Delete
add_filter( 'oembed_dataparse', array( $this, '_strip_newlines' ), 10, 3 );
[212] Fix | Delete
}
[213] Fix | Delete
[214] Fix | Delete
/**
[215] Fix | Delete
* Exposes private/protected methods for backward compatibility.
[216] Fix | Delete
*
[217] Fix | Delete
* @since 4.0.0
[218] Fix | Delete
*
[219] Fix | Delete
* @param string $name Method to call.
[220] Fix | Delete
* @param array $arguments Arguments to pass when calling.
[221] Fix | Delete
* @return mixed|false Return value of the callback, false otherwise.
[222] Fix | Delete
*/
[223] Fix | Delete
public function __call( $name, $arguments ) {
[224] Fix | Delete
if ( in_array( $name, $this->compat_methods, true ) ) {
[225] Fix | Delete
return $this->$name( ...$arguments );
[226] Fix | Delete
}
[227] Fix | Delete
return false;
[228] Fix | Delete
}
[229] Fix | Delete
[230] Fix | Delete
/**
[231] Fix | Delete
* Takes a URL and returns the corresponding oEmbed provider's URL, if there is one.
[232] Fix | Delete
*
[233] Fix | Delete
* @since 4.0.0
[234] Fix | Delete
*
[235] Fix | Delete
* @see WP_oEmbed::discover()
[236] Fix | Delete
*
[237] Fix | Delete
* @param string $url The URL to the content.
[238] Fix | Delete
* @param string|array $args {
[239] Fix | Delete
* Optional. Additional provider arguments. Default empty.
[240] Fix | Delete
*
[241] Fix | Delete
* @type bool $discover Optional. Determines whether to attempt to discover link tags
[242] Fix | Delete
* at the given URL for an oEmbed provider when the provider URL
[243] Fix | Delete
* is not found in the built-in providers list. Default true.
[244] Fix | Delete
* }
[245] Fix | Delete
* @return string|false The oEmbed provider URL on success, false on failure.
[246] Fix | Delete
*/
[247] Fix | Delete
public function get_provider( $url, $args = '' ) {
[248] Fix | Delete
$args = wp_parse_args( $args );
[249] Fix | Delete
[250] Fix | Delete
$provider = false;
[251] Fix | Delete
[252] Fix | Delete
if ( ! isset( $args['discover'] ) ) {
[253] Fix | Delete
$args['discover'] = true;
[254] Fix | Delete
}
[255] Fix | Delete
[256] Fix | Delete
foreach ( $this->providers as $matchmask => $data ) {
[257] Fix | Delete
list( $providerurl, $regex ) = $data;
[258] Fix | Delete
[259] Fix | Delete
// Turn the asterisk-type provider URLs into regex.
[260] Fix | Delete
if ( ! $regex ) {
[261] Fix | Delete
$matchmask = '#' . str_replace( '___wildcard___', '(.+)', preg_quote( str_replace( '*', '___wildcard___', $matchmask ), '#' ) ) . '#i';
[262] Fix | Delete
$matchmask = preg_replace( '|^#http\\\://|', '#https?\://', $matchmask );
[263] Fix | Delete
}
[264] Fix | Delete
[265] Fix | Delete
if ( preg_match( $matchmask, $url ) ) {
[266] Fix | Delete
$provider = str_replace( '{format}', 'json', $providerurl ); // JSON is easier to deal with than XML.
[267] Fix | Delete
break;
[268] Fix | Delete
}
[269] Fix | Delete
}
[270] Fix | Delete
[271] Fix | Delete
if ( ! $provider && $args['discover'] ) {
[272] Fix | Delete
$provider = $this->discover( $url );
[273] Fix | Delete
}
[274] Fix | Delete
[275] Fix | Delete
return $provider;
[276] Fix | Delete
}
[277] Fix | Delete
[278] Fix | Delete
/**
[279] Fix | Delete
* Adds an oEmbed provider.
[280] Fix | Delete
*
[281] Fix | Delete
* The provider is added just-in-time when wp_oembed_add_provider() is called before
[282] Fix | Delete
* the {@see 'plugins_loaded'} hook.
[283] Fix | Delete
*
[284] Fix | Delete
* The just-in-time addition is for the benefit of the {@see 'oembed_providers'} filter.
[285] Fix | Delete
*
[286] Fix | Delete
* @since 4.0.0
[287] Fix | Delete
*
[288] Fix | Delete
* @see wp_oembed_add_provider()
[289] Fix | Delete
*
[290] Fix | Delete
* @param string $format Format of URL that this provider can handle. You can use
[291] Fix | Delete
* asterisks as wildcards.
[292] Fix | Delete
* @param string $provider The URL to the oEmbed provider..
[293] Fix | Delete
* @param bool $regex Optional. Whether the $format parameter is in a regex format.
[294] Fix | Delete
* Default false.
[295] Fix | Delete
*/
[296] Fix | Delete
public static function _add_provider_early( $format, $provider, $regex = false ) {
[297] Fix | Delete
if ( empty( self::$early_providers['add'] ) ) {
[298] Fix | Delete
self::$early_providers['add'] = array();
[299] Fix | Delete
}
[300] Fix | Delete
[301] Fix | Delete
self::$early_providers['add'][ $format ] = array( $provider, $regex );
[302] Fix | Delete
}
[303] Fix | Delete
[304] Fix | Delete
/**
[305] Fix | Delete
* Removes an oEmbed provider.
[306] Fix | Delete
*
[307] Fix | Delete
* The provider is removed just-in-time when wp_oembed_remove_provider() is called before
[308] Fix | Delete
* the {@see 'plugins_loaded'} hook.
[309] Fix | Delete
*
[310] Fix | Delete
* The just-in-time removal is for the benefit of the {@see 'oembed_providers'} filter.
[311] Fix | Delete
*
[312] Fix | Delete
* @since 4.0.0
[313] Fix | Delete
*
[314] Fix | Delete
* @see wp_oembed_remove_provider()
[315] Fix | Delete
*
[316] Fix | Delete
* @param string $format The format of URL that this provider can handle. You can use
[317] Fix | Delete
* asterisks as wildcards.
[318] Fix | Delete
*/
[319] Fix | Delete
public static function _remove_provider_early( $format ) {
[320] Fix | Delete
if ( empty( self::$early_providers['remove'] ) ) {
[321] Fix | Delete
self::$early_providers['remove'] = array();
[322] Fix | Delete
}
[323] Fix | Delete
[324] Fix | Delete
self::$early_providers['remove'][] = $format;
[325] Fix | Delete
}
[326] Fix | Delete
[327] Fix | Delete
/**
[328] Fix | Delete
* Takes a URL and attempts to return the oEmbed data.
[329] Fix | Delete
*
[330] Fix | Delete
* @see WP_oEmbed::fetch()
[331] Fix | Delete
*
[332] Fix | Delete
* @since 4.8.0
[333] Fix | Delete
*
[334] Fix | Delete
* @param string $url The URL to the content that should be attempted to be embedded.
[335] Fix | Delete
* @param string|array $args Optional. Additional arguments for retrieving embed HTML.
[336] Fix | Delete
* See wp_oembed_get() for accepted arguments. Default empty.
[337] Fix | Delete
* @return object|false The result in the form of an object on success, false on failure.
[338] Fix | Delete
*/
[339] Fix | Delete
public function get_data( $url, $args = '' ) {
[340] Fix | Delete
$args = wp_parse_args( $args );
[341] Fix | Delete
[342] Fix | Delete
$provider = $this->get_provider( $url, $args );
[343] Fix | Delete
[344] Fix | Delete
if ( ! $provider ) {
[345] Fix | Delete
return false;
[346] Fix | Delete
}
[347] Fix | Delete
[348] Fix | Delete
$data = $this->fetch( $provider, $url, $args );
[349] Fix | Delete
[350] Fix | Delete
if ( false === $data ) {
[351] Fix | Delete
return false;
[352] Fix | Delete
}
[353] Fix | Delete
[354] Fix | Delete
return $data;
[355] Fix | Delete
}
[356] Fix | Delete
[357] Fix | Delete
/**
[358] Fix | Delete
* The do-it-all function that takes a URL and attempts to return the HTML.
[359] Fix | Delete
*
[360] Fix | Delete
* @see WP_oEmbed::fetch()
[361] Fix | Delete
* @see WP_oEmbed::data2html()
[362] Fix | Delete
*
[363] Fix | Delete
* @since 2.9.0
[364] Fix | Delete
*
[365] Fix | Delete
* @param string $url The URL to the content that should be attempted to be embedded.
[366] Fix | Delete
* @param string|array $args Optional. Additional arguments for retrieving embed HTML.
[367] Fix | Delete
* See wp_oembed_get() for accepted arguments. Default empty.
[368] Fix | Delete
* @return string|false The UNSANITIZED (and potentially unsafe) HTML that should be used to embed
[369] Fix | Delete
* on success, false on failure.
[370] Fix | Delete
*/
[371] Fix | Delete
public function get_html( $url, $args = '' ) {
[372] Fix | Delete
/**
[373] Fix | Delete
* Filters the oEmbed result before any HTTP requests are made.
[374] Fix | Delete
*
[375] Fix | Delete
* This allows one to short-circuit the default logic, perhaps by
[376] Fix | Delete
* replacing it with a routine that is more optimal for your setup.
[377] Fix | Delete
*
[378] Fix | Delete
* Returning a non-null value from the filter will effectively short-circuit retrieval
[379] Fix | Delete
* and return the passed value instead.
[380] Fix | Delete
*
[381] Fix | Delete
* @since 4.5.3
[382] Fix | Delete
*
[383] Fix | Delete
* @param null|string $result The UNSANITIZED (and potentially unsafe) HTML that should be used to embed.
[384] Fix | Delete
* Default null to continue retrieving the result.
[385] Fix | Delete
* @param string $url The URL to the content that should be attempted to be embedded.
[386] Fix | Delete
* @param string|array $args Optional. Additional arguments for retrieving embed HTML.
[387] Fix | Delete
* See wp_oembed_get() for accepted arguments. Default empty.
[388] Fix | Delete
*/
[389] Fix | Delete
$pre = apply_filters( 'pre_oembed_result', null, $url, $args );
[390] Fix | Delete
[391] Fix | Delete
if ( null !== $pre ) {
[392] Fix | Delete
return $pre;
[393] Fix | Delete
}
[394] Fix | Delete
[395] Fix | Delete
$data = $this->get_data( $url, $args );
[396] Fix | Delete
[397] Fix | Delete
if ( false === $data ) {
[398] Fix | Delete
return false;
[399] Fix | Delete
}
[400] Fix | Delete
[401] Fix | Delete
/**
[402] Fix | Delete
* Filters the HTML returned by the oEmbed provider.
[403] Fix | Delete
*
[404] Fix | Delete
* @since 2.9.0
[405] Fix | Delete
*
[406] Fix | Delete
* @param string|false $data The returned oEmbed HTML (false if unsafe).
[407] Fix | Delete
* @param string $url URL of the content to be embedded.
[408] Fix | Delete
* @param string|array $args Optional. Additional arguments for retrieving embed HTML.
[409] Fix | Delete
* See wp_oembed_get() for accepted arguments. Default empty.
[410] Fix | Delete
*/
[411] Fix | Delete
return apply_filters( 'oembed_result', $this->data2html( $data, $url ), $url, $args );
[412] Fix | Delete
}
[413] Fix | Delete
[414] Fix | Delete
/**
[415] Fix | Delete
* Attempts to discover link tags at the given URL for an oEmbed provider.
[416] Fix | Delete
*
[417] Fix | Delete
* @since 2.9.0
[418] Fix | Delete
*
[419] Fix | Delete
* @param string $url The URL that should be inspected for discovery `<link>` tags.
[420] Fix | Delete
* @return string|false The oEmbed provider URL on success, false on failure.
[421] Fix | Delete
*/
[422] Fix | Delete
public function discover( $url ) {
[423] Fix | Delete
$providers = array();
[424] Fix | Delete
$args = array(
[425] Fix | Delete
'limit_response_size' => 153600, // 150 KB
[426] Fix | Delete
);
[427] Fix | Delete
[428] Fix | Delete
/**
[429] Fix | Delete
* Filters oEmbed remote get arguments.
[430] Fix | Delete
*
[431] Fix | Delete
* @since 4.0.0
[432] Fix | Delete
*
[433] Fix | Delete
* @see WP_Http::request()
[434] Fix | Delete
*
[435] Fix | Delete
* @param array $args oEmbed remote get arguments.
[436] Fix | Delete
* @param string $url URL to be inspected.
[437] Fix | Delete
*/
[438] Fix | Delete
$args = apply_filters( 'oembed_remote_get_args', $args, $url );
[439] Fix | Delete
[440] Fix | Delete
// Fetch URL content.
[441] Fix | Delete
$request = wp_safe_remote_get( $url, $args );
[442] Fix | Delete
$html = wp_remote_retrieve_body( $request );
[443] Fix | Delete
if ( $html ) {
[444] Fix | Delete
[445] Fix | Delete
/**
[446] Fix | Delete
* Filters the link types that contain oEmbed provider URLs.
[447] Fix | Delete
*
[448] Fix | Delete
* @since 2.9.0
[449] Fix | Delete
*
[450] Fix | Delete
* @param string[] $format Array of oEmbed link types. Accepts 'application/json+oembed',
[451] Fix | Delete
* 'text/xml+oembed', and 'application/xml+oembed' (incorrect,
[452] Fix | Delete
* used by at least Vimeo).
[453] Fix | Delete
*/
[454] Fix | Delete
$linktypes = apply_filters(
[455] Fix | Delete
'oembed_linktypes',
[456] Fix | Delete
array(
[457] Fix | Delete
'application/json+oembed' => 'json',
[458] Fix | Delete
'text/xml+oembed' => 'xml',
[459] Fix | Delete
'application/xml+oembed' => 'xml',
[460] Fix | Delete
)
[461] Fix | Delete
);
[462] Fix | Delete
[463] Fix | Delete
// Strip <body>.
[464] Fix | Delete
$html_head_end = stripos( $html, '</head>' );
[465] Fix | Delete
if ( $html_head_end ) {
[466] Fix | Delete
$html = substr( $html, 0, $html_head_end );
[467] Fix | Delete
}
[468] Fix | Delete
[469] Fix | Delete
// Do a quick check.
[470] Fix | Delete
$tagfound = false;
[471] Fix | Delete
foreach ( $linktypes as $linktype => $format ) {
[472] Fix | Delete
if ( stripos( $html, $linktype ) ) {
[473] Fix | Delete
$tagfound = true;
[474] Fix | Delete
break;
[475] Fix | Delete
}
[476] Fix | Delete
}
[477] Fix | Delete
[478] Fix | Delete
if ( $tagfound && preg_match_all( '#<link([^<>]+)/?>#iU', $html, $links ) ) {
[479] Fix | Delete
foreach ( $links[1] as $link ) {
[480] Fix | Delete
$atts = shortcode_parse_atts( $link );
[481] Fix | Delete
[482] Fix | Delete
if ( ! empty( $atts['type'] ) && ! empty( $linktypes[ $atts['type'] ] ) && ! empty( $atts['href'] ) ) {
[483] Fix | Delete
$providers[ $linktypes[ $atts['type'] ] ] = htmlspecialchars_decode( $atts['href'] );
[484] Fix | Delete
[485] Fix | Delete
// Stop here if it's JSON (that's all we need).
[486] Fix | Delete
if ( 'json' === $linktypes[ $atts['type'] ] ) {
[487] Fix | Delete
break;
[488] Fix | Delete
}
[489] Fix | Delete
}
[490] Fix | Delete
}
[491] Fix | Delete
}
[492] Fix | Delete
}
[493] Fix | Delete
[494] Fix | Delete
// JSON is preferred to XML.
[495] Fix | Delete
if ( ! empty( $providers['json'] ) ) {
[496] Fix | Delete
return $providers['json'];
[497] Fix | Delete
} elseif ( ! empty( $providers['xml'] ) ) {
[498] Fix | Delete
return $providers['xml'];
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function