WordPress.org

Make WordPress Core

Ticket #10337: 10337.youtubeoembedandtweaks.patch

File 10337.youtubeoembedandtweaks.patch, 6.2 KB (added by Viper007Bond, 12 years ago)

Switches YouTube to using oEmbed, adds easier way to add a new oEmbed provider URL, and some phpdoc improvements

  • wp-includes/capabilities.php

     
    962962/**
    963963 * Whether author of supplied post has capability or role.
    964964 *
    965  * @since 2.9
     965 * @since 2.9.0
    966966 *
    967967 * @param int|object $post Post ID or post object.
    968968 * @param string $capability Capability or role name.
  • wp-includes/class-oembed.php

     
    3737                // The WP_Embed class disables discovery for non-unfiltered_html users,
    3838                // so only providers in this array will be used for them.
    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',
    4042                        'http://blip.tv/file/*'       => 'http://blip.tv/oembed/',
    4143                        'http://*.flickr.com/*'       => 'http://www.flickr.com/services/oembed/',
     44                        'http://www.hulu.com/watch/*' => 'http://www.hulu.com/api/oembed.{format}',
    4245                        'http://*.viddler.com/*'      => 'http://lab.viddler.com/services/oembed/',
    4346                        'http://qik.com/*'            => 'http://qik.com/api/oembed.{format}',
    4447                        'http://*.revision3.com/*'    => 'http://revision3.com/api/oembed/',
    45                         'http://www.hulu.com/watch/*' => 'http://www.hulu.com/api/oembed.{format}',
    4648
    4749                        // Vimeo uses the discovery <link>, so leave this commented to use it as a discovery test
    4850                        //'http://www.vimeo.com/*'      => 'http://www.vimeo.com/api/oembed.{format}',
  • wp-includes/default-embeds.php

     
    88 */
    99
    1010/**
    11  * The YouTube.com embed handler callback. YouTube does not support oEmbed and we want to provide extra customization.
    12  *
    13  * @see WP_Embed::register_handler()
    14  * @see WP_Embed::shortcode()
    15  *
    16  * @param array $matches The regex matches from the provided regex when calling {@link wp_embed_register_handler()}.
    17  * @param array $attr Embed attributes.
    18  * @param string $url The original URL that was matched by the regex.
    19  * @param array $rawattr The original unmodified attributes.
    20  * @return string The embed HTML.
    21  */
    22 function wp_embed_handler_youtube( $matches, $attr, $url, $rawattr ) {
    23         // If the user supplied a fixed width AND height, use it
    24         if ( !empty($rawattr['width']) && !empty($rawattr['height']) ) {
    25                 $width  = (int) $rawattr['width'];
    26                 $height = (int) $rawattr['height'];
    27         } else {
    28                 list( $width, $height ) = wp_expand_dimensions( 425, 344, $attr['width'], $attr['height'] );
    29         }
    30 
    31         return apply_filters( 'embed_youtube', '<object width="' . esc_attr($width) . '" height="' . esc_attr($height) . '"><param name="movie" value="http://www.youtube.com/v/' . esc_attr($matches[3]) . '&amp;hl=en&amp;fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/' . esc_attr($matches[3]) . '&amp;hl=en&amp;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="' . esc_attr($width) . '" height="' . esc_attr($height) . '"></embed></object>', $matches, $attr, $url, $rawattr );
    32 }
    33 wp_embed_register_handler( 'youtube', '#http://(www.youtube|youtube|[A-Za-z]{2}.youtube)\.com/(watch\?v=|w/\?v=|\?v=)([\w-]+)(.*?)#i', 'wp_embed_handler_youtube' );
    34 
    35 
    36 /**
    3711 * The Google Video embed handler callback. Google Video does not support oEmbed.
    3812 *
    3913 * @see WP_Embed::register_handler()
  • wp-includes/formatting.php

     
    23582358                case 'medium_size_h':
    23592359                case 'large_size_w':
    23602360                case 'large_size_h':
    2361                 //case 'embed_size_w':
    23622361                case 'embed_size_h':
    23632362                case 'default_post_edit_rows':
    23642363                case 'mailserver_port':
     
    23752374                        $value = absint( $value );
    23762375                        break;
    23772376
     2377                case 'embed_size_w':
     2378                        if ( '' !== $value )
     2379                                $value = absint( $value );
     2380                        break;
     2381
    23782382                case 'posts_per_page':
    23792383                case 'posts_per_rss':
    23802384                        $value = (int) $value;
  • wp-includes/media.php

     
    11341134/**
    11351135 * Register an embed handler. This function should probably only be used for sites that do not support oEmbed.
    11361136 *
     1137 * @since 2.9.0
    11371138 * @see WP_Embed::register_handler()
    11381139 */
    11391140function wp_embed_register_handler( $id, $regex, $callback, $priority = 10 ) {
     
    11441145/**
    11451146 * Unregister a previously registered embed handler.
    11461147 *
     1148 * @since 2.9.0
    11471149 * @see WP_Embed::unregister_handler()
    11481150 */
    11491151function wp_embed_unregister_handler( $id, $priority = 10 ) {
     
    11541156/**
    11551157 * Create default array of embed parameters.
    11561158 *
     1159 * @since 2.9.0
     1160 *
    11571161 * @return array Default embed parameters.
    11581162 */
    11591163function wp_embed_defaults() {
     
    11771181/**
    11781182 * Based on a supplied width/height example, return the biggest possible dimensions based on the max width/height.
    11791183 *
     1184 * @since 2.9.0
    11801185 * @uses wp_constrain_dimensions() This function passes the widths and the heights.
    11811186 *
    11821187 * @param int $example_width The width of an example embed.
     
    11971202/**
    11981203 * Attempts to fetch the embed HTML for a provided URL using oEmbed.
    11991204 *
     1205 * @since 2.9.0
    12001206 * @see WP_oEmbed
    12011207 *
    12021208 * @uses _wp_oembed_get_object()
     
    12111217        $oembed = _wp_oembed_get_object();
    12121218        return $oembed->get_html( $url, $args );
    12131219}
     1220
     1221/**
     1222 * Adds a URL format and oEmbed provider URL pair.
     1223 *
     1224 * @since 2.9.0
     1225 * @see WP_oEmbed
     1226 *
     1227 * @uses _wp_oembed_get_object()
     1228 *
     1229 * @param string $format The format of URL that this provider can handle. Use asterisks as wildcards.
     1230 * @param string $provider The URL to the oEmbed provider.
     1231 */
     1232function wp_oembed_addprovider( $format, $provider ) {
     1233        require_once( 'class-oembed.php' );
     1234        $oembed = _wp_oembed_get_object();
     1235        $oembed->providers[$format] = $provider;
     1236}