status_header

The timeline below displays how wordpress function status_header has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.2

/**
 * Sets HTTP status header.
 *
 * @since 2.0.0
 * @since 4.4.0 Added the `$description` parameter.
 *
 * @see get_status_header_desc()
 *
 * @param int    $code        HTTP status code.
 * @param string $description Optional. A custom description for the HTTP status.
 *                            Defaults to the result of get_status_header_desc() for the given code.
 */
function status_header($code, $description = '')
{
    if (!$description) {
        $description = get_status_header_desc($code);
    }
    if (empty($description)) {
        return;
    }
    $protocol = wp_get_server_protocol();
    $status_header = "{$protocol} {$code} {$description}";
    if (function_exists('apply_filters')) {
        /**
         * Filters an HTTP status header.
         *
         * @since 2.2.0
         *
         * @param string $status_header HTTP status header.
         * @param int    $code          HTTP status code.
         * @param string $description   Description for the status code.
         * @param string $protocol      Server protocol.
         */
        $status_header = apply_filters('status_header', $status_header, $code, $description, $protocol);
    }
    if (!headers_sent()) {
        header($status_header, true, $code);
    }
}

WordPress Version: 6.1

/**
 * Sets HTTP status header.
 *
 * @since 2.0.0
 * @since 4.4.0 Added the `$description` parameter.
 *
 * @see get_status_header_desc()
 *
 * @param int    $code        HTTP status code.
 * @param string $description Optional. A custom description for the HTTP status.
 */
function status_header($code, $description = '')
{
    if (!$description) {
        $description = get_status_header_desc($code);
    }
    if (empty($description)) {
        return;
    }
    $protocol = wp_get_server_protocol();
    $status_header = "{$protocol} {$code} {$description}";
    if (function_exists('apply_filters')) {
        /**
         * Filters an HTTP status header.
         *
         * @since 2.2.0
         *
         * @param string $status_header HTTP status header.
         * @param int    $code          HTTP status code.
         * @param string $description   Description for the status code.
         * @param string $protocol      Server protocol.
         */
        $status_header = apply_filters('status_header', $status_header, $code, $description, $protocol);
    }
    if (!headers_sent()) {
        header($status_header, true, $code);
    }
}

WordPress Version: 5.3

/**
 * Set HTTP status header.
 *
 * @since 2.0.0
 * @since 4.4.0 Added the `$description` parameter.
 *
 * @see get_status_header_desc()
 *
 * @param int    $code        HTTP status code.
 * @param string $description Optional. A custom description for the HTTP status.
 */
function status_header($code, $description = '')
{
    if (!$description) {
        $description = get_status_header_desc($code);
    }
    if (empty($description)) {
        return;
    }
    $protocol = wp_get_server_protocol();
    $status_header = "{$protocol} {$code} {$description}";
    if (function_exists('apply_filters')) {
        /**
         * Filters an HTTP status header.
         *
         * @since 2.2.0
         *
         * @param string $status_header HTTP status header.
         * @param int    $code          HTTP status code.
         * @param string $description   Description for the status code.
         * @param string $protocol      Server protocol.
         */
        $status_header = apply_filters('status_header', $status_header, $code, $description, $protocol);
    }
    if (!headers_sent()) {
        header($status_header, true, $code);
    }
}

WordPress Version: 4.6

/**
 * Set HTTP status header.
 *
 * @since 2.0.0
 * @since 4.4.0 Added the `$description` parameter.
 *
 * @see get_status_header_desc()
 *
 * @param int    $code        HTTP status code.
 * @param string $description Optional. A custom description for the HTTP status.
 */
function status_header($code, $description = '')
{
    if (!$description) {
        $description = get_status_header_desc($code);
    }
    if (empty($description)) {
        return;
    }
    $protocol = wp_get_server_protocol();
    $status_header = "{$protocol} {$code} {$description}";
    if (function_exists('apply_filters')) {
        /**
         * Filters an HTTP status header.
         *
         * @since 2.2.0
         *
         * @param string $status_header HTTP status header.
         * @param int    $code          HTTP status code.
         * @param string $description   Description for the status code.
         * @param string $protocol      Server protocol.
         */
        $status_header = apply_filters('status_header', $status_header, $code, $description, $protocol);
    }
    @header($status_header, true, $code);
}

WordPress Version: 4.4

/**
 * Set HTTP status header.
 *
 * @since 2.0.0
 * @since 4.4.0 Added the `$description` parameter.
 *
 * @see get_status_header_desc()
 *
 * @param int    $code        HTTP status code.
 * @param string $description Optional. A custom description for the HTTP status.
 */
function status_header($code, $description = '')
{
    if (!$description) {
        $description = get_status_header_desc($code);
    }
    if (empty($description)) {
        return;
    }
    $protocol = wp_get_server_protocol();
    $status_header = "{$protocol} {$code} {$description}";
    if (function_exists('apply_filters')) {
        /**
         * Filter an HTTP status header.
         *
         * @since 2.2.0
         *
         * @param string $status_header HTTP status header.
         * @param int    $code          HTTP status code.
         * @param string $description   Description for the status code.
         * @param string $protocol      Server protocol.
         */
        $status_header = apply_filters('status_header', $status_header, $code, $description, $protocol);
    }
    @header($status_header, true, $code);
}

WordPress Version: 4.0

/**
 * Set HTTP status header.
 *
 * @since 2.0.0
 *
 * @see get_status_header_desc()
 *
 * @param int $code HTTP status code.
 */
function status_header($code)
{
    $description = get_status_header_desc($code);
    if (empty($description)) {
        return;
    }
    $protocol = $_SERVER['SERVER_PROTOCOL'];
    if ('HTTP/1.1' != $protocol && 'HTTP/1.0' != $protocol) {
        $protocol = 'HTTP/1.0';
    }
    $status_header = "{$protocol} {$code} {$description}";
    if (function_exists('apply_filters')) {
        /**
         * Filter an HTTP status header.
         *
         * @since 2.2.0
         *
         * @param string $status_header HTTP status header.
         * @param int    $code          HTTP status code.
         * @param string $description   Description for the status code.
         * @param string $protocol      Server protocol.
         */
        $status_header = apply_filters('status_header', $status_header, $code, $description, $protocol);
    }
    @header($status_header, true, $code);
}

WordPress Version: 3.9

/**
 * Set HTTP status header.
 *
 * @since 2.0.0
 * @see get_status_header_desc()
 *
 * @param int $code HTTP status code.
 */
function status_header($code)
{
    $description = get_status_header_desc($code);
    if (empty($description)) {
        return;
    }
    $protocol = $_SERVER['SERVER_PROTOCOL'];
    if ('HTTP/1.1' != $protocol && 'HTTP/1.0' != $protocol) {
        $protocol = 'HTTP/1.0';
    }
    $status_header = "{$protocol} {$code} {$description}";
    if (function_exists('apply_filters')) {
        /**
         * Filter an HTTP status header.
         *
         * @since 2.2.0
         *
         * @param string $status_header HTTP status header.
         * @param int    $code          HTTP status code.
         * @param string $description   Description for the status code.
         * @param string $protocol      Server protocol.
         */
        $status_header = apply_filters('status_header', $status_header, $code, $description, $protocol);
    }
    @header($status_header, true, $code);
}

WordPress Version: 3.8

/**
 * Set HTTP status header.
 *
 * @since 2.0.0
 * @see get_status_header_desc()
 *
 * @param int $code HTTP status code.
 */
function status_header($code)
{
    $description = get_status_header_desc($code);
    if (empty($description)) {
        return;
    }
    $protocol = $_SERVER['SERVER_PROTOCOL'];
    if ('HTTP/1.1' != $protocol && 'HTTP/1.0' != $protocol) {
        $protocol = 'HTTP/1.0';
    }
    $status_header = "{$protocol} {$code} {$description}";
    if (function_exists('apply_filters')) {
        $status_header = apply_filters('status_header', $status_header, $code, $description, $protocol);
    }
    @header($status_header, true, $code);
}

WordPress Version: 3.7

/**
 * Set HTTP status header.
 *
 * @since 2.0.0
 * @uses apply_filters() Calls 'status_header' on status header string, HTTP
 *		HTTP code, HTTP code description, and protocol string as separate
 *		parameters.
 *
 * @param int $header HTTP status code
 * @return unknown
 */
function status_header($header)
{
    $text = get_status_header_desc($header);
    if (empty($text)) {
        return false;
    }
    $protocol = $_SERVER["SERVER_PROTOCOL"];
    if ('HTTP/1.1' != $protocol && 'HTTP/1.0' != $protocol) {
        $protocol = 'HTTP/1.0';
    }
    $status_header = "{$protocol} {$header} {$text}";
    if (function_exists('apply_filters')) {
        $status_header = apply_filters('status_header', $status_header, $header, $text, $protocol);
    }
    return @header($status_header, true, $header);
}