Make WordPress Core

Opened 3 years ago

Closed 23 months ago

#44963 closed defect (bug) (invalid)

PHP Notice: Undefined variable in wp-includes/rest-api.php $args['type']

Reported by: weblogma Owned by:
Milestone: Priority: normal
Severity: minor Version: 4.7
Component: REST API Keywords: has-patch reporter-feedback
Focuses: rest-api Cc:

Description (last modified by SergeyBiryukov)

This problem occur in rest_validate_value_from_schema and rest_sanitize_value_from_schema functions.
Please add

if ( isset($args['type']) && 'array' === $args['type'] )...

isset($args['type']) before *** === $args['type'] for fixed these.

Attachments (2)

rest-api.php (39.2 KB) - added by weblogma 3 years ago.
I fixed bugs in this file.
44963.patch (789 bytes) - added by mukesh27 3 years ago.
You have to add patch like attached.

Download all attachments as: .zip

Change History (7)

3 years ago

I fixed bugs in this file.

#1 @mukesh27
3 years ago

  • Keywords needs-patch added
Version 0, edited 3 years ago by mukesh27 (next)

3 years ago

You have to add patch like attached.

#2 @mukesh27
3 years ago

  • Keywords has-patch added; needs-patch removed
  • Severity changed from normal to minor

#3 @TimothyBlynJacobs
3 years ago

@weblogma Can you attach what schema you are using? Or are you using the function directly?

#4 @SergeyBiryukov
3 years ago

  • Description modified (diff)
  • Keywords reporter-feedback added; dev-feedback removed

#5 @TimothyBlynJacobs
23 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed
  • Version set to 4.7

Hi @weblogma,

I'm going to close out this ticket. At the moment, specifying a type for your schema is required. Otherwise rest_validate_value_from_schema won't have anything to do. If you don't want the default validator or sanitizers to be called, you can manually set validate_callback and sanitize_callback to null. For an example: https://github.com/WordPress/wordpress-develop/blob/75f82d8bc2b96074d67df09c371cfc1139c19d8c/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php#L2081

If you have a use case as to why the type should be optional, feel free to comment and reopen the ticket.

Note: See TracTickets for help on using tickets.