WordPress.org

Make WordPress Core

Ticket #30346: 30346.2.patch

File 30346.2.patch, 649 bytes (added by bradyvercher, 7 years ago)
  • src/wp-includes/media.php

    diff --git src/wp-includes/media.php src/wp-includes/media.php
    index 48be78e..32eef2e 100644
    function attachment_url_to_postid( $url ) { 
    32693269        global $wpdb;
    32703270
    32713271        $dir = wp_upload_dir();
    3272         $path = ltrim( $url, $dir['baseurl'] . '/' );
     3272
     3273        if ( 0 === strpos( $url, $dir['baseurl'] . '/' ) ) {
     3274                $url = substr( $url, strlen( $dir['baseurl'] . '/' ) );
     3275        }
    32733276
    32743277        $sql = $wpdb->prepare(
    32753278                "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wp_attached_file' AND meta_value = %s",
    3276                 $path
     3279                $url
    32773280        );
    32783281        $post_id = $wpdb->get_var( $sql );
    32793282        if ( ! empty( $post_id ) ) {