Make WordPress Core

Changeset 28846


Ignore:
Timestamp:
06/26/2014 02:29:20 AM (10 years ago)
Author:
wonderboymusic
Message:

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.

Location:
trunk/src/wp-includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-oembed.php

    r28834 r28846  
    2020class WP_oEmbed {
    2121    public $providers = array();
     22    public static $early_providers = array();
    2223
    2324    /**
     
    6667        );
    6768
     69        if ( ! empty( self::$early_providers['add'] ) ) {
     70            foreach ( self::$early_providers['add'] as $format => $data ) {
     71                $providers[ $format ] = $data;
     72            }
     73        }
     74
     75        if ( ! empty( self::$early_providers['remove'] ) ) {
     76            foreach ( self::$early_providers['remove'] as $format ) {
     77                unset( $providers[ $format ] );
     78            }
     79        }
     80
     81        self::$early_providers = array();
     82
    6883        /**
    6984         * Filter the list of oEmbed providers.
     
    132147
    133148        return $provider;
     149    }
     150
     151    public static function _add_provider_early( $format, $provider, $regex = false ) {
     152        if ( empty( self::$early_providers['add'] ) ) {
     153            self::$early_providers['add'] = array();
     154        }
     155
     156        self::$early_providers['add'][ $format ] = array( $provider, $regex );
     157    }
     158
     159    public static function _remove_provider_early( $format ) {
     160        if ( empty( self::$early_providers['remove'] ) ) {
     161            self::$early_providers['remove'] = array();
     162        }
     163
     164        self::$early_providers['remove'][] = $format;
    134165    }
    135166
  • trunk/src/wp-includes/media.php

    r28682 r28846  
    21362136function wp_oembed_add_provider( $format, $provider, $regex = false ) {
    21372137    require_once( ABSPATH . WPINC . '/class-oembed.php' );
    2138     $oembed = _wp_oembed_get_object();
    2139     $oembed->providers[$format] = array( $provider, $regex );
     2138
     2139    if ( did_action( 'plugins_loaded' ) ) {
     2140        $oembed = _wp_oembed_get_object();
     2141        $oembed->providers[$format] = array( $provider, $regex );
     2142    } else {
     2143        WP_oEmbed::_add_provider_early( $format, $provider, $regex );
     2144    }
    21402145}
    21412146
     
    21532158    require_once( ABSPATH . WPINC . '/class-oembed.php' );
    21542159
    2155     $oembed = _wp_oembed_get_object();
    2156 
    2157     if ( isset( $oembed->providers[ $format ] ) ) {
    2158         unset( $oembed->providers[ $format ] );
    2159         return true;
     2160    if ( did_action( 'plugins_loaded' ) ) {
     2161        $oembed = _wp_oembed_get_object();
     2162
     2163        if ( isset( $oembed->providers[ $format ] ) ) {
     2164            unset( $oembed->providers[ $format ] );
     2165            return true;
     2166        }
     2167    } else {
     2168        WP_oEmbed::_remove_provider_early( $format );
    21602169    }
    21612170
Note: See TracChangeset for help on using the changeset viewer.