[wp-trac] [WordPress Trac] #44497: get_page_link() doesn't check if a valid post object is returned before trying to access its properties
WordPress Trac
noreply at wordpress.org
Tue Jul 3 14:05:49 UTC 2018
#44497: get_page_link() doesn't check if a valid post object is returned before
trying to access its properties
-------------------------------+-----------------------------
Reporter: rodrigosprimo | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Posts, Post Types | Version:
Severity: normal | Keywords:
Focuses: |
-------------------------------+-----------------------------
If get_page_link() receives an invalid post ID as the first parameter it
will generate a PHP notice:
{{{#!bash
$ 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?
--
Ticket URL: <https://core.trac.wordpress.org/ticket/44497>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list