WP_REST_Request::has_param() WordPress Method

The WP_REST_Request::has_param() method is used to determine whether a parameter has been set for a given request. This can be useful when validating user input or when trying to determine whether a certain piece of data is available.

WP_REST_Request::has_param( string $key ) #

Checks if a parameter exists in the request.


Description

This allows distinguishing between an omitted parameter, and a parameter specifically set to null.


Top ↑

Parameters

$key

(string)(Required)Parameter name.


Top ↑

Return

(bool) True if a param exists for the given key.


Top ↑

Source

File: wp-includes/rest-api/class-wp-rest-request.php

	public function has_param( $key ) {
		$order = $this->get_parameter_order();

		foreach ( $order as $type ) {
			if ( is_array( $this->params[ $type ] ) && array_key_exists( $key, $this->params[ $type ] ) ) {
				return true;
			}
		}

		return false;
	}


Top ↑

Changelog

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