WP_REST_Search_Controller::sanitize_subtypes() WordPress Method

This method is used to sanitize subtypes for use in search.

WP_REST_Search_Controller::sanitize_subtypes( string|array $subtypes, WP_REST_Request $request, string $parameter ) #

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


Parameters

$subtypes

(string|array)(Required)One or more subtypes.

$request

(WP_REST_Request)(Required)Full details about the request.

$parameter

(string)(Required)Parameter name.


Top ↑

Return

(array|WP_Error) List of valid subtypes, or WP_Error object on failure.


Top ↑

Source

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

	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() );
	}


Top ↑

Changelog

Changelog
VersionDescription
5.0.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.