WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 6 years ago

#7622 closed defect (bug) (fixed)

wp_get_attachment_url() uses the GUID as the URL

Reported by: DD32 Owned by:
Milestone: 2.7 Priority: normal
Severity: normal Version: 2.7
Component: Template Keywords: has-patch blessed
Focuses: Cc:

Description

At present wp_get_attachment_url() relies upon the GUID for the URL of the attachment, As discussed on wp-hackers ("Re: [wp-hackers] Re: permalinks redirected despite WP_SITEURL") this shouldnt be done due to the fact that it just so happens that the guid is the url in wordpress

The attached patch attempts to use the attachment metadata to workout the files location, followed by using the filtered uploads directory to determine the real location (See comments in patch).

Attachments (4)

7622.diff (1.1 KB) - added by DD32 6 years ago.
7622.2.diff (1.1 KB) - added by DD32 6 years ago.
7622.3.diff (2.9 KB) - added by ryan 6 years ago.
Make attachment file path relative to the upload dir
7622.patch (1.6 KB) - added by DD32 6 years ago.

Download all attachments as: .zip

Change History (12)

DD326 years ago

comment:1 DD326 years ago

A possibly better option would be to use _wp_attached_file metadata, see the attached patch.

Also note, That in the event the metadata fails, the uploads folder is not located, or the file does not exist within the uploads folder, it fails back to using the GUID

DD326 years ago

comment:2 ryan6 years ago

  • Keywords blessed added

Definitely needs to be done. I'll try it out.

ryan6 years ago

Make attachment file path relative to the upload dir

comment:3 ryan6 years ago

I expanded the patch so that files are saved to attachment meta data with paths relative to upload dir rather than absolute paths. That makes it much easier to change your content dir location or move your blog to another host.

comment:4 ryan6 years ago

(In [8796]) Make attachment file path relative to the upload dir. Don't use GUID to find attachement URL. Props DD32. see #7622

comment:5 DD326 years ago

Changeset broke image thumbnail creation. (The full path is not passed to the image creation functions)

attached patch fixes it.

DD326 years ago

comment:6 DD326 years ago

Looks like it also broke the exif retrieval, Patch refreshed with extra change.

comment:7 ryan6 years ago

(In [8879]) Thumbnail and exif fixes from DD32. see #7622

comment:8 DD326 years ago

  • Resolution set to fixed
  • Status changed from new to closed

WP no longer relies on the GUID for the attachment url (but falls back to it), And it seems like the bugs caused by it have been fixed up, So closing as fixed.

Note: See TracTickets for help on using tickets.