Check for the existence of `$post` before using it in `get_the_ID()`. Return `false` if it doesn't exist.

Props UmeshSingla.
Fixes #17034.

Built from https://develop.svn.wordpress.org/trunk@28844


git-svn-id: http://core.svn.wordpress.org/trunk@28648 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Scott Taylor 2014-06-26 02:05:14 +00:00
parent 9739b9b74d
commit c725b77068
1 changed files with 3 additions and 2 deletions

View File

@ -23,10 +23,11 @@ function the_ID() {
* @since 2.1.0 * @since 2.1.0
* @uses $post * @uses $post
* *
* @return int * @return int|bool The ID of the current item in the WordPress Loop. False if $post is not set.
*/ */
function get_the_ID() { function get_the_ID() {
return get_post()->ID; $post = get_post();
return ! empty ( $post ) ? $post->ID : false;
} }
/** /**