Make WordPress Core

Opened 6 years ago

Last modified 12 months ago

#44497 new defect (bug)

get_page_link() doesn't check if a valid post object is returned before trying to access its properties

Reported by: rodrigosprimo's profile rodrigosprimo Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Posts, Post Types Keywords: has-patch
Focuses: Cc:

Description

If get_page_link() receives an invalid post ID as the first parameter it will generate a PHP notice:

$ wp shell
>>> get_page_link( -1 )
PHP Notice:  Trying to get property of non-object in /vagrant/www/wccore/htdocs/wp-includes/link-template.php on line 317

Should a check be added to prevent this notice from happening? I'm happy to submit a patch. I'm just not sure what is the best way to handle this. Should the function return null if get_post() can't find a valid post? Should it call _doing_it_wrong()? Something else?

Attachments (2)

44497.diff (518 bytes) - added by bartech101 6 years ago.
44497.patch (638 bytes) - added by bartech101 6 years ago.

Download all attachments as: .zip

Change History (5)

@bartech101
6 years ago

#1 @bartech101
6 years ago

Last edited 6 years ago by bartech101 (previous) (diff)

@bartech101
6 years ago

This ticket was mentioned in Slack in #core by aaxxiiss. View the logs.


12 months ago

This ticket was mentioned in PR #4579 on WordPress/wordpress-develop by @aaxxiiss.


12 months ago
#3

  • Keywords has-patch added

…properties

Modified get_page_link() function to check if post object is found before proceeding to access its properties.

Trac ticket: 44497

Note: See TracTickets for help on using tickets.