From 77e65eace541663ac1875aa00688943d5d8bd446 Mon Sep 17 00:00:00 2001 From: Peter Wilson Date: Wed, 21 Sep 2022 01:07:52 +0000 Subject: [PATCH] Themes: Relocate actions firing prior to and after template loading. This relocates the actions `wp_before_load_template` and `wp_after_load_template` to fire within the `load_template()` function. Prior to this change the actions fired in the `locate_template()` function. Follow up to [53560]. Props johnjamesjacoby, johnbillion. Fixes #54541. git-svn-id: https://develop.svn.wordpress.org/trunk@54270 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/template.php | 46 +++++++++++++++++------------------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/src/wp-includes/template.php b/src/wp-includes/template.php index f4cace8bab..d34276a0ba 100644 --- a/src/wp-includes/template.php +++ b/src/wp-includes/template.php @@ -715,31 +715,7 @@ function locate_template( $template_names, $load = false, $require_once = true, } if ( $load && '' !== $located ) { - /** - * Fires before a located template is loaded. - * - * @since 6.1.0 - * - * @param string $located The template filename. - * @param string|array $template_names Template file(s) to search for, in order. - * @param bool $require_once Whether to require_once or require. - * @param array $args Additional arguments passed to the template. - */ - do_action( 'wp_before_load_template', $located, $template_names, $require_once, $args ); - load_template( $located, $require_once, $args ); - - /** - * Fires after a located template is loaded. - * - * @since 6.1.0 - * - * @param string $located The template filename. - * @param string|array $template_names Template file(s) to search for, in order. - * @param bool $require_once Whether to require_once or require. - * @param array $args Additional arguments passed to the template. - */ - do_action( 'wp_after_load_template', $located, $template_names, $require_once, $args ); } return $located; @@ -792,9 +768,31 @@ function load_template( $_template_file, $require_once = true, $args = array() ) $s = esc_attr( $s ); } + /** + * Fires before a template file is loaded. + * + * @since 6.1.0 + * + * @param string $_template_file The full path to the template file. + * @param bool $require_once Whether to require_once or require. + * @param array $args Additional arguments passed to the template. + */ + do_action( 'wp_before_load_template', $_template_file, $require_once, $args ); + if ( $require_once ) { require_once $_template_file; } else { require $_template_file; } + + /** + * Fires after a template file is loaded. + * + * @since 6.1.0 + * + * @param string $_template_file The full path to the template file. + * @param bool $require_once Whether to require_once or require. + * @param array $args Additional arguments passed to the template. + */ + do_action( 'wp_after_load_template', $_template_file, $require_once, $args ); }