[wp-trac] [WordPress Trac] #57851: PHP notice error when template part is created

WordPress Trac noreply at wordpress.org
Thu Mar 2 16:03:45 UTC 2023


#57851: PHP notice error when template part is created
-------------------------------------------------+-------------------------
 Reporter:  wildworks                            |       Owner:  (none)
     Type:  defect (bug)                         |      Status:  new
 Priority:  normal                               |   Milestone:  6.3
Component:  Editor                               |     Version:
 Severity:  normal                               |  Resolution:
 Keywords:  has-patch has-testing-info needs-    |     Focuses:
  unit-tests                                     |
-------------------------------------------------+-------------------------
Changes (by hellofromTonya):

 * keywords:  has-patch => has-patch has-testing-info needs-unit-tests
 * component:  General => Editor
 * milestone:  Awaiting Review => 6.3


Old description:

> 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.

New description:

 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

 1. go to /wp-admin/site-
 editor.php?canvas=view&path=%2Fwp_template_part&postType=wp_template_part
 then edit the Footer TP for example
 2. 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

--

Comment:

 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.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/57851#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list