WP_REST_Plugins_Controller::does_plugin_match_request() WordPress Method

The WP_REST_Plugins_Controller::does_plugin_match_request() method is used to check if a given plugin is active and compatible with the current request. This is useful for determining if a particular plugin is required for a given request, and if so, whether or not it is already active. If the plugin is not active, this method will return false. If the plugin is active but not compatible with the current request, this method will return a WP_Error object. Otherwise, this method will return true.

WP_REST_Plugins_Controller::does_plugin_match_request( WP_REST_Request $request, array $item ) #

Checks if the plugin matches the requested parameters.


Parameters

$request

(WP_REST_Request)(Required)The request to require the plugin matches against.

$item

(array)(Required)The plugin item.


Top ↑

Return

(bool)


Top ↑

Source

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

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

		if ( $search ) {
			$matched_search = false;

			foreach ( $item as $field ) {
				if ( is_string( $field ) && false !== strpos( 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;
	}


Top ↑

Changelog

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