wppaste
WordPress

WP::send_headers()

Since
2.0.0, 4.4.0, 6.1.0
Source
wp-includes/class-wp.php:435
Sends additional HTTP headers for caching, content type, etc.

Description

Sets the Content-Type header. Sets the 'error' status (if passed) and optionally exits.
If showing a feed, it will also send Last-Modified, ETag, and 304 status if needed.

Compatibility

WordPress
since 6.1.0
PHP
7.4–8.6-dev
  • 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), and compiles on PHP 7.4 through 8.6-dev.

Performance profile

How much work a call to WP::send_headers() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Heavy

Reaches the database via get_post().

Scaling
Scales with input

The body loops, so the work grows with how much data it finds.

Instructions
119–165

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 307.

Plugin surface
2 hooks

Third-party callbacks on 'wp_headers', 'send_headers' run inside this call, and their cost is not bounded by anything here.

Called by
1

1 place in core call this, so the cost is paid more often than your own code shows.

What it touches

  • optionoption read or writeget_option()called directly
  • hookthird-party callbacksapply_filters()called directly
  • cacheobject cachewp_cache_get()one call below WP::send_headers()
  • serializeserialisationmaybe_unserialize()one call below WP::send_headers()
  • querycontent queryget_post()one call below WP::send_headers()

Further down the call graph this can also reach transient. That is the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 72 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost WP::send_headers() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
!is_user_logged_in() && !isset($value) && empty($status)119–136is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), apply_filters(), headers_sent()
!is_user_logged_in() && !isset($value) && empty($status)121–138is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), apply_filters(), headers_sent(), exit()
!is_user_logged_in() && !isset($value) && !empty($status)122–139is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), apply_filters(), status_header(), headers_sent()
!is_user_logged_in() && !isset($value) && !empty($status)124–141is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), apply_filters(), status_header(), headers_sent(), exit()
!is_user_logged_in() && !isset($value) && empty($status) && isset($headers) && headers_sent()126–140is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), apply_filters(), headers_sent(), headers_sent()
!is_user_logged_in() && !isset($value) && empty($status) && isset($headers) && headers_sent()128–142is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), apply_filters(), headers_sent(), headers_sent(), exit()
!is_user_logged_in() && !isset($value) && is_singular() && !pings_open() && empty($post) && empty($status)129–140is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), pings_open(), apply_filters(), headers_sent()
!is_user_logged_in() && !isset($value) && empty($status) && isset($headers) && !headers_sent()129–143is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), apply_filters(), headers_sent(), header_remove(), headers_sent()
!is_user_logged_in() && !isset($value) && !empty($status) && isset($headers) && headers_sent()129–143is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), apply_filters(), status_header(), headers_sent(), headers_sent()
!is_user_logged_in() && !isset($value) && is_singular() && !pings_open() && empty($post) && empty($status)131–142is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), pings_open(), apply_filters(), headers_sent(), exit()
!is_user_logged_in() && !isset($value) && empty($status) && isset($headers) && !headers_sent()131–145is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), apply_filters(), headers_sent(), header_remove(), headers_sent(), exit()
!is_user_logged_in() && !isset($value) && !empty($status) && isset($headers) && headers_sent()131–145is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), apply_filters(), status_header(), headers_sent(), headers_sent(), exit()
60 further outcomes, up to 165 instructions
!is_user_logged_in() && !isset($value) && is_singular() && !empty($post) && empty($status)132–143is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), wp_get_nocache_headers(), array_merge(), apply_filters(), headers_sent()
!is_user_logged_in() && !isset($value) && is_singular() && !pings_open() && empty($post) && !empty($status)132–143is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), pings_open(), apply_filters(), status_header(), headers_sent()
!is_user_logged_in() && !isset($value) && !empty($status) && isset($headers) && !headers_sent()132–146is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), apply_filters(), status_header(), headers_sent(), header_remove(), headers_sent()
!is_user_logged_in() && !isset($value) && is_singular() && !empty($post) && empty($status)134–145is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), wp_get_nocache_headers(), array_merge(), apply_filters(), headers_sent(), exit()
!is_user_logged_in() && !isset($value) && is_singular() && !pings_open() && empty($post) && !empty($status)134–145is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), pings_open(), apply_filters(), status_header(), headers_sent(), exit()
!is_user_logged_in() && !isset($value) && !empty($status) && isset($headers) && !headers_sent()134–148is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), apply_filters(), status_header(), headers_sent(), header_remove(), headers_sent(), exit()
!is_user_logged_in() && !isset($value) && is_singular() && pings_open() && empty($post) && empty($status)135–146is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), pings_open(), get_bloginfo(), apply_filters(), headers_sent()
!is_user_logged_in() && !isset($value) && is_singular() && !empty($post) && !empty($status)135–146is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), wp_get_nocache_headers(), array_merge(), apply_filters(), status_header(), headers_sent()
!is_user_logged_in() && !isset($value) && is_singular() && !pings_open() && empty($post) && empty($status) && isset($headers) && headers_sent()136–144is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), pings_open(), apply_filters(), headers_sent(), headers_sent()
!is_user_logged_in() && !isset($value) && is_singular() && !pings_open() && !empty($post) && empty($status)136–147is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), pings_open(), wp_get_nocache_headers(), array_merge(), apply_filters(), headers_sent()
!is_user_logged_in() && !isset($value) && is_singular() && pings_open() && empty($post) && empty($status)137–148is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), pings_open(), get_bloginfo(), apply_filters(), headers_sent(), exit()
!is_user_logged_in() && !isset($value) && is_singular() && !empty($post) && !empty($status)137–148is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), wp_get_nocache_headers(), array_merge(), apply_filters(), status_header(), headers_sent(), exit()
!is_user_logged_in() && !isset($value) && is_singular() && !pings_open() && empty($post) && empty($status) && isset($headers) && headers_sent()138–146is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), pings_open(), apply_filters(), headers_sent(), headers_sent(), exit()
!is_user_logged_in() && !isset($value) && is_singular() && pings_open() && empty($post) && !empty($status)138–149is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), pings_open(), get_bloginfo(), apply_filters(), status_header(), headers_sent()
!is_user_logged_in() && !isset($value) && is_singular() && !pings_open() && !empty($post) && empty($status)138–149is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), pings_open(), wp_get_nocache_headers(), array_merge(), apply_filters(), headers_sent(), exit()
!is_user_logged_in() && !isset($value) && is_singular() && !empty($post) && empty($status) && isset($headers) && headers_sent()139–147is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), wp_get_nocache_headers(), array_merge(), apply_filters(), headers_sent(), headers_sent()
!is_user_logged_in() && !isset($value) && is_singular() && !pings_open() && empty($post) && empty($status) && isset($headers) && !headers_sent()139–147is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), pings_open(), apply_filters(), headers_sent(), header_remove(), headers_sent()
!is_user_logged_in() && !isset($value) && is_singular() && !pings_open() && empty($post) && !empty($status) && isset($headers) && headers_sent()139–147is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), pings_open(), apply_filters(), status_header(), headers_sent(), headers_sent()
!is_user_logged_in() && !isset($value) && is_singular() && !pings_open() && !empty($post) && !empty($status)139–150is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), pings_open(), wp_get_nocache_headers(), array_merge(), apply_filters(), status_header(), headers_sent()
!is_user_logged_in() && !isset($value) && is_singular() && pings_open() && empty($post) && !empty($status)140–151is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), pings_open(), get_bloginfo(), apply_filters(), status_header(), headers_sent(), exit()
!is_user_logged_in() && !isset($value) && is_singular() && !empty($post) && empty($status) && isset($headers) && headers_sent()141–149is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), wp_get_nocache_headers(), array_merge(), apply_filters(), headers_sent(), headers_sent(), exit()
!is_user_logged_in() && !isset($value) && is_singular() && !pings_open() && empty($post) && empty($status) && isset($headers) && !headers_sent()141–149is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), pings_open(), apply_filters(), headers_sent(), header_remove(), headers_sent(), exit()
!is_user_logged_in() && !isset($value) && is_singular() && !pings_open() && empty($post) && !empty($status) && isset($headers) && headers_sent()141–149is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), pings_open(), apply_filters(), status_header(), headers_sent(), headers_sent(), exit()
!is_user_logged_in() && !isset($value) && is_singular() && !pings_open() && !empty($post) && !empty($status)141–152is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), pings_open(), wp_get_nocache_headers(), array_merge(), apply_filters(), status_header(), headers_sent(), exit()
!is_user_logged_in() && !isset($value) && is_singular() && pings_open() && empty($post) && empty($status) && isset($headers) && headers_sent()142–150is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), pings_open(), get_bloginfo(), apply_filters(), headers_sent(), headers_sent()
!is_user_logged_in() && !isset($value) && is_singular() && !empty($post) && empty($status) && isset($headers) && !headers_sent()142–150is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), wp_get_nocache_headers(), array_merge(), apply_filters(), headers_sent(), header_remove(), headers_sent()
!is_user_logged_in() && !isset($value) && is_singular() && !empty($post) && !empty($status) && isset($headers) && headers_sent()142–150is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), wp_get_nocache_headers(), array_merge(), apply_filters(), status_header(), headers_sent(), headers_sent()
!is_user_logged_in() && !isset($value) && is_singular() && !pings_open() && empty($post) && !empty($status) && isset($headers) && !headers_sent()142–150is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), pings_open(), apply_filters(), status_header(), headers_sent(), header_remove(), headers_sent()
!is_user_logged_in() && !isset($value) && is_singular() && pings_open() && !empty($post) && empty($status)142–153is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), pings_open(), get_bloginfo(), wp_get_nocache_headers(), array_merge(), apply_filters(), headers_sent()
!is_user_logged_in() && !isset($value) && is_singular() && !pings_open() && !empty($post) && empty($status) && isset($headers) && headers_sent()143–151is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), pings_open(), wp_get_nocache_headers(), array_merge(), apply_filters(), headers_sent(), headers_sent()
!is_user_logged_in() && !isset($value) && is_singular() && pings_open() && empty($post) && empty($status) && isset($headers) && headers_sent()144–152is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), pings_open(), get_bloginfo(), apply_filters(), headers_sent(), headers_sent(), exit()
!is_user_logged_in() && !isset($value) && is_singular() && !empty($post) && empty($status) && isset($headers) && !headers_sent()144–152is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), wp_get_nocache_headers(), array_merge(), apply_filters(), headers_sent(), header_remove(), headers_sent(), exit()
!is_user_logged_in() && !isset($value) && is_singular() && !empty($post) && !empty($status) && isset($headers) && headers_sent()144–152is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), wp_get_nocache_headers(), array_merge(), apply_filters(), status_header(), headers_sent(), headers_sent(), exit()
!is_user_logged_in() && !isset($value) && is_singular() && !pings_open() && empty($post) && !empty($status) && isset($headers) && !headers_sent()144–152is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), pings_open(), apply_filters(), status_header(), headers_sent(), header_remove(), headers_sent(), exit()
!is_user_logged_in() && !isset($value) && is_singular() && pings_open() && !empty($post) && empty($status)144–155is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), pings_open(), get_bloginfo(), wp_get_nocache_headers(), array_merge(), apply_filters(), headers_sent(), exit()
!is_user_logged_in() && !isset($value) && is_singular() && pings_open() && empty($post) && empty($status) && isset($headers) && !headers_sent()145–153is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), pings_open(), get_bloginfo(), apply_filters(), headers_sent(), header_remove(), headers_sent()
!is_user_logged_in() && !isset($value) && is_singular() && pings_open() && empty($post) && !empty($status) && isset($headers) && headers_sent()145–153is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), pings_open(), get_bloginfo(), apply_filters(), status_header(), headers_sent(), headers_sent()
!is_user_logged_in() && !isset($value) && is_singular() && !empty($post) && !empty($status) && isset($headers) && !headers_sent()145–153is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), wp_get_nocache_headers(), array_merge(), apply_filters(), status_header(), headers_sent(), header_remove(), headers_sent()
!is_user_logged_in() && !isset($value) && is_singular() && !pings_open() && !empty($post) && empty($status) && isset($headers) && headers_sent()145–153is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), pings_open(), wp_get_nocache_headers(), array_merge(), apply_filters(), headers_sent(), headers_sent(), exit()
!is_user_logged_in() && !isset($value) && is_singular() && pings_open() && !empty($post) && !empty($status)145–156is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), pings_open(), get_bloginfo(), wp_get_nocache_headers(), array_merge(), apply_filters(), status_header(), headers_sent()
!is_user_logged_in() && !isset($value) && is_singular() && !pings_open() && !empty($post) && empty($status) && isset($headers) && !headers_sent()146–154is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), pings_open(), wp_get_nocache_headers(), array_merge(), apply_filters(), headers_sent(), header_remove(), headers_sent()
!is_user_logged_in() && !isset($value) && is_singular() && !pings_open() && !empty($post) && !empty($status) && isset($headers) && headers_sent()146–154is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), pings_open(), wp_get_nocache_headers(), array_merge(), apply_filters(), status_header(), headers_sent(), headers_sent()
!is_user_logged_in() && !isset($value) && is_singular() && pings_open() && empty($post) && empty($status) && isset($headers) && !headers_sent()147–155is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), pings_open(), get_bloginfo(), apply_filters(), headers_sent(), header_remove(), headers_sent(), exit()
!is_user_logged_in() && !isset($value) && is_singular() && pings_open() && empty($post) && !empty($status) && isset($headers) && headers_sent()147–155is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), pings_open(), get_bloginfo(), apply_filters(), status_header(), headers_sent(), headers_sent(), exit()
!is_user_logged_in() && !isset($value) && is_singular() && !empty($post) && !empty($status) && isset($headers) && !headers_sent()147–155is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), wp_get_nocache_headers(), array_merge(), apply_filters(), status_header(), headers_sent(), header_remove(), headers_sent(), exit()
!is_user_logged_in() && !isset($value) && is_singular() && pings_open() && !empty($post) && !empty($status)147–158is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), pings_open(), get_bloginfo(), wp_get_nocache_headers(), array_merge(), apply_filters(), status_header(), headers_sent(), exit()
!is_user_logged_in() && !isset($value) && is_singular() && pings_open() && empty($post) && !empty($status) && isset($headers) && !headers_sent()148–156is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), pings_open(), get_bloginfo(), apply_filters(), status_header(), headers_sent(), header_remove(), headers_sent()
!is_user_logged_in() && !isset($value) && is_singular() && !pings_open() && !empty($post) && empty($status) && isset($headers) && !headers_sent()148–156is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), pings_open(), wp_get_nocache_headers(), array_merge(), apply_filters(), headers_sent(), header_remove(), headers_sent(), exit()
!is_user_logged_in() && !isset($value) && is_singular() && !pings_open() && !empty($post) && !empty($status) && isset($headers) && headers_sent()148–156is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), pings_open(), wp_get_nocache_headers(), array_merge(), apply_filters(), status_header(), headers_sent(), headers_sent(), exit()
!is_user_logged_in() && !isset($value) && is_singular() && pings_open() && !empty($post) && empty($status) && isset($headers) && headers_sent()149–157is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), pings_open(), get_bloginfo(), wp_get_nocache_headers(), array_merge(), apply_filters(), headers_sent(), headers_sent()
!is_user_logged_in() && !isset($value) && is_singular() && !pings_open() && !empty($post) && !empty($status) && isset($headers) && !headers_sent()149–157is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), pings_open(), wp_get_nocache_headers(), array_merge(), apply_filters(), status_header(), headers_sent(), header_remove(), headers_sent()
!is_user_logged_in() && !isset($value) && is_singular() && pings_open() && empty($post) && !empty($status) && isset($headers) && !headers_sent()150–158is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), pings_open(), get_bloginfo(), apply_filters(), status_header(), headers_sent(), header_remove(), headers_sent(), exit()
!is_user_logged_in() && !isset($value) && is_singular() && pings_open() && !empty($post) && empty($status) && isset($headers) && headers_sent()151–159is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), pings_open(), get_bloginfo(), wp_get_nocache_headers(), array_merge(), apply_filters(), headers_sent(), headers_sent(), exit()
!is_user_logged_in() && !isset($value) && is_singular() && !pings_open() && !empty($post) && !empty($status) && isset($headers) && !headers_sent()151–159is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), pings_open(), wp_get_nocache_headers(), array_merge(), apply_filters(), status_header(), headers_sent(), header_remove(), headers_sent(), exit()
!is_user_logged_in() && !isset($value) && is_singular() && pings_open() && !empty($post) && empty($status) && isset($headers) && !headers_sent()152–160is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), pings_open(), get_bloginfo(), wp_get_nocache_headers(), array_merge(), apply_filters(), headers_sent(), header_remove(), headers_sent()
!is_user_logged_in() && !isset($value) && is_singular() && pings_open() && !empty($post) && !empty($status) && isset($headers) && headers_sent()152–160is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), pings_open(), get_bloginfo(), wp_get_nocache_headers(), array_merge(), apply_filters(), status_header(), headers_sent(), headers_sent()
!is_user_logged_in() && !isset($value) && is_singular() && pings_open() && !empty($post) && empty($status) && isset($headers) && !headers_sent()154–162is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), pings_open(), get_bloginfo(), wp_get_nocache_headers(), array_merge(), apply_filters(), headers_sent(), header_remove(), headers_sent(), exit()
!is_user_logged_in() && !isset($value) && is_singular() && pings_open() && !empty($post) && !empty($status) && isset($headers) && headers_sent()154–162is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), pings_open(), get_bloginfo(), wp_get_nocache_headers(), array_merge(), apply_filters(), status_header(), headers_sent(), headers_sent(), exit()
!is_user_logged_in() && !isset($value) && is_singular() && pings_open() && !empty($post) && !empty($status) && isset($headers) && !headers_sent()155–163is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), pings_open(), get_bloginfo(), wp_get_nocache_headers(), array_merge(), apply_filters(), status_header(), headers_sent(), header_remove(), headers_sent()
!is_user_logged_in() && !isset($value) && is_singular() && pings_open() && !empty($post) && !empty($status) && isset($headers) && !headers_sent()157–165is_user_logged_in(), feed_content_type(), get_option(), get_lastpostmodified(), mysql2date(), get_lastcommentmodified(), mysql2date(), strtotime(), strtotime(), md5(), strtotime(), is_singular(), pings_open(), get_bloginfo(), wp_get_nocache_headers(), array_merge(), apply_filters(), status_header(), headers_sent(), header_remove(), headers_sent(), exit()

This body has more branch combinations than are worth enumerating, so the table covers the outcomes found first rather than every one that exists.

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev307119–16541
8.5307119–16541
8.4307119–165415 fewer instructions than PHP 8.3
8.3312113–16341
8.2312113–16341
8.1312113–163412 fewer instructions than PHP 7.4
7.4314113–16341

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Hooks and filters fired · 2

2 hooks fire while WP::send_headers() runs, in this order:

  1. apply_filters( wp_headers )filterline 563 (+128 into the body)

    Filters the HTTP headers before they're sent to the browser.

  2. do_action( send_headers )actionline 598 (+163 into the body)

    Fires once the requested HTTP headers for caching, content type, etc. have been sent.

Uses · 16

Show all 16

Used by · 1

  • WP::main()Sets up all of the variables required by the WordPress environment.

Source code

	public function send_headers() {		global $wp_query; 		$headers       = array();		$status        = null;		$exit_required = false;		$date_format   = 'D, d M Y H:i:s'; 		if ( is_user_logged_in() ) {			$headers = array_merge( $headers, wp_get_nocache_headers() );		} elseif ( ! empty( $_GET['unapproved'] ) && ! empty( $_GET['moderation-hash'] ) ) {			// Unmoderated comments are only visible for 10 minutes via the moderation hash.			$expires = 10 * MINUTE_IN_SECONDS; 			$headers['Expires']       = gmdate( $date_format, time() + $expires );			$headers['Cache-Control'] = sprintf(				'max-age=%d, must-revalidate',				$expires			);		}		if ( ! empty( $this->query_vars['error'] ) ) {			$status = (int) $this->query_vars['error']; 			if ( 404 === $status ) {				if ( ! is_user_logged_in() ) {					$headers = array_merge( $headers, wp_get_nocache_headers() );				} 				$headers['Content-Type'] = get_option( 'html_type' ) . '; charset=' . get_option( 'blog_charset' );			} elseif ( in_array( $status, array( 403, 500, 502, 503 ), true ) ) {				$exit_required = true;			}		} elseif ( empty( $this->query_vars['feed'] ) ) {			$headers['Content-Type'] = get_option( 'html_type' ) . '; charset=' . get_option( 'blog_charset' );		} else {			// Set the correct content type for feeds.			$type = $this->query_vars['feed'];			if ( 'feed' === $this->query_vars['feed'] ) {				$type = get_default_feed();			} 			$headers['Content-Type'] = feed_content_type( $type ) . '; charset=' . get_option( 'blog_charset' ); 			// We're showing a feed, so WP is indeed the only thing that last changed.			if ( ! empty( $this->query_vars['withcomments'] )				|| str_contains( $this->query_vars['feed'], 'comments-' )				|| ( empty( $this->query_vars['withoutcomments'] )					&& ( ! empty( $this->query_vars['p'] )						|| ! empty( $this->query_vars['name'] )						|| ! empty( $this->query_vars['page_id'] )						|| ! empty( $this->query_vars['pagename'] )						|| ! empty( $this->query_vars['attachment'] )						|| ! empty( $this->query_vars['attachment_id'] )					)				)			) {				$wp_last_modified_post    = mysql2date( $date_format, get_lastpostmodified( 'GMT' ), false );				$wp_last_modified_comment = mysql2date( $date_format, get_lastcommentmodified( 'GMT' ), false ); 				if ( strtotime( $wp_last_modified_post ) > strtotime( $wp_last_modified_comment ) ) {					$wp_last_modified = $wp_last_modified_post;				} else {					$wp_last_modified = $wp_last_modified_comment;				}			} else {				$wp_last_modified = mysql2date( $date_format, get_lastpostmodified( 'GMT' ), false );			} 			if ( ! $wp_last_modified ) {				$wp_last_modified = gmdate( $date_format );			} 			$wp_last_modified .= ' GMT';			$wp_etag           = '"' . md5( $wp_last_modified ) . '"'; 			$headers['Last-Modified'] = $wp_last_modified;			$headers['ETag']          = $wp_etag; 			// Support for conditional GET.			if ( isset( $_SERVER['HTTP_IF_NONE_MATCH'] ) ) {

Changelog

Introduced in 2.0.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.

6.1.0
Runs after posts have been queried.from the docblock
4.4.0
X-Pingback header is added conditionally for single posts that allow pings.from the docblock
2.0.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/class-wp.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.