From cd0349b3012dc7011c8c7e6d606a0551f66b998a Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sun, 28 Jun 2020 23:10:04 +0000 Subject: [PATCH] Themes: Add a return value to theme functions calling `locate_template()`: * `get_header()` * `get_footer()` * `get_sidebar()` * `get_template_part()` These functions now return false if the template file could not be found, to allow for easier debugging. Props tferry, sphakka, johnbillion, pento, davidbinda, desrosj, birgire, garrett-eclipse, williampatton, davidbaumwald, SergeyBiryukov. Fixes #40969. Built from https://develop.svn.wordpress.org/trunk@48209 git-svn-id: http://core.svn.wordpress.org/trunk@47978 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/general-template.php | 24 ++++++++++++++++++++---- wp-includes/version.php | 2 +- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/wp-includes/general-template.php b/wp-includes/general-template.php index 6827b425e7..d2eccbb617 100644 --- a/wp-includes/general-template.php +++ b/wp-includes/general-template.php @@ -16,8 +16,10 @@ * "special". * * @since 1.5.0 + * @since 5.5.0 A return value was added. * * @param string $name The name of the specialised header. + * @return void|false Void on success, false if the template does not exist. */ function get_header( $name = null ) { /** @@ -38,7 +40,9 @@ function get_header( $name = null ) { $templates[] = 'header.php'; - locate_template( $templates, true ); + if ( ! locate_template( $templates, true ) ) { + return false; + } } /** @@ -51,8 +55,10 @@ function get_header( $name = null ) { * "special". * * @since 1.5.0 + * @since 5.5.0 A return value was added. * * @param string $name The name of the specialised footer. + * @return void|false Void on success, false if the template does not exist. */ function get_footer( $name = null ) { /** @@ -73,7 +79,9 @@ function get_footer( $name = null ) { $templates[] = 'footer.php'; - locate_template( $templates, true ); + if ( ! locate_template( $templates, true ) ) { + return false; + } } /** @@ -86,8 +94,10 @@ function get_footer( $name = null ) { * "special". * * @since 1.5.0 + * @since 5.5.0 A return value was added. * * @param string $name The name of the specialised sidebar. + * @return void|false Void on success, false if the template does not exist. */ function get_sidebar( $name = null ) { /** @@ -108,7 +118,9 @@ function get_sidebar( $name = null ) { $templates[] = 'sidebar.php'; - locate_template( $templates, true ); + if ( ! locate_template( $templates, true ) ) { + return false; + } } /** @@ -128,9 +140,11 @@ function get_sidebar( $name = null ) { * "special". * * @since 3.0.0 + * @since 5.5.0 A return value was added. * * @param string $slug The slug name for the generic template. * @param string $name The name of the specialised template. + * @return void|false Void on success, false if the template does not exist. */ function get_template_part( $slug, $name = null ) { /** @@ -165,7 +179,9 @@ function get_template_part( $slug, $name = null ) { */ do_action( 'get_template_part', $slug, $name, $templates ); - locate_template( $templates, true, false ); + if ( ! locate_template( $templates, true, false ) ) { + return false; + } } /** diff --git a/wp-includes/version.php b/wp-includes/version.php index 0dd7824cf3..6b92f9d5f4 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.5-alpha-48208'; +$wp_version = '5.5-alpha-48209'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.