WordPress.org

Make WordPress Core

Ticket #26992: wp_get_attachment_url.patch

File wp_get_attachment_url.patch, 1.0 KB (added by wpdavis, 6 years ago)
  • wp-includes/post.php

     
    49274927        // Get attached file.
    49284928        if ( $file = get_post_meta( $post->ID, '_wp_attached_file', true) ) {
    49294929                // Get upload directory.
    4930                 if ( ($uploads = wp_upload_dir()) && false === $uploads['error'] ) {
     4930                if ( ($uploads = wp_upload_dir()) ) {
    49314931                        // Check that the upload base exists in the file location.
    49324932                        if ( 0 === strpos( $file, $uploads['basedir'] ) ) {
    49334933                                // Replace file location with url location.
    49344934                                $url = str_replace($uploads['basedir'], $uploads['baseurl'], $file);
    49354935                        } elseif ( false !== strpos($file, 'wp-content/uploads') ) {
    49364936                                $url = $uploads['baseurl'] . substr( $file, strpos($file, 'wp-content/uploads') + 18 );
    4937                         } else {
     4937                        } elseif( false !== $uploads['error'] ) {
    49384938                                // It's a newly-uploaded file, therefore $file is relative to the basedir.
    49394939                                $url = $uploads['baseurl'] . "/$file";
    49404940                        }