Make WordPress Core

Opened 16 months ago

Closed 11 months ago

Last modified 11 months ago

#57851 closed defect (bug) (fixed)

PHP notice error when template part is created

Reported by: wildworks's profile wildworks Owned by: audrasjb's profile audrasjb
Milestone: 6.3 Priority: normal
Severity: normal Version:
Component: Editor Keywords: has-patch has-testing-info has-unit-tests needs-testing
Focuses: Cc:

Description (last modified by hellofromTonya)

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

Attachments (1)

wpRestTemplatesController.diff (2.2 KB) - added by Rahmohn 12 months ago.
Test to WP_REST_Templates_Controller::prepare_item_for_database

Download all attachments as: .zip

Change History (20)

This ticket was mentioned in PR #4165 on WordPress/wordpress-develop by @wildworks.


16 months ago
#1

  • Keywords has-patch added

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.

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. I think we need to consider both cases, when the $template part is null or when the area property is empty.

#2 @hellofromTonya
16 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.

#3 @dunhakdis
16 months ago

Was able to reproduce this issue as well. Thanks for submitting a PR, added a comment to use empty().

#4 @audrasjb
15 months ago

  • Owner set to audrasjb
  • Status changed from new to reviewing

Self assigning for review

@Rahmohn
12 months ago

Test to WP_REST_Templates_Controller::prepare_item_for_database

#5 @Rahmohn
12 months ago

  • Keywords has-unit-tests added; needs-unit-tests removed

Hi @audrasjb.

I've added a unit test that gets this issue.

This ticket was mentioned in Slack in #core by mukeshpanchal27. View the logs.


12 months ago

#7 @oglekler
12 months ago

@audrasjb can you please look at this ticket?

@Rahmohn why patch and unit test are in different patches?

#8 @Rahmohn
12 months ago

@oglekler I added the unit test in a different patch because I don't have permission to push commits to https://github.com/WordPress/wordpress-develop/pull/4165.

#9 @audrasjb
12 months ago

Ok @Rahmohn in this case, could you please add a new pull request of your own containing the changeset + your unit tests, please? We'll close the previous PR in favor of yours :)

This ticket was mentioned in PR #4833 on WordPress/wordpress-develop by @Rahmohn.


12 months ago
#10

This PR fixes the PHP notice when a template part is created in the site editor and adds a unit test to cover WP_REST_Templates_Controller::prepare_item_for_database.

Trac ticket: 57851

#11 @Rahmohn
12 months ago

@audrasjb

Sure. PR created :)

@wpsharif commented on PR #4833:


12 months ago
#12

Fix media not getting removed from the media library popup after clicking "Delete permanently" button

@wpsharif commented on PR #4833:


12 months ago
#13

Fix media not getting removed from the media library popup after clicking "Delete permanently" button

#14 @oglekler
12 months ago

  • Keywords needs-testing added

@audrasjb commented on PR #4165:


11 months ago
#16

closed in favor of #4833

This ticket was mentioned in Slack in #core by audrasjb. View the logs.


11 months ago

#18 @audrasjb
11 months ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

Fixed in [56248]

This ticket was mentioned in Slack in #core-test by mai21. View the logs.


11 months ago

Note: See TracTickets for help on using tickets.