WP_REST_Plugins_Controller::does_plugin_match_request()protectedWP 5.5.0

Checks if the plugin matches the requested parameters.

Method of the class: WP_REST_Plugins_Controller{}

No Hooks.

Return

true|false.

Usage

// protected - for code of main (parent) or child class
$result = $this->does_plugin_match_request( $request, $item );
$request(WP_REST_Request) (required)
The request to require the plugin matches against.
$item(array) (required)
The plugin item.

Changelog

Since 5.5.0 Introduced.

WP_REST_Plugins_Controller::does_plugin_match_request() code WP 6.5.2

protected function does_plugin_match_request( $request, $item ) {
	$search = $request['search'];

	if ( $search ) {
		$matched_search = false;

		foreach ( $item as $field ) {
			if ( is_string( $field ) && str_contains( strip_tags( $field ), $search ) ) {
				$matched_search = true;
				break;
			}
		}

		if ( ! $matched_search ) {
			return false;
		}
	}

	$status = $request['status'];

	if ( $status && ! in_array( $this->get_plugin_status( $item['_file'] ), $status, true ) ) {
		return false;
	}

	return true;
}