Opened 6 weeks ago
Closed 6 weeks ago
#63122 closed defect (bug) (fixed)
Site Editor: Browser reload causes PHP warning error on the Pages screen
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 6.8 | Priority: | normal |
Severity: | normal | Version: | trunk |
Component: | Editor | Keywords: | has-testing-info has-patch commit |
Focuses: | Cc: |
Description
- Access Apperance > Editor > Pages > Select "Sample Page"
- The URL should be: http://localhost:8888/wp-admin/site-editor.php?p=%2Fpage&postId=2
- Reload your browser
- Confirm the PHP warning
Warning: Undefined variable $post in /var/www/html/wp-admin/site-editor.php on line 242 Warning: Attempt to read property "post_name" on null in /var/www/html/wp-admin/site-editor.php on line 242 Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-admin/site-editor.php:242) in /var/www/html/wp-admin/admin-header.php on line 14
This warning is new to 6.8.
Attachments (5)
Change History (23)
#2
@
6 weeks ago
@joemcgill I'm able to reproduce it here with an install upgraded from 6.7.2 to 6.8 using the Beta Tester Plugin.
Environment
- WordPress: 6.8-beta3
- PHP: 8.3.11
- Server: nginx/1.26.1
- Database: mysqli (Server: 8.0.35 / Client: mysqlnd 8.3.11)
- Browser: Chrome 134.0.0.0
- OS: Windows 10/11
- Theme: Twenty Twenty-Three 1.6
- MU Plugins: None activated
- Plugins:
- Health Check & Troubleshooting 1.7.1
- Test Reports 1.2.0
- WordPress Beta Tester 3.6.2
- WP Activity Log 5.3.3
#3
@
6 weeks ago
PHP error hidden on desktop
Yes, the warning text may be hard to see in desktop view, but it is there.
#4
@
6 weeks ago
Unable to reproduce on an identical site that is on PHP 7.4, maybe PHP version based? What PHP version are you on @wildworks ?
#6
@
6 weeks ago
Hi @wildworks thanks for bringing this up.
After investigating the issue, I found the problem is in site-editor.php
. When building the URL for template lookup, there's a variable naming inconsistency:
empty( $block_editor_context->post->post_name ) ? 'page' : 'page-' . $post->post_name,
The code correctly uses $block_editor_context->post
in the first part, but then incorrectly uses $post
in the second part. Since $post
is undefined at this point, it triggers PHP warnings when the browser is reloaded.
The fix is to use the same variable throughout:
empty( $block_editor_context->post->post_name ) ? 'page' : 'page-' . $block_editor_context->post->post_name,
This resolves the warning in my testing. Let me know if this works for you and I can raise a PR with the fix.
This ticket was mentioned in PR #8535 on WordPress/wordpress-develop by @abcd95.
6 weeks ago
#8
- Keywords has-patch added
#9
@
6 weeks ago
@wildworks I'm also able to reproduce it here with in the given environment.
Environment
WordPress: 6.8-beta3-60042-src
PHP: 8.3.11
Server: nginx/1.26.1
Database: mysqli (Server: 8.0.35 / Client: mysqlnd 8.3.11)
Browser: Chrome 134.0.0.0
OS: Windows 10/11
Theme: Twenty Twenty-Five 1.1
MU Plugins: None activated
Plugins:
Health Check & Troubleshooting 1.7.1
Test Reports 1.2.1
#10
@
6 weeks ago
- Keywords has-testing-info added
Test Report :
Patch tested : https://github.com/WordPress/wordpress-develop/pull/8535
Environment
WordPress: 6.8-beta3-60042-src
PHP: 8.3.11
Server: nginx/1.26.1
Database: mysqli (Server: 8.0.35 / Client: mysqlnd 8.3.11)
Browser: Chrome 134.0.0.0
OS: Windows 10/11
Theme: Twenty Twenty-Five 1.1
MU Plugins: None activated
Plugins:
Health Check & Troubleshooting 1.7.1
Result:
After applying the patch the error has been gone.
Screenshot:
6 weeks ago
#11
Thanks for the patch @himanshupathak95 !
This looks good to me, also with this patch the error/warning has been gone.
#12
@
6 weeks ago
@abcd95 Thanks for submitting the patch.
The code correctly uses
$block_editor_context->post
in the first part, but then incorrectly uses$post
in the second part. Since$post
is undefined at this point, it triggers PHP warnings when the browser is reloaded.
The fix is to use the same variable throughout:
This approach looks correct to me.
This ticket was mentioned in Slack in #core by audrasjb. View the logs.
6 weeks ago
#14
@
6 weeks ago
- Keywords has-patch removed
Test Summary
This report verifies the resolution of a PHP warning in the WordPress Appearance Editor when accessing and reloading the Sample Page before and after applying the patch.
Test Environment
WordPress Version: 6.8 Beta 3
Server: Localhost (http://localhost/)
PHP Version: 8.1
Browser: chrome, firefox mozilla
Test Steps and Results
Before Applying Patch
Navigate to Appearance > Editor.
Click on Pages and select Sample Page.
The URL should be:
http://localhost/wp-admin/site-editor.php?p=%2Fpage&postId=2
Reload the browser.
Expected Result: The PHP warning should not appear.
Actual Result: The PHP warning appears.
Status: Failed.
After Applying Patch
Navigate to Appearance > Editor.
Click on Pages and select Sample Page.
Reload the browser.
Expected Result: No PHP warning should appear.
Actual Result: No PHP warning appears.
Status: Passed.
Conclusion
The applied patch successfully fixed the PHP warning in the WordPress 6.8 Beta 3 Appearance Editor. After applying the patch, reloading the Sample Page did not trigger any warnings.
Recommendation
Perform additional regression testing to ensure the patch does not introduce any unintended issues in other sections of the Appearance Editor.
#16
@
6 weeks ago
- Keywords commit added
I've tested the associated pull request and validated the fix:
- warning no longer thrown on reload
- REST request for
/wp/v2/templates/lookup?slug=page-sample-page
is correctly preloaded on the branch and no longer made upon page load
This looks good for commit, thank you!
Hi @wildworks, I'm not able to reproduce this in trunk nor in a fresh install of WP 6.8 beta 3. Is there any other information that would be needed to reproduce this issue? Do you have any other plugins active that could be triggering this error?