WordPress.org

Make WordPress Core

Ticket #14148: post.php.patch

File post.php.patch, 1.6 KB (added by danorton, 8 years ago)
  • wp-includes/post.php

     
    35603560        return update_post_meta( $post->ID, '_wp_attachment_metadata', $data);
    35613561}
    35623562
     3563
     3564function _wp_get_url_from_filesystem_path($path) {
     3565  $filesystem_elements = explode('/',$path);
     3566  $url_elements = array();
     3567  foreach($filesystem_elements as $link) {
     3568        $url_elements[] = rawurlencode($link);
     3569  }
     3570  return implode('/',$url_elements);
     3571}
     3572
     3573
    35633574/**
    35643575 * Retrieve the URL for an attachment.
    35653576 *
     
    35763587        $url = '';
    35773588        if ( $file = get_post_meta( $post->ID, '_wp_attached_file', true) ) { //Get attached file
    35783589                if ( ($uploads = wp_upload_dir()) && false === $uploads['error'] ) { //Get upload directory
    3579                         if ( 0 === strpos($file, $uploads['basedir']) ) //Check that the upload base exists in the file location
    3580                                 $url = str_replace($uploads['basedir'], $uploads['baseurl'], $file); //replace file location with url location
    3581                         elseif ( false !== strpos($file, 'wp-content/uploads') )
    3582                                 $url = $uploads['baseurl'] . substr( $file, strpos($file, 'wp-content/uploads') + 18 );
    3583                         else
    3584                                 $url = $uploads['baseurl'] . "/$file"; //Its a newly uploaded file, therefor $file is relative to the basedir.
     3590                        if ( 0 === strpos($file, $uploads['basedir']) ) { //Check that the upload base exists in the file location
     3591                                $relative_path = substr($file,strlen($uploads['basedir'])+1);
     3592                        }
     3593                        elseif ( false !== strpos($file, 'wp-content/uploads') ) {
     3594                                $relative_path = substr($file,strpos($file, 'wp-content/uploads') + 19 );
     3595                        }
     3596                        else {
     3597                                $relative_path = $file;
     3598                        }
     3599                        $url = $uploads['baseurl'] . "/" . _wp_get_url_from_filesystem_path($relative_path);
    35853600                }
    35863601        }
    35873602