Make WordPress Core

Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#37560 closed enhancement (fixed)

Enable sanitize_callback to return WP_Error

Reported by: websupporter Owned by: rachelbaker
Priority: normal Milestone: 4.7
Component: REST API Version: 4.4
Severity: normal Keywords: has-patch
Cc: Focuses:

Description

As discussed in Slack, it might be helpful, if the sanitization callback could return a WP_Error object like the validation callback.

https://wordpress.slack.com/archives/core-restapi/p1470200720000471

This patch wants to get this done.

With this patch, we would give developers the opportunity to reject incoming data without using the validation callback. It also enables us to do sanitization and validation in one function in instances where this could be useful.

I've oriented the solution on how it is done in the validation callback:
So, first all Errors are collected and then they will be returned. So if a request has more than one error, you get all the messages at once.

Attachments (2)

37560.diff (2.1 KB ) - added by websupporter 10 years ago.
37560.2.diff (3.8 KB ) - added by rmccue 10 years ago.
Updated patch with tests

Download all attachments as: .zip

Change History (8)

@websupporter
10 years ago

This ticket was mentioned in Slack in #core-restapi by rachelbaker. View the logs.


10 years ago

#2 @rachelbaker
10 years ago

  • Milestone Awaiting Review4.7
  • Owner set to rachelbaker
  • Status newassigned

@rmccue
10 years ago

Updated patch with tests

#3 @rmccue
10 years ago

  • Keywords has-patch added
  • Version4.4

Updated the patch and added a unit test to check it's working as expected.

This ticket was mentioned in Slack in #core-restapi by rmccue. View the logs.


10 years ago

#5 @joehoyle
10 years ago

  • Resolutionfixed
  • Status assignedclosed

In 38601:

REST API: Enable sanitize_callback to return WP_Error.

Give developers the opportunity to reject incoming data without using the validation callback. It also enables us to do sanitization and validation in one function in instances where this could be useful.

Props websupporter, rmccue.
Fixes #37560.

This ticket was mentioned in Slack in #core-restapi by kadamwhite. View the logs.


10 years ago

Note: See TracTickets for help on using tickets.