Make WordPress Core

Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#28970 closed defect (bug) (invalid)

wp_get_attachment_url 0 === should be false ===

Reported by: brashell's profile brashell 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)

#1 @brashell
11 years ago

  • Keywords has-patch added

#2 @SergeyBiryukov
11 years ago

  • Keywords reporter-feedback added; has-patch removed

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.

I will also note this was uploaded via a plugin I made.

  1. Could you provide the uploading code from your plugin?
  2. What are $uploads['basedir'] and $uploads['baseurl'] values in your case?
  3. Does the issue happen with regular uploads?

#3 @brashell
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.

#4 @johnbillion
11 years ago

  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.