On this page
status_header( int $code, string $description = '' )
Sets HTTP status header.
Description
See also
Parameters
$codeint Required-
HTTP status code.
$descriptionstring Optional-
A custom description for the HTTP status.
Default:
''
More Information
Usage:
status_header( $header );
Notes:
Uses: apply_filters() Calls ‘status_header‘ on status header string, HTTP code, HTTP code description, and protocol string as separate parameters.
Source
File: wp-includes/functions.php. View all references
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 );
}
}
Hooks
- apply_filters( 'status_header',
string $status_header ,int $code ,string $description ,string $protocol ) -
Filters an HTTP status header.
Related
Uses
| Uses | Description |
|---|---|
| wp_get_server_protocol() wp-includes/load.php | Return the HTTP protocol sent by the server. |
| get_status_header_desc() wp-includes/functions.php | Retrieves the description for the HTTP status. |
| apply_filters() wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. |
Used By
| Used By | Description |
|---|---|
| IXR_Server::serve() wp-includes/IXR/class-IXR-server.php | |
| wp_xmlrpc_server::error() wp-includes/class-wp-xmlrpc-server.php | Send error response to client. |
| WP_Sitemaps::render_sitemaps() wp-includes/sitemaps/class-wp-sitemaps.php | Renders sitemap templates based on rewrite rules. |
| _jsonp_wp_die_handler() wp-includes/functions.php | Kills WordPress execution and displays JSONP response with an error message. |
| _xml_wp_die_handler() wp-includes/functions.php | Kills WordPress execution and displays XML response with an error message. |
| _json_wp_die_handler() wp-includes/functions.php | Kills WordPress execution and displays JSON response with an error message. |
| WP_Customize_Nav_Menus::ajax_insert_auto_draft_post() wp-includes/class-wp-customize-nav-menus.php | Ajax handler for adding a new auto-draft post. |
| WP_Customize_Selective_Refresh::handle_render_partials_request() wp-includes/customize/class-wp-customize-selective-refresh.php | Handles the Ajax request to return the rendered partials for the requested placements. |
| _oembed_rest_pre_serve_request() wp-includes/embed.php | Hooks into the REST API output to print XML instead of JSON. |
| WP_REST_Server::set_status() wp-includes/rest-api/class-wp-rest-server.php | Sends an HTTP status code. |
| wp_redirect() wp-includes/pluggable.php | Redirects to another page. |
| WP::handle_404() wp-includes/class-wp.php | Set the Headers for 404, if nothing is found for requested URL. |
| WP::send_headers() wp-includes/class-wp.php | Sends additional HTTP headers for caching, content type, etc. |
| wp_send_json() wp-includes/functions.php | Sends a JSON response back to an Ajax request. |
| _default_wp_die_handler() wp-includes/functions.php | Kills WordPress execution and displays HTML page with an error message. |
| _ajax_wp_die_handler() wp-includes/functions.php | Kills WordPress execution and displays Ajax response with an error message. |
| send_origin_headers() wp-includes/http.php | Send Access-Control-Allow-Origin and related headers if the current request is from an allowed origin. |
Changelog
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/status_header