WP_REST_Response::remove_link() WordPress Method

The WP_REST_Response::remove_link() function can be used to remove a link from the response object. This is useful if you need to update or remove a link based on some condition.

WP_REST_Response::remove_link( string $rel, string $href = null ) #

Removes a link from the response.


Parameters

$rel

(string)(Required)Link relation. Either an IANA registered type, or an absolute URL.

$href

(string)(Optional) Only remove links for the relation matching the given href.

Default value: null


Top ↑

Source

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

	public function remove_link( $rel, $href = null ) {
		if ( ! isset( $this->links[ $rel ] ) ) {
			return;
		}

		if ( $href ) {
			$this->links[ $rel ] = wp_list_filter( $this->links[ $rel ], array( 'href' => $href ), 'NOT' );
		} else {
			$this->links[ $rel ] = array();
		}

		if ( ! $this->links[ $rel ] ) {
			unset( $this->links[ $rel ] );
		}
	}


Top ↑

Changelog

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