WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 3 years ago

#37343 closed defect (bug) (fixed)

wp_get_attachment_link() outputs nothing if the attachment post has no title

Reported by: henry.wright Owned by: wonderboymusic
Milestone: 4.7 Priority: normal
Severity: normal Version: 4.5.3
Component: Media Keywords: has-patch
Focuses: Cc:

Description

wp_get_attachment_link() fails to output if the attachment post doesn't have a title.

This doesn't apply to image attachments, but it does apply to PDFs etc.

Attachments (6)

37343-01.patch (423 bytes) - added by Jonnyauk 3 years ago.
Adds additional check if no title set on non-image attachment, and sets filename as fallback
37343-02.patch (395 bytes) - added by Jonnyauk 3 years ago.
Correct file path reference
37343-03.patch (530 bytes) - added by Jonnyauk 3 years ago.
Updated patch file in correct format (trunk dev version)
37343.diff (585 bytes) - added by henry.wright 3 years ago.
37343-05.patch (552 bytes) - added by Jonnyauk 3 years ago.
@henry.wright - nice - looks a-little neater as a fallback, I've submitted a new patch (37343-05.patch) which retains the original title, which should be used if available.
37343.2.diff (1.1 KB) - added by wonderboymusic 3 years ago.

Download all attachments as: .zip

Change History (14)

#1 @SergeyBiryukov
3 years ago

  • Component changed from General to Media

#2 @Jonnyauk
3 years ago

Confirmed - I've replicated this issue with a non-image file (PDF) with no post title where wp_get_attachment_link() doesn't return link, but it functions correctly with a non-titled image file.

Version 0, edited 3 years ago by Jonnyauk (next)

@Jonnyauk
3 years ago

Adds additional check if no title set on non-image attachment, and sets filename as fallback

@Jonnyauk
3 years ago

Correct file path reference

#3 @Jonnyauk
3 years ago

  • Keywords has-patch added
  • Version set to 4.5.3

#4 @SergeyBiryukov
3 years ago

  • Keywords needs-refresh added

37343-02.patch looks reversed. Also, please create patches from the root directory of the repository.

@Jonnyauk
3 years ago

Updated patch file in correct format (trunk dev version)

#5 @henry.wright
3 years ago

@Jonnyauk what are your thoughts on using the attachment's file name instead of the guid? Patch incoming...

@henry.wright
3 years ago

@Jonnyauk
3 years ago

@henry.wright - nice - looks a-little neater as a fallback, I've submitted a new patch (37343-05.patch) which retains the original title, which should be used if available.

#6 @henry.wright
3 years ago

Looks good to me! 😃

#7 @wonderboymusic
3 years ago

  • Keywords needs-refresh removed
  • Milestone changed from Awaiting Review to 4.7
  • Owner set to wonderboymusic
  • Status changed from new to assigned

#8 @wonderboymusic
3 years ago

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

In 38295:

Media: wp_get_attachment_link() fails to output text for non-images if the attachment post doesn't have a title and $text (argument #5) was not passed to the func. In this case, use the filename.

Props Jonnyauk, henry.wright.
Fixes #37343.

Note: See TracTickets for help on using tickets.