Opened 7 years ago
Closed 5 years ago
#42875 closed defect (bug) (fixed)
Registering an "array" setting for the REST API causes a "Undefined index: items" warning
Reported by: | perrywagle | Owned by: | TimothyBlynJacobs |
---|---|---|---|
Milestone: | 5.4 | Priority: | normal |
Severity: | normal | Version: | 4.9 |
Component: | REST API | Keywords: | has-patch has-unit-tests |
Focuses: | docs | Cc: |
Description
Getting the error:
Undefined index: items in /var/www/html/wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php on line 328
The context of that line is that the variable is determined to be an 'array', but then gets indexed by the string 'items', which is not in the apparently associative array of associative array (?).
Apparently, some people trigger this, and some don't.
Attachments (3)
Change History (13)
#2
@
7 years ago
AH. Its leaving out the
define( 'WP_DEBUG_DISPLAY', false );
that does it (default true).
Seems seems to be a problem, just a different one.
#3
@
7 years ago
I traced the issue, in discussions with @perrywagle to a plugin using register_setting to declare a type of 'array' and noting show_in_rest.
It says that valid types are 'string', 'boolean', 'integer', and 'number'. I don't recall seeing this when the feature was first extended. Either way, the addition of a function in 4.9 created this error if the type is not set to one of the above 4.
The simple solution is, if it is an unsupported type, it should generate an error about that.
#4
@
5 years ago
- Focuses docs added
- Keywords has-patch has-unit-tests added
- Milestone changed from Awaiting Review to 5.4
- Owner set to TimothyBlynJacobs
- Status changed from new to assigned
- Summary changed from /var/www/html/wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php on line 328 to Registering an "array" setting for the REST API causes a "Undefined index: items" warning
- Version changed from 4.9.1 to 4.9
See also https://core.trac.wordpress.org/ticket/43392#comment:45 which had the same issue.
To summarize, when registering an array setting, a defined "items" schema is required. I've uploaded a patch that mirrors the fix in #43392, except that it won't prevent the registration of the setting. Since this code is already in the wild, I don't think we can prevent the registration. This means you'll still get the PHP warning as well.
This ticket was mentioned in Slack in #core-restapi by timothybjacobs. View the logs.
5 years ago
#6
@
5 years ago
We say "meta" when we mean setting, in one comment on the latest patch; and for clarity it might be good to have a test that explicitly asserts we DON'T get a doing_it_wrong when we DO provide the items schema, though that may be covered implicitly by the other tests.
#7
@
5 years ago
I uploaded a new patch that fixes the documentation error.
Opted not to add an additional test since we do have the test_get_item_with_custom_array_setting
test and it isn't clear what the assertion would be for just testing the doing it wrong.
Actually, with debugging on, it doesn't work.