[wp-trac] [WordPress Trac] #41753: _wp_get_attachment_relative_path uses hardcoded uploads directory path

WordPress Trac noreply at wordpress.org
Tue Aug 29 15:55:56 UTC 2017


#41753: _wp_get_attachment_relative_path uses hardcoded uploads directory path
-------------------------+-----------------------------
 Reporter:  nedga055     |      Owner:
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  Media        |    Version:  4.7.4
 Severity:  normal       |   Keywords:
  Focuses:               |
-------------------------+-----------------------------
 I'm using a theme that in turn uses the _wp_get_attachment_relative_path
 to help generate paths to uploaded images.

 However, because my WordPress install changes the uploads directory path,
 the function returns the file system path for the attachment rather than
 then relative path within the uploads directory as expected, which
 ultimately breaks the intended functionality.

 In _wp_get_attachment_relative_path, would it make sense to do something
 like the following instead of hard coding 'wp-content/uploads':

 {{{
 $uploads_dir = wp_upload_dir();
 $uploads_basedir = $uploads_dir['basedir'];
 if ( false !== strpos( $dirname, $uploads_basedir ) ) {
         // Get the directory name relative to the upload directory (back
 compat for pre-2.7 uploads)
         $dirname = substr( $dirname, strpos( $dirname, $uploads_basedir )
 + strlen($uploads_basedir) );
         $dirname = ltrim( $dirname, '/' );
 }
 }}}

--
Ticket URL: <https://core.trac.wordpress.org/ticket/41753>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list