Make WordPress Core


Ignore:
Timestamp:
07/03/2013 08:23:48 PM (13 years ago)
Author:
nacin
Message:

Remove attachment_url_to_postid(). props kovshenin, wonderboymusic. see #24458.

File:
1 edited

Legend:

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

    r24547 r24548  
    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                 }
    1397         }
    1398 
     1388        }
    13991389        $video = sprintf( '[video %s src="%s" /]', $dimensions, esc_url( $url ) );
    14001390        return apply_filters( 'wp_embed_handler_video', $video, $attr, $url, $rawattr );
     
    24892479
    24902480/**
    2491  * Retrieve the post id for an attachment file URL
    2492  *
    2493  * @since 3.6.0
    2494  *
    2495  * @param string $url Permalink to check.
    2496  * @return int Post ID, or 0 on failure.
    2497  */
    2498 function attachment_url_to_postid( $url ) {
    2499         global $wpdb;
    2500         if ( preg_match( '#\.[a-zA-Z0-9]+$#', $url ) ) {
    2501                 $id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type = 'attachment' " .
    2502                         "AND guid = %s", $url ) );
    2503 
    2504                 if ( ! empty( $id ) )
    2505                         return (int) $id;
    2506         }
    2507 
    2508         return 0;
    2509 }
    2510 
    2511 /**
    25122481 * Retrieve the attachment post id from HTML containing an image.
    25132482 *
     
    25272496        $matched_html = $matches[0];
    25282497
    2529         // Look for attributes.
    2530         if ( ! preg_match_all( '#(src|class)=([\'"])(.+?)\2#is', $matched_html, $matches ) || empty( $matches ) )
     2498        // Look for the class attribute.
     2499        if ( ! preg_match( '#class=([\'"])(.+?)\1#is', $matched_html, $matches ) || empty( $matches ) )
    25312500                return $attachment_id;
    25322501
    2533         $attr = array();
    2534         foreach ( $matches[1] as $key => $attribute_name )
    2535                 $attr[ $attribute_name ] = $matches[3][ $key ];
    2536 
    2537         if ( ! empty( $attr['class'] ) && false !== strpos( $attr['class'], 'wp-image-' ) )
    2538                 if ( preg_match( '#wp-image-([0-9]+)#i', $attr['class'], $matches ) )
     2502        $classes = $matches[2];
     2503        if ( ! empty( $classes ) && false !== strpos( $classes, 'wp-image-' ) )
     2504                if ( preg_match( '#wp-image-([0-9]+)#i', $classes, $matches ) )
    25392505                        $attachment_id = absint( $matches[1] );
    25402506
    2541         if ( ! $attachment_id && ! empty( $attr['src'] ) )
    2542                 $attachment_id = attachment_url_to_postid( $attr['src'] );
    2543 
    25442507        return $attachment_id;
    25452508}
Note: See TracChangeset for help on using the changeset viewer.