WordPress.org

Make WordPress Core

Opened 2 years ago

Last modified 5 weeks ago

#42875 assigned defect (bug)

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:
PR Number:

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 (1)

42875.diff (4.5 KB) - added by TimothyBlynJacobs 5 weeks ago.

Download all attachments as: .zip

Change History (5)

#1 @perrywagle
2 years ago

Actually, with debugging on, it doesn't work.

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

Last edited 2 years ago by perrywagle (previous) (diff)

#3 @dshanske
2 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 @TimothyBlynJacobs
5 weeks 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.

Note: See TracTickets for help on using tickets.