WordPress.org

Make WordPress Core

Ticket #11452: _wp_attached_file.diff

File _wp_attached_file.diff, 1.8 KB (added by scribu, 4 years ago)

Replace get_post_meta($id, '_wp_attached_file') with get_attached file()

  • wp-includes/post.php

     
    29692969                return false; 
    29702970 
    29712971        $url = ''; 
    2972         if ( $file = get_post_meta( $post->ID, '_wp_attached_file', true) ) { //Get attached file 
     2972        if ( $file = get_attached_file($post->ID) ) { //Get attached file 
    29732973                if ( ($uploads = wp_upload_dir()) && false === $uploads['error'] ) { //Get upload directory 
    29742974                        if ( 0 === strpos($file, $uploads['basedir']) ) //Check that the upload base exists in the file location 
    29752975                                $url = str_replace($uploads['basedir'], $uploads['baseurl'], $file); //replace file location with url location 
  • wp-app.php

     
    720720                        $this->auth_required(__('Sorry, you do not have the right to delete this post.')); 
    721721                } 
    722722 
    723                 $location = get_post_meta($entry['ID'], '_wp_attached_file', true); 
     723                $location = get_attached_file($entry['ID']); 
    724724                $filetype = wp_check_filetype($location); 
    725725 
    726726                if(!isset($location) || 'attachment' != $entry['post_type'] || empty($filetype['ext'])) 
     
    758758                        $this->auth_required(__('Sorry, you do not have the right to edit this post.')); 
    759759                } 
    760760 
    761                 $location = get_post_meta($entry['ID'], '_wp_attached_file', true); 
     761                $location = get_attached_file($entry['ID']); 
    762762                $location = get_option ('upload_path') . '/' . $location; 
    763763                $filetype = wp_check_filetype($location); 
    764764 
     
    810810                } 
    811811 
    812812                $upload_dir = wp_upload_dir( ); 
    813                 $location = get_post_meta($entry['ID'], '_wp_attached_file', true); 
     813                $location = get_attached_file($entry['ID']); 
    814814                $filetype = wp_check_filetype($location); 
    815815 
    816816                $location = "{$upload_dir['basedir']}/{$location}";