WP_HTTP_Response
- Since
- 4.4.0
- Source
wp-includes/class-wp-http-response.php:15
Core class used to prepare HTTP responses.
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).
Properties · 3
$datamixedpublic- Response data.
$headersarraypublic- Response headers.
$statusintpublic- Response status.
Methods · 9
- __construct()Constructor.
- get_headers()Retrieves headers associated with the response.
- set_headers()Sets all header values.
- header()Sets a single HTTP header.
- get_status()Retrieves the HTTP return code for the response.
- set_status()Sets the 3-digit HTTP status code.
- get_data()Retrieves the response data.
- set_data()Sets the response data.
- jsonSerialize()Retrieves the response data for JSON serialization.
Source code
#[AllowDynamicProperties]class WP_HTTP_Response { /** * Response data. * * @since 4.4.0 * @var mixed */ public $data; /** * Response headers. * * @since 4.4.0 * @var array */ public $headers; /** * Response status. * * @since 4.4.0 * @var int */ public $status; /** * Constructor. * * @since 4.4.0 * * @param mixed $data Response data. Default null. * @param int $status Optional. HTTP status code. Default 200. * @param array $headers Optional. HTTP header map. Default empty array. */ public function __construct( $data = null, $status = 200, $headers = array() ) { $this->set_data( $data ); $this->set_status( $status ); $this->set_headers( $headers ); } /** * Retrieves headers associated with the response. * * @since 4.4.0 * * @return array Map of header name to header value. */ public function get_headers() { return $this->headers; } /** * Sets all header values. * * @since 4.4.0 * * @param array $headers Map of header name to header value. */ public function set_headers( $headers ) { $this->headers = $headers; } /** * Sets a single HTTP header. * * @since 4.4.0 * * @param string $key Header name. * @param string $value Header value. * @param bool $replace Optional. Whether to replace an existing header of the same name. * Default true. */ public function header( $key, $value, $replace = true ) { if ( $replace || ! isset( $this->headers[ $key ] ) ) { $this->headers[ $key ] = $value; } else { $this->headers[ $key ] .= ', ' . $value; }Changelog
Introduced in 4.4.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/class-wp-http-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.