Skip to content

Needs more detailed descriptions about validate_callback in WP REST API #194

Open
@fumikito

Description

@fumikito

In Adding Custom Endpoints, validate_callback for arguments list is described like below.

validate_callback: Used to pass a function that will be passed the value of the argument. That function should return true if the value is valid, and false if not.

source: https://github.com/WP-API/docs/blob/master/extending-the-rest-api/adding-custom-endpoints.md?plain=1#L123

But it seems that extra descriptions are required.

  • It also accepts WP_Error as return value. WP_Error adds extra messages to response.
  • false is checked strictly, so other falsey values like '', 0, and null will be recognized as valid.

Code is here: https://github.com/WordPress/WordPress/blob/master/wp-includes/rest-api/class-wp-rest-request.php#L911-L923

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions