WP_REST_Settings_Controller::sanitize_callback() WordPress Method

The WP_REST_Settings_Controller::sanitize_callback() method is used to sanitize data before it is saved to the database. This is a safety measure to ensure that only valid data is stored in the database.

WP_REST_Settings_Controller::sanitize_callback( mixed $value, WP_REST_Request $request, string $param ) #

Custom sanitize callback used for all options to allow the use of ‘null’.


Description

By default, the schema of settings will throw an error if a value is set to null as it’s not a valid value for something like "type => string". We provide a wrapper sanitizer to allow the use of null.


Top ↑

Parameters

$value

(mixed)(Required)The value for the setting.

$request

(WP_REST_Request)(Required)The request object.

$param

(string)(Required)The parameter name.


Top ↑

Return

(mixed|WP_Error)


Top ↑

Source

File: wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php

	public function sanitize_callback( $value, $request, $param ) {
		if ( is_null( $value ) ) {
			return $value;
		}

		return rest_parse_request_arg( $value, $request, $param );
	}


Top ↑

Changelog

Changelog
VersionDescription
4.7.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.