Make WordPress Core


Ignore:
Timestamp:
04/11/2013 10:34:05 PM (12 years ago)
Author:
markjaquith
Message:

Enforce video dimensions.

props wonderboymusic. see #23831.

File:
1 edited

Legend:

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

    r23938 r23969  
    16391639
    16401640        $response = array_merge( $response, array( 'sizes' => $sizes ), $sizes['full'] );
     1641    } elseif ( $meta && 'video' === $type ) {
     1642        if ( isset( $meta['width'] ) )
     1643            $response['width'] = (int) $meta['width'];
     1644        if ( isset( $meta['height'] ) )
     1645            $response['height'] = (int) $meta['height'];
    16411646    }
    16421647
     
    20152020            $dimensions .= sprintf( 'width="%d" ', (int) $rawattr['width'] );
    20162021            $dimensions .= sprintf( 'height="%d" ', (int) $rawattr['height'] );
     2022        } elseif ( strstr( $url, home_url() ) ) {
     2023            $id = attachment_url_to_postid( $url );
     2024            if ( ! empty( $id ) ) {
     2025                $meta = wp_get_attachment_metadata( $id );
     2026                if ( ! empty( $meta['width'] ) )
     2027                    $dimensions .= sprintf( 'width="%d" ', (int) $meta['width'] );
     2028                if ( ! empty( $meta['height'] ) )
     2029                    $dimensions .= sprintf( 'height="%d" ', (int) $meta['height'] );
     2030            }
    20172031        }
    20182032        $video = do_shortcode( '[video ' . $dimensions . 'src="' . $url . '" /]' );
     
    24392453    echo get_the_post_format_image( $attached_size );
    24402454}
     2455
     2456/**
     2457 * Retrieve the post id for an attachment file URL
     2458 *
     2459 * @since 3.6.0
     2460 *
     2461 * @param string $url Permalink to check.
     2462 * @return int Post ID, or 0 on failure.
     2463 */
     2464function attachment_url_to_postid( $url ) {
     2465    global $wpdb;
     2466    if ( preg_match( '#\.[a-zA-Z0-9]+$#', $url ) ) {
     2467        $id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type = 'attachment' " .
     2468            "AND guid = %s", $url ) );
     2469
     2470        if ( ! empty( $id ) )
     2471            return (int) $id;
     2472    }
     2473
     2474    return 0;
     2475}
Note: See TracChangeset for help on using the changeset viewer.