wppaste
WordPress

WP_REST_Response

Since
4.4.0
Source
wp-includes/rest-api/class-wp-rest-response.php:17
Core class used to implement a REST response object.

Compatibility

WordPress
since 4.4.0
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0).

Hooks and filters fired · 1

Every hook that fires from inside WP_REST_Response, in the order it appears in the class, grouped by the method that fires it.

Properties · 3

$matched_routestringprotected
The route that was to create the response.
$matched_handlernull|arrayprotected
The handler that was used to create the response.

Methods · 12

Source code

class WP_REST_Response extends WP_HTTP_Response { 	/**	 * Links related to the response.	 *	 * @since 4.4.0	 * @var array	 */	protected $links = array(); 	/**	 * The route that was to create the response.	 *	 * @since 4.4.0	 * @var string	 */	protected $matched_route = ''; 	/**	 * The handler that was used to create the response.	 *	 * @since 4.4.0	 * @var null|array	 */	protected $matched_handler = null; 	/**	 * Adds a link to the response.	 *	 * @internal The $rel parameter is first, as this looks nicer when sending multiple.	 *	 * @since 4.4.0	 *	 * @link https://tools.ietf.org/html/rfc5988	 * @link https://www.iana.org/assignments/link-relations/link-relations.xml	 *	 * @param string $rel        Link relation. Either an IANA registered type,	 *                           or an absolute URL.	 * @param string $href       Target URI for the link.	 * @param array  $attributes Optional. Link parameters to send along with the URL. Default empty array.	 */	public function add_link( $rel, $href, $attributes = array() ) {		if ( empty( $this->links[ $rel ] ) ) {			$this->links[ $rel ] = array();		} 		if ( isset( $attributes['href'] ) ) {			// Remove the href attribute, as it's used for the main URL.			unset( $attributes['href'] );		} 		$this->links[ $rel ][] = array(			'href'       => $href,			'attributes' => $attributes,		);	} 	/**	 * Removes a link from the response.	 *	 * @since 4.4.0	 *	 * @param string $rel  Link relation. Either an IANA registered type, or an absolute URL.	 * @param string $href Optional. Only remove links for the relation matching the given href.	 *                     Default null.	 */	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 ] );		}

Changelog

Introduced in 4.4.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 6.8.8 tag, from src/wp-includes/rest-api/class-wp-rest-response.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.