Opened 3 months ago
Last modified 3 months ago
#57851 reviewing defect (bug)
PHP notice error when template part is created
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 6.3 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Editor | Keywords: | has-patch has-testing-info needs-unit-tests |
Focuses: | Cc: |
Description (last modified by )
Originally reported in the Gutenberg repository: https://github.com/WordPress/gutenberg/issues/48596
I get a PHP notice error when adding a new template part in the site editor.
PHP Notice: Trying to get property 'area' of non-object in /var/www/src/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php on line 581
When adding a new template part, the $template
variable will be null
, so this error would occur.
Original Report:
Reporter: @chrystl
Description
I get the notice below with WordPress 6.2-beta3-55428 and and Twenty Twenty Three (only) when creating a new TP from the TP block inside a TP.
[PHP Notice: Trying to get property 'area' of non-object in /wp-single/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php on line 586 [PHP Stack trace: [PHP 1. {main}() /wp-single/index.php:0 [PHP 2. require() /wp-single/index.php:17 [PHP 3. wp() /wp-single/wp-blog-header.php:16 [PHP 4. WP->main() /wp-single/wp-includes/functions.php:1330 [PHP 5. WP->parse_request() /wp-single/wp-includes/class-wp.php:780 [PHP 6. do_action_ref_array() /wp-single/wp-includes/class-wp.php:399 [PHP 7. WP_Hook->do_action() /wp-single/wp-includes/plugin.php:565 [PHP 8. WP_Hook->apply_filters() /wp-single/wp-includes/class-wp-hook.php:332 [PHP 9. rest_api_loaded() /wp-single/wp-includes/class-wp-hook.php:308 [PHP 10. WP_REST_Server->serve_request() /wp-single/wp-includes/rest-api.php:410 [PHP 11. WP_REST_Server->dispatch() /wp-single/wp-includes/rest-api/class-wp-rest-server.php:442 [PHP 12. WP_REST_Server->respond_to_request() /wp-single/wp-includes/rest-api/class-wp-rest-server.php:1028 [PHP 13. WP_REST_Templates_Controller->create_item() /wp-single/wp-includes/rest-api/class-wp-rest-server.php:1181 [PHP 14. WP_REST_Templates_Controller->prepare_item_for_database() /wp-single/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php:400
Step-by-step reproduction instructions
- go to /wp-admin/site-editor.php?canvas=view&path=%2Fwp_template_part&postType=wp_template_part then edit the Footer TP for example
- add a TP block > choose "start blank" > then create your TP. This action triggers the PHP notice mentioned above.
Environment
- WordPress: 6.1.1, 6.2-beta3-55428
- PHP: 7.2.3
Change History (4)
This ticket was mentioned in PR #4165 on WordPress/wordpress-develop by @wildworks.
3 months ago
#1
- Keywords has-patch added
#2
@
3 months ago
- Component changed from General to Editor
- Description modified (diff)
- Keywords has-testing-info needs-unit-tests added
- Milestone changed from Awaiting Review to 6.3
Hello @wildworks and @chrystl.
Welcome back to WordPress Core's Trac. Thanks for bringing the report here.
I've coped notes from the original report and added them to the ticket's description.
Trac ticket: https://core.trac.wordpress.org/ticket/57851
Originally reported in the Gutenberg repository: https://github.com/WordPress/gutenberg/issues/48596
This PR fixes the PHP notice error when template part is created.
When adding a new template part, the
$template
variable will benull
, so this error would occur. I think we need to consider both cases, when the$template
part isnull
or when thearea
property is empty.