WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 3 years ago

Last modified 3 years 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:
PR Number:

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

Download all attachments as: .zip

Change History (8)

@websupporter
3 years ago

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


3 years ago

#2 @rachelbaker
3 years ago

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

@rmccue
3 years ago

Updated patch with tests

#3 @rmccue
3 years 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.


3 years ago

#5 @joehoyle
3 years 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.


3 years ago

Note: See TracTickets for help on using tickets.