From 1628128a1080c2a1c04c0bd392acc0be1e98d17e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Perona?= Date: Fri, 25 Mar 2022 16:16:51 -0400 Subject: [PATCH 1/4] add new actions before and after loading the located template --- src/wp-includes/template.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/wp-includes/template.php b/src/wp-includes/template.php index b5b5619af564a..467e508948875 100644 --- a/src/wp-includes/template.php +++ b/src/wp-includes/template.php @@ -711,7 +711,25 @@ function locate_template( $template_names, $load = false, $require_once = true, } if ( $load && '' !== $located ) { + /** + * Fires before the located template is loaded + * + * @since 6.0.0 + * + * @param string The template filename. + */ + do_action( 'before_load_template', $located ); + load_template( $located, $require_once, $args ); + + /** + * Fires after the located template is loaded + * + * @since 6.0.0 + * + * @param string The template filename. + */ + do_action( 'after_load_template', $located ); } return $located; From 571ef96c5dd83bdb6ed42a30a3606b9cac51657e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Perona?= Date: Fri, 3 Jun 2022 16:30:20 -0400 Subject: [PATCH 2/4] Apply suggestions from code review Co-authored-by: Peter Wilson <519727+peterwilsoncc@users.noreply.github.com> --- src/wp-includes/template.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/wp-includes/template.php b/src/wp-includes/template.php index 467e508948875..b412ede67acb1 100644 --- a/src/wp-includes/template.php +++ b/src/wp-includes/template.php @@ -712,24 +712,24 @@ function locate_template( $template_names, $load = false, $require_once = true, if ( $load && '' !== $located ) { /** - * Fires before the located template is loaded + * Fires before the located template is loaded. * * @since 6.0.0 * * @param string The template filename. */ - do_action( 'before_load_template', $located ); + do_action( 'wp_before_load_template', $located ); load_template( $located, $require_once, $args ); /** - * Fires after the located template is loaded + * Fires after the located template is loaded. * * @since 6.0.0 * * @param string The template filename. */ - do_action( 'after_load_template', $located ); + do_action( 'wp_after_load_template', $located ); } return $located; From 5bc0c5a764e9643cf1b0be3660edd05558174602 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Perona?= Date: Fri, 3 Jun 2022 16:32:24 -0400 Subject: [PATCH 3/4] Apply suggestions from code review --- src/wp-includes/template.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/template.php b/src/wp-includes/template.php index b412ede67acb1..7a2a0a8cd3476 100644 --- a/src/wp-includes/template.php +++ b/src/wp-includes/template.php @@ -714,7 +714,7 @@ function locate_template( $template_names, $load = false, $require_once = true, /** * Fires before the located template is loaded. * - * @since 6.0.0 + * @since 6.1.0 * * @param string The template filename. */ @@ -725,7 +725,7 @@ function locate_template( $template_names, $load = false, $require_once = true, /** * Fires after the located template is loaded. * - * @since 6.0.0 + * @since 6.1.0 * * @param string The template filename. */ From f622576ba910c75546561e74f0fe75f7044ecdbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Perona?= Date: Tue, 21 Jun 2022 13:01:13 -0400 Subject: [PATCH 4/4] add additional parameters to the action --- src/wp-includes/template.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/wp-includes/template.php b/src/wp-includes/template.php index 7a2a0a8cd3476..260055f552f2c 100644 --- a/src/wp-includes/template.php +++ b/src/wp-includes/template.php @@ -716,9 +716,14 @@ function locate_template( $template_names, $load = false, $require_once = true, * * @since 6.1.0 * - * @param string The template filename. + * @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. Has no effect if `$load` is false. + * Default true. + * @param array $args Optional. Additional arguments passed to the template. + * Default empty array. */ - do_action( 'wp_before_load_template', $located ); + do_action( 'wp_before_load_template', $located, $template_names, $require_once, $args ); load_template( $located, $require_once, $args ); @@ -727,9 +732,14 @@ function locate_template( $template_names, $load = false, $require_once = true, * * @since 6.1.0 * - * @param string The template filename. + * @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. Has no effect if `$load` is false. + * Default true. + * @param array $args Optional. Additional arguments passed to the template. + * Default empty array. */ - do_action( 'wp_after_load_template', $located ); + do_action( 'wp_after_load_template', $located, $template_names, $require_once, $args ); } return $located;