Opened 4 weeks ago
Last modified 3 weeks ago
#41753 reopened enhancement
_wp_get_attachment_relative_path uses hardcoded uploads directory path
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Awaiting Review | Priority: | normal |
| Severity: | normal | Version: | 4.7.4 |
| Component: | Media | Keywords: | has-patch |
| Focuses: | Cc: |
Description
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, '/' );
}
Attachments (2)
Change History (4)
#1
@nikolastoqnow
3 weeks ago
- Keywords has-patch added
- Resolution set to invalid
- Status changed from new to closed
#2
@nikolastoqnow
3 weeks ago
- Resolution invalid deleted
- Status changed from closed to reopened
Note: See
TracTickets for help on using
tickets.
The correct patch file