WordPress.org

Make WordPress Core

Ticket #10337: 10337.6.patch

File 10337.6.patch, 4.1 KB (added by Viper007Bond, 12 years ago)

Allow non-admins to use Vimeo and allow regex in oEmbed URL formats

  • wp-includes/class-oembed.php

     
    3333         * @uses apply_filters() Filters a list of pre-defined oEmbed providers.
    3434         */
    3535        function __construct() {
    36                 // List out some popular sites, mainly ones that don't have discovery tags in their <head>
    37                 // The WP_Embed class disables discovery for non-unfiltered_html users,
    38                 // so only providers in this array will be used for them.
     36                // List out some popular sites that support oEmbed.
     37                // The WP_Embed class disables discovery for non-unfiltered_html users, so only providers in this array will be used for them.
     38                // Add to this list using the wp_oembed_add_provider() function
    3939                $this->providers = apply_filters( 'oembed_providers', array(
    40                         'http://*.youtube.com/watch*' => 'http://www.youtube.com/oembed',
    41                         'http://youtube.com/watch*'   => 'http://www.youtube.com/oembed',
    42                         'http://blip.tv/file/*'       => 'http://blip.tv/oembed/',
    43                         'http://*.flickr.com/*'       => 'http://www.flickr.com/services/oembed/',
    44                         'http://www.hulu.com/watch/*' => 'http://www.hulu.com/api/oembed.{format}',
    45                         'http://*.viddler.com/*'      => 'http://lab.viddler.com/services/oembed/',
    46                         'http://qik.com/*'            => 'http://qik.com/api/oembed.{format}',
    47                         'http://*.revision3.com/*'    => 'http://revision3.com/api/oembed/',
    48 
    49                         // Vimeo uses the discovery <link>, so leave this commented to use it as a discovery test
    50                         //'http://www.vimeo.com/*'      => 'http://www.vimeo.com/api/oembed.{format}',
     40                        'http://www.youtube.com/watch*'   => array( 'http://www.youtube.com/oembed',            false  ),
     41                        'http://blip.tv/file/*'           => array( 'http://blip.tv/oembed/',                   false ),
     42                        '#http://(www\.)?vimeo\.com/.*#i' => array( 'http://www.vimeo.com/api/oembed.{format}', true  ),
     43                        'http://*.flickr.com/*'           => array( 'http://www.flickr.com/services/oembed/',   false ),
     44                        'http://www.hulu.com/watch/*'     => array( 'http://www.hulu.com/api/oembed.{format}',  false ),
     45                        'http://*.viddler.com/*'          => array( 'http://lab.viddler.com/services/oembed/',  false ),
     46                        'http://qik.com/*'                => array( 'http://qik.com/api/oembed.{format}',       false ),
     47                        'http://*.revision3.com/*'        => array( 'http://revision3.com/api/oembed/',         false ),
    5148                ) );
    5249        }
    5350
     
    6865                if ( !isset($args['discover']) )
    6966                        $args['discover'] = true;
    7067
    71                 foreach ( $this->providers as $matchmask => $providerurl ) {
     68                foreach ( $this->providers as $matchmask => $data ) {
     69                        list( $providerurl, $regex ) = $data;
     70
    7271                        // Turn the asterisk-type provider URLs into regex
    73                         $regex = '#' . str_replace( '___wildcard___', '(.+)', preg_quote( str_replace( '*', '___wildcard___', $matchmask ), '#' ) ) . '#i';
     72                        if ( !$regex )
     73                                $matchmask = '#' . str_replace( '___wildcard___', '(.+)', preg_quote( str_replace( '*', '___wildcard___', $matchmask ), '#' ) ) . '#i';
    7474
    75                         if ( preg_match( $regex, $url ) ) {
     75                        if ( preg_match( $matchmask, $url ) ) {
    7676                                $provider = str_replace( '{format}', 'json', $providerurl ); // JSON is easier to deal with than XML
    7777                                break;
    7878                        }
  • wp-includes/media.php

     
    12621262 *
    12631263 * @uses _wp_oembed_get_object()
    12641264 *
    1265  * @param string $format The format of URL that this provider can handle. Use asterisks as wildcards.
     1265 * @param string $format The format of URL that this provider can handle. You can use asterisks as wildcards.
    12661266 * @param string $provider The URL to the oEmbed provider.
     1267 * @param boolean $regex Whether the $format parameter is in a regex format or not.
    12671268 */
    1268 function wp_oembed_add_provider( $format, $provider ) {
     1269function wp_oembed_add_provider( $format, $provider, $regex = false ) {
    12691270        require_once( 'class-oembed.php' );
    12701271        $oembed = _wp_oembed_get_object();
    1271         $oembed->providers[$format] = $provider;
     1272        $oembed->providers[$format] = array( $provider, $regex );
    12721273}