WordPress.org

Make WordPress Core

Ticket #24458: 24458.5.diff

File 24458.5.diff, 2.7 KB (added by wonderboymusic, 8 years ago)
  • wp-includes/media.php

    diff --git a/wp-includes/media.php b/wp-includes/media.php
    index e63e5bb..3722521 100644
    a b function wp_embed_handler_video( $matches, $attr, $url, $rawattr ) { 
    13851385        if ( ! empty( $rawattr['width'] ) && ! empty( $rawattr['height'] ) ) {
    13861386                $dimensions .= sprintf( 'width="%d" ', (int) $rawattr['width'] );
    13871387                $dimensions .= sprintf( 'height="%d" ', (int) $rawattr['height'] );
    1388         } elseif ( strstr( $url, home_url() ) ) {
    1389                 $id = attachment_url_to_postid( $url );
    1390                 if ( ! empty( $id ) ) {
    1391                         $meta = wp_get_attachment_metadata( $id );
    1392                         if ( ! empty( $meta['width'] ) )
    1393                                 $dimensions .= sprintf( 'width="%d" ', (int) $meta['width'] );
    1394                         if ( ! empty( $meta['height'] ) )
    1395                                 $dimensions .= sprintf( 'height="%d" ', (int) $meta['height'] );
    1396                 }
    13971388        }
    1398 
    13991389        $video = sprintf( '[video %s src="%s" /]', $dimensions, esc_url( $url ) );
    14001390        return apply_filters( 'wp_embed_handler_video', $video, $attr, $url, $rawattr );
    14011391}
    function the_post_format_image( $attached_size = 'full' ) { 
    24712461}
    24722462
    24732463/**
    2474  * Retrieve the post id for an attachment file URL
    2475  *
    2476  * @since 3.6.0
    2477  *
    2478  * @param string $url Permalink to check.
    2479  * @return int Post ID, or 0 on failure.
    2480  */
    2481 function attachment_url_to_postid( $url ) {
    2482         global $wpdb;
    2483         if ( preg_match( '#\.[a-zA-Z0-9]+$#', $url ) ) {
    2484                 $id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type = 'attachment' " .
    2485                         "AND guid = %s", $url ) );
    2486 
    2487                 if ( ! empty( $id ) )
    2488                         return (int) $id;
    2489         }
    2490 
    2491         return 0;
    2492 }
    2493 
    2494 /**
    24952464 * Retrieve the attachment post id from HTML containing an image.
    24962465 *
    24972466 * @since 3.6.0
    function img_html_to_post_id( $html, &$matched_html = null ) { 
    25092478
    25102479        $matched_html = $matches[0];
    25112480
    2512         // Look for attributes.
    2513         if ( ! preg_match_all( '#(src|class)=([\'"])(.+?)\2#is', $matched_html, $matches ) || empty( $matches ) )
     2481        // Look for the class attribute.
     2482        if ( ! preg_match( '#class=([\'"])(.+?)\1#is', $matched_html, $matches ) || empty( $matches ) )
    25142483                return $attachment_id;
    25152484
    2516         $attr = array();
    2517         foreach ( $matches[1] as $key => $attribute_name )
    2518                 $attr[ $attribute_name ] = $matches[3][ $key ];
    2519 
    2520         if ( ! empty( $attr['class'] ) && false !== strpos( $attr['class'], 'wp-image-' ) )
    2521                 if ( preg_match( '#wp-image-([0-9]+)#i', $attr['class'], $matches ) )
     2485        $classes = $matches[2];
     2486        if ( ! empty( $classes ) && false !== strpos( $classes, 'wp-image-' ) )
     2487                if ( preg_match( '#wp-image-([0-9]+)#i', $classes, $matches ) )
    25222488                        $attachment_id = absint( $matches[1] );
    25232489
    2524         if ( ! $attachment_id && ! empty( $attr['src'] ) )
    2525                 $attachment_id = attachment_url_to_postid( $attr['src'] );
    2526 
    25272490        return $attachment_id;
    25282491}