From 580d9913499a79f90ca5499a4d0727c1b2b64b3f Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Thu, 30 Jun 2022 15:48:15 +0000 Subject: [PATCH] Editor: Ensure only the main query is modified when resolving template for new posts. This adds a check for the main query in `_resolve_template_for_new_post()` to fix a 404 response when resolving template for new posts or pages caused by the wrong query being modified. Original PR from Gutenberg repository: * [https://github.com/WordPress/gutenberg/pull/40799 #40799: Ensure only the main query is modified when resolving template for new posts] Follow-up to [52316]. Props petitphp, zieladam, poena, ndiego, gziolo, kebbet, Mamaduka, manfcarlo. See #56058. Built from https://develop.svn.wordpress.org/trunk@53593 git-svn-id: http://core.svn.wordpress.org/trunk@53181 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/block-template.php | 4 ++++ wp-includes/version.php | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/wp-includes/block-template.php b/wp-includes/block-template.php index 7bd5684ed2..4d3a0449ea 100644 --- a/wp-includes/block-template.php +++ b/wp-includes/block-template.php @@ -312,6 +312,10 @@ function _block_template_render_without_post_block_context( $context ) { * @param WP_Query $wp_query Current WP_Query instance, passed by reference. */ function _resolve_template_for_new_post( $wp_query ) { + if ( ! $wp_query->is_main_query() ) { + return; + } + remove_filter( 'pre_get_posts', '_resolve_template_for_new_post' ); // Pages. diff --git a/wp-includes/version.php b/wp-includes/version.php index 30bab04a51..c135a548cc 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.1-alpha-53592'; +$wp_version = '6.1-alpha-53593'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.