From 724ccb492fec463b2fa4840d5e8df395fd4d887a Mon Sep 17 00:00:00 2001 From: Dominik Schilling Date: Tue, 23 Feb 2016 16:08:25 +0000 Subject: [PATCH] In `WP::handle_404()` introduce a filter `pre_handle_404` to short-circuit default header status handling. This comes handy if you use WordPress without posts, means `$wp_query` contains no results. Props prettyboymp, hakre, prettyboymp, Denis-de-Bernardy, ethitter, ocean90. Fixes #10722. Built from https://develop.svn.wordpress.org/trunk@36629 git-svn-id: http://core.svn.wordpress.org/trunk@36596 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-wp.php | 15 +++++++++++++++ wp-includes/version.php | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/wp-includes/class-wp.php b/wp-includes/class-wp.php index 238e2e6660..74ea29fe6f 100644 --- a/wp-includes/class-wp.php +++ b/wp-includes/class-wp.php @@ -629,6 +629,21 @@ class WP { public function handle_404() { global $wp_query; + /** + * Filter whether to short-circuit default header status handling. + * + * Returning a non-false value from the filter will short-circuit the handling + * and return early. + * + * @since 4.5.0 + * + * @param bool $preempt Whether to short-circuit default header status handling. Default false. + * @param WP_Query $wp_query WordPress Query object. + */ + if ( false !== apply_filters( 'pre_handle_404', false, $wp_query ) ) { + return; + } + // If we've already issued a 404, bail. if ( is_404() ) return; diff --git a/wp-includes/version.php b/wp-includes/version.php index d8c60cf599..ce763f297f 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.5-alpha-36628'; +$wp_version = '4.5-alpha-36629'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.