WordPress.org

Make WordPress Core

Ticket #7622: 7622.2.diff

File 7622.2.diff, 1.1 KB (added by DD32, 7 years ago)
  • wp-includes/post.php

     
    24502450        if ( !$post =& get_post( $post_id ) ) 
    24512451                return false; 
    24522452 
    2453         $url = get_the_guid( $post->ID ); 
     2453        $url = ''; 
     2454        if ( $file = get_post_meta( $post->ID, '_wp_attached_file', true) ) //Get attached file 
     2455                if ( ($uploads = wp_upload_dir()) && false === $uploads['error'] ) //Get upload directory 
     2456                        if ( 0 === strpos($file, $uploads['basedir']) ) //Check that the upload base exists in the file location 
     2457                                $url = str_replace($uploads['basedir'], $uploads['baseurl'], $file); //replace file location with url location 
    24542458 
    2455         if ( 'attachment' != $post->post_type || !$url ) 
     2459        if ( empty($url) ) //If any of the above options failed, Fallback on the GUID as used pre-2.7, not recomended to rely upon this. 
     2460                $url = get_the_guid( $post->ID ); 
     2461 
     2462        if ( 'attachment' != $post->post_type || empty($url) ) 
    24562463                return false; 
    24572464 
    24582465        return apply_filters( 'wp_get_attachment_url', $url, $post->ID );