[wp-trac] [WordPress Trac] #28572: Modify get_the_ID() function to return false, if get_post() returns null, otherwise it generates a PHP warning

WordPress Trac noreply at wordpress.org
Wed Jun 18 08:57:42 UTC 2014


#28572: Modify get_the_ID() function to return false, if get_post() returns null,
otherwise it generates a PHP warning
-------------------------------+-----------------------------
 Reporter:  UmeshSingla        |      Owner:
     Type:  defect (bug)       |     Status:  new
 Priority:  normal             |  Milestone:  Awaiting Review
Component:  Posts, Post Types  |    Version:  2.1
 Severity:  normal             |   Keywords:
  Focuses:                     |
-------------------------------+-----------------------------
 To replicate the issue, a simple use case would be, add this to
 functions.php:
 {{{
 #!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.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/28572>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list