Make WordPress Core

Opened 11 years ago

Closed 11 years ago

#28572 closed defect (bug) (duplicate)

Modify get_the_ID() function to return false, if get_post() returns null, otherwise it generates a PHP warning

Reported by: umeshsingla's profile UmeshSingla Owned by:
Milestone: Priority: normal
Severity: normal Version: 2.1
Component: Posts, Post Types Keywords:
Focuses: Cc:

Description

To replicate the issue, a simple use case would be, add this to functions.php:

add_action ( 'wp_enqueue_scripts', 'us_enqueue_myscripts' );

function us_enqueue_myscripts() {
 $post_id = 5; //Any random post id here
 if ( get_the_ID() != $post_id ) {
        return;
 }
}

There are NO POSTS, If you access wp-signup.php in case of multisite, get_post() would return null and as a result get_the_ID() generates a PHP Notice: Trying to get property of non-object

Another strange behavior I came across while testing this, get_post() returns a latest Post ID on wp-signup.php, instead it should have returned null.

There are no additional plugins or themes, just the defaults one.

Attachments (1)

28572.diff (456 bytes) - added by UmeshSingla 11 years ago.
Fixes get_the_ID() if get_post() returns null

Download all attachments as: .zip

Change History (2)

@UmeshSingla
11 years ago

Fixes get_the_ID() if get_post() returns null

#1 @SergeyBiryukov
11 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #17034.

Note: See TracTickets for help on using tickets.