When wp_oembed_add_provider()
or wp_oembed_remove_provider()
is called before the plugins_loaded
hook has, store the values statically on the WP_oEmbed
object and add them just-in-time when the object is instantiated.
This ensures that all plugins have an accurate provider list when `apply_filters( 'oembed_providers', $providers )` is called. Props kovshenin. Fixes #28284. git-svn-id: https://develop.svn.wordpress.org/trunk@28846 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
4d1313bffc
commit
7139817d2e
@ -19,6 +19,7 @@
|
|||||||
*/
|
*/
|
||||||
class WP_oEmbed {
|
class WP_oEmbed {
|
||||||
public $providers = array();
|
public $providers = array();
|
||||||
|
public static $early_providers = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
@ -65,6 +66,20 @@ class WP_oEmbed {
|
|||||||
'#https?://(www\.)?(animoto|video214)\.com/play/.*#i' => array( 'http://animoto.com/oembeds/create', true ),
|
'#https?://(www\.)?(animoto|video214)\.com/play/.*#i' => array( 'http://animoto.com/oembeds/create', true ),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if ( ! empty( self::$early_providers['add'] ) ) {
|
||||||
|
foreach ( self::$early_providers['add'] as $format => $data ) {
|
||||||
|
$providers[ $format ] = $data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ! empty( self::$early_providers['remove'] ) ) {
|
||||||
|
foreach ( self::$early_providers['remove'] as $format ) {
|
||||||
|
unset( $providers[ $format ] );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
self::$early_providers = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filter the list of oEmbed providers.
|
* Filter the list of oEmbed providers.
|
||||||
*
|
*
|
||||||
@ -133,6 +148,22 @@ class WP_oEmbed {
|
|||||||
return $provider;
|
return $provider;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function _add_provider_early( $format, $provider, $regex = false ) {
|
||||||
|
if ( empty( self::$early_providers['add'] ) ) {
|
||||||
|
self::$early_providers['add'] = array();
|
||||||
|
}
|
||||||
|
|
||||||
|
self::$early_providers['add'][ $format ] = array( $provider, $regex );
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function _remove_provider_early( $format ) {
|
||||||
|
if ( empty( self::$early_providers['remove'] ) ) {
|
||||||
|
self::$early_providers['remove'] = array();
|
||||||
|
}
|
||||||
|
|
||||||
|
self::$early_providers['remove'][] = $format;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The do-it-all function that takes a URL and attempts to return the HTML.
|
* The do-it-all function that takes a URL and attempts to return the HTML.
|
||||||
*
|
*
|
||||||
|
@ -2135,8 +2135,13 @@ function wp_oembed_get( $url, $args = '' ) {
|
|||||||
*/
|
*/
|
||||||
function wp_oembed_add_provider( $format, $provider, $regex = false ) {
|
function wp_oembed_add_provider( $format, $provider, $regex = false ) {
|
||||||
require_once( ABSPATH . WPINC . '/class-oembed.php' );
|
require_once( ABSPATH . WPINC . '/class-oembed.php' );
|
||||||
$oembed = _wp_oembed_get_object();
|
|
||||||
$oembed->providers[$format] = array( $provider, $regex );
|
if ( did_action( 'plugins_loaded' ) ) {
|
||||||
|
$oembed = _wp_oembed_get_object();
|
||||||
|
$oembed->providers[$format] = array( $provider, $regex );
|
||||||
|
} else {
|
||||||
|
WP_oEmbed::_add_provider_early( $format, $provider, $regex );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -2152,11 +2157,15 @@ function wp_oembed_add_provider( $format, $provider, $regex = false ) {
|
|||||||
function wp_oembed_remove_provider( $format ) {
|
function wp_oembed_remove_provider( $format ) {
|
||||||
require_once( ABSPATH . WPINC . '/class-oembed.php' );
|
require_once( ABSPATH . WPINC . '/class-oembed.php' );
|
||||||
|
|
||||||
$oembed = _wp_oembed_get_object();
|
if ( did_action( 'plugins_loaded' ) ) {
|
||||||
|
$oembed = _wp_oembed_get_object();
|
||||||
|
|
||||||
if ( isset( $oembed->providers[ $format ] ) ) {
|
if ( isset( $oembed->providers[ $format ] ) ) {
|
||||||
unset( $oembed->providers[ $format ] );
|
unset( $oembed->providers[ $format ] );
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
WP_oEmbed::_remove_provider_early( $format );
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
Reference in New Issue
Block a user