Opened 12 years ago
Closed 12 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 | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Posts, Post Types | Version: | 2.1 |
| Severity: | normal | Keywords: | |
| Cc: | Focuses: |
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)
Change History (2)
Note:
See TracTickets
for help on using tickets.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Fixes get_the_ID() if get_post() returns null