#54159 closed defect (bug) (fixed)
comments_open() & pings_open() trigger PHP Notice when called on a page without a $post
Reported by: | dd32 | Owned by: | hellofromTonya |
---|---|---|---|
Milestone: | 5.9 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Comments | Keywords: | has-patch commit has-unit-tests |
Focuses: | Cc: |
Description
Both comments_open()
and pings_open()
contain some slightly odd logic, that accounts for the $post
not existing on one line, and assuming it does exist on the next. Causing a PHP Notice under some specific circumstances.
Calling comments_open( $post_id_that_does_not_exist )
would also trigger it.
See attached.
Attachments (2)
Change History (11)
#4
@
3 years ago
- Owner set to hellofromTonya
- Status changed from new to accepted
Though today is 5.9 Beta 1, assigning to me to check test coverage and get this one committed.
#5
@
3 years ago
Test Report
Env
- WordPress 5.9-alpha-20211117.140912
- Chrome 95.0.4638.69
- Windows 10
- Theme: Twenty Twenty Two
- Gutenberg Editor
- Plugin: None activated
Steps to test
- Add
comments_open( 999999 );
to your theme'sfunctions.php
file. - Load any page. You should see a PHP notice.
- Apply the patch.
- Reload the page. You should not see a PHP notice.
Results
Without the patch: A PHP notice displays for Warning: Attempt to read property "comment_status" on null
.
With the patch: The PHP notice no longer displays.
This ticket was mentioned in PR #1921 on WordPress/wordpress-develop by hellofromtonya.
3 years ago
#7
- Keywords has-unit-tests added
Adds unit tests for both functions. Confirms PHP notice.
Applies patch 54159.1.diff. Confirms notice is fixed.
Trac ticket: https://core.trac.wordpress.org/ticket/54159
hellofromtonya commented on PR #1921:
3 years ago
#9
Committed via changeset https://core.trac.wordpress.org/changeset/52223.
The patch doesn't apply anymore against trunk