#51389 closed defect (bug) (fixed)
REST API: WP_REST_Meta_Fields::default_additional_properties_to_false assumes that the schema has properties.
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 5.6 | Priority: | normal |
Severity: | normal | Version: | 4.9 |
Component: | REST API | Keywords: | good-first-bug needs-patch |
Focuses: | Cc: |
Description
This function simply traverses through $schema
object and doesn't intend to do any type check on schema. Hence it may need to check existence of properties before traverse into it.
It affect the REST API response for post that has meta with object
type, the warning message PHP Warning: Invalid argument supplied for foreach() in ...
will corrupt the json output if the error_reporting
configuration is low enough.
The problem can be reproduced with the following meta registration in a plugin:
<?php function test_register_post_meta() { register_post_meta('post', 'test_key', array( 'type' => 'object', 'show_in_rest' => true, )); } add_action('init', 'test_register_post_meta'); ?>
#48785 might be related. They add test for that case, but I'm not sure what behavior should I test over in my case(for eliminating an warning without affecting the final result).
Attachments (3)
Change History (15)
#4
@
4 years ago
I changed the method used in get_registered_fields
into rest_default_additional_properties_to_false
, and since it seems to be the only method calling default_additional_properties_to_false
, deleting the whole method also seems OK.
I have done npm run test:php
once, the result remain the same after I made these changes. Remind me if I did anything wrong.
#5
@
4 years ago
Thanks for the refreshed patch @austin880625! We still need to keep the method around since developers who are extending the class may be using the method. So instead of removing it, we should instead mark it as deprecated and use _deprecated_function
.
#6
@
4 years ago
the method has been put back and the call to _deprecated_function
is added. You may check if there's any other problem.
#7
@
4 years ago
Thanks @austin880625! Can you open this as a Pull Request please, https://github.com/WordPress/wordpress-develop? It looks like there are some linting issues which a Pull Request will highlight.
This ticket was mentioned in PR #659 on WordPress/wordpress-develop by austin880625.
4 years ago
#8
- Keywords has-patch added; needs-patch removed
Signed-off-by: Austin Chang <austin880625@…>
Change the call to the default_additional_properties_to_false
method into rest_default_addtional_properties_to_false
introduced in 5.5
Trac ticket: https://core.trac.wordpress.org/ticket/51389
This ticket was mentioned in PR #660 on WordPress/wordpress-develop by austin880625.
4 years ago
#9
Signed-off-by: Austin Chang <austin880625@…>
Change the call to the default_additional_properties_to_false method into rest_default_addtional_properties_to_false introduced in 5.5
Trac ticket: https://core.trac.wordpress.org/ticket/51389
#10
@
4 years ago
- Keywords needs-patch added; has-patch removed
Ah, fixed the indentation issue.
Should I upload the patch that being displayed on the PR section again?
#11
@
4 years ago
- Owner set to TimothyBlynJacobs
- Resolution set to fixed
- Status changed from new to closed
In 49308:
TimothyBJacobs commented on PR #660:
4 years ago
#12
Merged in 3646dd2e9f8c80d924a6b6a691a5c1387e51c2c4. Thanks for the patch @austin880625!
Thanks for the patch @austin880625 and welcome to trac!
We could take a look at switching out that method to use the new
rest_default_additional_properties_to_false
introduced in WordPress 5.5.