WordPress.org

Make WordPress Core

Ticket #11452: _wp_attached_file.3.diff

File _wp_attached_file.3.diff, 2.9 KB (added by scribu, 8 years ago)

Pass $unfiltered to wp_get_attachment_metadata()

  • wp-includes/post.php

     
    4141 * @return string The file path to the attached file.
    4242 */
    4343function get_attached_file( $attachment_id, $unfiltered = false ) {
    44         $file = get_post_meta( $attachment_id, '_wp_attached_file', true );
     44        if ( !get_post( $attachment_id ) )
     45                return false;
     46
     47        $data = wp_get_attachment_metadata($attachment_id, $unfiltered);
     48        $file = @$data['file'];
     49
    4550        // If the file is relative, prepend upload dir
    4651        if ( 0 !== strpos($file, '/') && !preg_match('|^.:\\\|', $file) && ( ($uploads = wp_upload_dir()) && false === $uploads['error'] ) )
    4752                $file = $uploads['basedir'] . "/$file";
     53
    4854        if ( $unfiltered )
    4955                return $file;
     56
    5057        return apply_filters( 'get_attached_file', $file, $attachment_id );
    5158}
    5259
     
    6774        if ( !get_post( $attachment_id ) )
    6875                return false;
    6976
     77        $data = wp_get_attachment_metadata($attachment_id);
     78
    7079        $file = apply_filters( 'update_attached_file', $file, $attachment_id );
    7180        $file = _wp_relative_upload_path($file);
    7281
    73         return update_post_meta( $attachment_id, '_wp_attached_file', $file );
     82        $data['file'] = $file;
     83
     84        return wp_update_attachment_metadata($attachment_id, $data);
    7485}
    7586
    7687/**
     
    29692980                return false;
    29702981
    29712982        $url = '';
    2972         if ( $file = get_post_meta( $post->ID, '_wp_attached_file', true) ) { //Get attached file
     2983        if ( $file = get_attached_file($post->ID) ) { //Get attached file
    29732984                if ( ($uploads = wp_upload_dir()) && false === $uploads['error'] ) { //Get upload directory
    29742985                        if ( 0 === strpos($file, $uploads['basedir']) ) //Check that the upload base exists in the file location
    29752986                                $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}";