diff --git a/src/wp-includes/class-oembed.php b/src/wp-includes/class-oembed.php index 2844bd1f1f..363b7c9933 100644 --- a/src/wp-includes/class-oembed.php +++ b/src/wp-includes/class-oembed.php @@ -19,6 +19,7 @@ */ class WP_oEmbed { public $providers = array(); + public static $early_providers = array(); /** * Constructor @@ -65,6 +66,20 @@ class WP_oEmbed { '#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. * @@ -133,6 +148,22 @@ class WP_oEmbed { 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. * diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php index 34ea96902f..3581b32e68 100644 --- a/src/wp-includes/media.php +++ b/src/wp-includes/media.php @@ -2135,8 +2135,13 @@ function wp_oembed_get( $url, $args = '' ) { */ function wp_oembed_add_provider( $format, $provider, $regex = false ) { 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 ) { 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 ] ) ) { - unset( $oembed->providers[ $format ] ); - return true; + if ( isset( $oembed->providers[ $format ] ) ) { + unset( $oembed->providers[ $format ] ); + return true; + } + } else { + WP_oEmbed::_remove_provider_early( $format ); } return false;