diff --git a/src/wp-includes/class-wp.php b/src/wp-includes/class-wp.php index 0a0a501ee0..67985c147b 100644 --- a/src/wp-includes/class-wp.php +++ b/src/wp-includes/class-wp.php @@ -410,8 +410,12 @@ class WP { * @since 2.0.0 * @since 4.4.0 `X-Pingback` header is added conditionally for single posts that allow pings. * @since 6.1.0 Runs after posts have been queried. + * + * @global WP_Query $wp_query WordPress Query object. */ public function send_headers() { + global $wp_query; + $headers = array(); $status = null; $exit_required = false; diff --git a/tests/phpunit/tests/wp/sendHeaders.php b/tests/phpunit/tests/wp/sendHeaders.php index cc956409ef..84feb74d1d 100644 --- a/tests/phpunit/tests/wp/sendHeaders.php +++ b/tests/phpunit/tests/wp/sendHeaders.php @@ -19,4 +19,19 @@ class Tests_WP_SendHeaders extends WP_UnitTestCase { $this->go_to( home_url() ); } + + /** + * @ticket 56840 + */ + public function test_send_headers_sets_x_pingback_for_single_posts_that_allow_pings() { + add_action( + 'wp_headers', + function ( $headers ) { + $this->assertArrayHasKey( 'X-Pingback', $headers ); + } + ); + + $post_id = self::factory()->post->create(); + $this->go_to( get_permalink( $post_id ) ); + } }