WordPress开发者和主题制作者的搜索引擎



status_header ›

Since2.0.0
已弃用n/a
status_header ( $code, $description = '' )
参数: (2)
  • (int) $code HTTP status code.
    Required: Yes
  • (string) $description Optional. A custom description for the HTTP status.
    Required: No
    默认: (empty)
查看:
定义在:
文档:
Change Log:
  • 4.4.0

Set HTTP status header.



源码

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 );
	}
}