WordPress.org

Make WordPress Core

Opened 12 months ago

Closed 10 months ago

Last modified 10 months ago

#37560 closed enhancement (fixed)

Enable sanitize_callback to return WP_Error

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

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 12 months ago.
37560.2.diff (3.8 KB) - added by rmccue 10 months ago.
Updated patch with tests

Download all attachments as: .zip

Change History (8)

@websupporter
12 months ago

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


12 months ago

#2 @rachelbaker
11 months ago

  • Milestone changed from Awaiting Review to 4.7
  • Owner set to rachelbaker
  • Status changed from new to assigned

@rmccue
10 months ago

Updated patch with tests

#3 @rmccue
10 months ago

  • Keywords has-patch added
  • Version set to 4.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 months ago

#5 @joehoyle
10 months ago

  • Resolution set to fixed
  • Status changed from assigned to closed

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 months ago

Note: See TracTickets for help on using tickets.