#28970 closed defect (bug) (invalid)
wp_get_attachment_url 0 === should be false ===
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 3.9.1 |
Component: | Media | Keywords: | reporter-feedback |
Focuses: | Cc: |
Description
wp_get_attachment_url() does this
if ( 0 === strpos($file, $uploads['basedir']) ) //Check that the upload base exists in the file location
which causes this to happen to media URL's on a multisite install.
http://mainsite.com/subsite/wp-content/uploads/sites/2/sites/2/2014/07/Some-PDF.pdf
The GUID in the database is correct though (http://mainsite.com/subsite/wp-content/uploads/sites/2/2014/07/Some-PDF.pdf), notice it's not /sites/2/sites/2/ I will also note this was uploaded via a plugin I made. When using false though, it works as it should and returns http://mainsite.com/subsite/wp-content/uploads/sites/2/2014/07/Some-PDF.pdf
if ( false === strpos($file, $uploads['basedir']) ) //Check that the upload base exists in the file location
Sorry, I am having trouble putting this into words and this is my first ticket, I think I put all the necessary details in though.
Change History (4)
#3
@
11 years ago
- Resolution set to invalid
- Status changed from new to closed
Well I just realized I did $file_return['url']
instead of $file_return['file']
in wp_insert_attachment and how dumb that was. It made it so the _wp_attached_file was http://mainsite.com/subsite/wp-content/uploads/sites/2/sites/2/2014/07/Some-PDF.pdf instead of 2014/07/Some-PDF.pdf I am really sorry about this and for wasting your time, it was such a simple oversight. Now that I think about it, it might be a good idea to automatically fix this for people in the future. Remove the URL and leave just the path like its supposed to be. I guess I will just have to live and learn and this will help someone in the future hopefully.
The code (introduced in [8796]) is correct.
We check if
$uploads['basedir']
exists in$file
, and if it does, we replace it with$uploads['baseurl']
. Replacing it if it does not exist would not make any sense.$uploads['basedir']
and$uploads['baseurl']
values in your case?