WordPress.org

Make WordPress Core


Ignore:
Timestamp:
09/25/2012 07:10:09 AM (7 years ago)
Author:
nacin
Message:

Always attempt to embed URLs in content, removing the Auto-embeds (autoembed_urls) option.

Remove the UI for setting the default width and height for embeds. Width was confusing as it
was blank by default (inheriting the content width from the theme, or 500px). The height is
now calculated as 1.5x the content width, or 1000px, whichever is smaller.

The [embed] shortcode can still receive manual height and width attributes. This just removes
the global settings.

props wonderboymusic. see #21719.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/media.php

    r21948 r21998  
    10821082    function __construct() {
    10831083        // Hack to get the [embed] shortcode to run before wpautop()
    1084         add_filter( 'the_content', array(&$this, 'run_shortcode'), 8 );
     1084        add_filter( 'the_content', array( $this, 'run_shortcode' ), 8 );
    10851085
    10861086        // Shortcode placeholder for strip_shortcodes()
     
    10881088
    10891089        // Attempts to embed all URLs in a post
    1090         if ( get_option('embed_autourls') )
    1091             add_filter( 'the_content', array(&$this, 'autoembed'), 8 );
     1090        add_filter( 'the_content', array( $this, 'autoembed' ), 8 );
    10921091
    10931092        // After a post is saved, invalidate the oEmbed cache
    1094         add_action( 'save_post', array(&$this, 'delete_oembed_caches') );
     1093        add_action( 'save_post', array( $this, 'delete_oembed_caches' ) );
    10951094
    10961095        // After a post is saved, cache oEmbed items via AJAX
    1097         add_action( 'edit_form_advanced', array(&$this, 'maybe_run_ajax_cache') );
     1096        add_action( 'edit_form_advanced', array( $this, 'maybe_run_ajax_cache' ) );
    10981097    }
    10991098
     
    11201119        remove_all_shortcodes();
    11211120
    1122         add_shortcode( 'embed', array(&$this, 'shortcode') );
     1121        add_shortcode( 'embed', array( $this, 'shortcode' ) );
    11231122
    11241123        // Do the shortcode (only the [embed] one is registered)
     
    12941293
    12951294            $content = $this->run_shortcode( $post->post_content );
    1296             if ( get_option('embed_autourls') )
    1297                 $this->autoembed( $content );
     1295            $this->autoembed( $content );
    12981296
    12991297            $this->usecache = true;
     
    13101308     */
    13111309    function autoembed( $content ) {
    1312         return preg_replace_callback( '|^\s*(https?://[^\s"]+)\s*$|im', array(&$this, 'autoembed_callback'), $content );
     1310        return preg_replace_callback( '|^\s*(https?://[^\s"]+)\s*$|im', array( $this, 'autoembed_callback' ), $content );
    13131311    }
    13141312
     
    13681366 * Create default array of embed parameters.
    13691367 *
     1368 * The width defaults to the content width as specified by the theme. If the
     1369 * theme does not specify a content width, then 500px is used.
     1370 *
     1371 * The default height is 1.5 times the width, or 1000px, whichever is smaller.
     1372 *
     1373 * The 'embed_defaults' filter can be used to adjust either of these values.
     1374 *
    13701375 * @since 2.9.0
    13711376 *
     
    13731378 */
    13741379function wp_embed_defaults() {
    1375     if ( !empty($GLOBALS['content_width']) )
    1376         $theme_width = (int) $GLOBALS['content_width'];
    1377 
    1378     $width = get_option('embed_size_w');
    1379 
    1380     if ( empty($width) && !empty($theme_width) )
    1381         $width = $theme_width;
    1382 
    1383     if ( empty($width) )
     1380    if ( ! empty( $GLOBALS['content_width'] ) )
     1381        $width = (int) $GLOBALS['content_width'];
     1382
     1383    if ( empty( $width ) )
    13841384        $width = 500;
    13851385
    1386     $height = get_option('embed_size_h');
    1387 
    1388     if ( empty($height) )
    1389         $height = 700;
    1390 
    1391     return apply_filters( 'embed_defaults', array(
    1392         'width'  => $width,
    1393         'height' => $height,
    1394     ) );
     1386    $height = min( ceil( $width * 1.5 ), 1000 );
     1387
     1388    return apply_filters( 'embed_defaults', compact( 'width', 'height' ) );
    13951389}
    13961390
Note: See TracChangeset for help on using the changeset viewer.