WP_REST_Search_Controller::sanitize_subtypes( string|array $subtypes, WP_REST_Request $request, string $parameter ): string[]|WP_Error

In this article

Sanitizes the list of subtypes, to ensure only subtypes of the passed type are included.

Parameters

$subtypesstring|arrayrequired
One or more subtypes.
$requestWP_REST_Requestrequired
Full details about the request.
$parameterstringrequired
Parameter name.

Return

string[]|WP_Error List of valid subtypes, or WP_Error object on failure.

Source

public function sanitize_subtypes( $subtypes, $request, $parameter ) {
	$subtypes = wp_parse_slug_list( $subtypes );

	$subtypes = rest_parse_request_arg( $subtypes, $request, $parameter );
	if ( is_wp_error( $subtypes ) ) {
		return $subtypes;
	}

	// 'any' overrides any other subtype.
	if ( in_array( self::TYPE_ANY, $subtypes, true ) ) {
		return array( self::TYPE_ANY );
	}

	$handler = $this->get_search_handler( $request );
	if ( is_wp_error( $handler ) ) {
		return $handler;
	}

	return array_intersect( $subtypes, $handler->get_subtypes() );
}

Changelog

VersionDescription
5.0.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.