WordPress.org

Make WordPress Core

Opened 2 years ago

Closed 2 years ago

Last modified 2 years ago

#24258 closed defect (bug) (duplicate)

PHP notices throws when the attachment parent not exists

Reported by: alex-ye Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.5.1
Component: Media Keywords: has-patch
Focuses: Cc:

Description

Some functions throws PHP notices when the attachment parent not exists ( the attachment have a value for a parent post but this post removed by any reason ).

like:
get_attachment_link()
WP_Media_List_Table=>display_rows()

Attachments (3)

link-template.patch (2.4 KB) - added by alex-ye 2 years ago.
class-wp-media-list-table.patch (1.6 KB) - added by alex-ye 2 years ago.
24258.diff (1.9 KB) - added by adamsilverstein 2 years ago.

Download all attachments as: .zip

Change History (10)

@alex-ye2 years ago

comment:1 follow-up: @alex-ye2 years ago

  • Version set to 3.5.1

@adamsilverstein2 years ago

comment:2 in reply to: ↑ 1 @adamsilverstein2 years ago

  • Keywords dev-feedback added

Replying to alex-ye:

thank you for contributing the bug report _and_ a patch! bravo!

a few notes:

  • its best to generate your patches from wp root, this makes applying easier
  • you can combine all your file updates into a single patch (same reason)
  • watch out for spaces vs. tabs, you might want to turn these on visually in your editor; your patch files had many lines indented with spaces - check the php coding standards

24258.diff​ refactors your patches and is generated from the root, also cleans up spaces vs. tabs issue and a little OCD space cleanup on the get_attachment_link since we were in there anyway (although you don't usually need to clean up old code that isn't to standard)

comment:3 @adamsilverstein2 years ago

  • Cc adamsilverstein@… added

comment:4 @SergeyBiryukov2 years ago

  • Keywords dev-feedback removed
  • Milestone Awaiting Review deleted
  • Status changed from new to closed

Thanks for the contribution. This is, however, a duplicate of #23154.

Version 0, edited 2 years ago by SergeyBiryukov (next)

comment:5 @SergeyBiryukov2 years ago

  • Resolution set to duplicate

comment:6 @alex-ye2 years ago

Thanks for your reply @adamsilverstein you really helps me :)

@SergeyBiryukov mmm, can apply the patch:
http://core.trac.wordpress.org/attachment/ticket/24258/24258.diff

Insted of
http://core.trac.wordpress.org/attachment/ticket/23154/23154.diff

I think the @adamsilverstein patch is better.

comment:7 @SergeyBiryukov2 years ago

See the combined patch in #23154.

if ( empty( $post ) ) check in get_attachment_link() from 24258.diff probably makes sense, but it should return a string instead of null to be in line with the function's PHPDocs, and should be consistent with other get_*_link() functions, so it's better to address that in a separate ticket.

Last edited 2 years ago by SergeyBiryukov (previous) (diff)
Note: See TracTickets for help on using tickets.