Themes: Return the value of `locate_template()` in functions that call it.

The `get_header()`, `get_footer()`, `get_sidebar()`, and `get_template_part()` functions all call `locate_template()` as their final action, which returns the name of the template being loaded. Returning this value helps handle problems with templates being loaded.

Props tferry.
Fixes #40969.



git-svn-id: https://develop.svn.wordpress.org/trunk@44678 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Gary Pendergast 2019-01-21 21:59:44 +00:00
parent 1d2153b0c1
commit f91ac658fe
1 changed files with 12 additions and 4 deletions

View File

@ -16,8 +16,10 @@
* "special". * "special".
* *
* @since 1.5.0 * @since 1.5.0
* @since 5.1.0 Added the return value.
* *
* @param string $name The name of the specialised header. * @param string $name The name of the specialised header.
* @return string The template filename if one is located.
*/ */
function get_header( $name = null ) { function get_header( $name = null ) {
/** /**
@ -38,7 +40,7 @@ function get_header( $name = null ) {
$templates[] = 'header.php'; $templates[] = 'header.php';
locate_template( $templates, true ); return locate_template( $templates, true );
} }
/** /**
@ -51,8 +53,10 @@ function get_header( $name = null ) {
* "special". * "special".
* *
* @since 1.5.0 * @since 1.5.0
* @since 5.1.0 Added the return value.
* *
* @param string $name The name of the specialised footer. * @param string $name The name of the specialised footer.
* @return string The template filename if one is located.
*/ */
function get_footer( $name = null ) { function get_footer( $name = null ) {
/** /**
@ -73,7 +77,7 @@ function get_footer( $name = null ) {
$templates[] = 'footer.php'; $templates[] = 'footer.php';
locate_template( $templates, true ); return locate_template( $templates, true );
} }
/** /**
@ -86,8 +90,10 @@ function get_footer( $name = null ) {
* "special". * "special".
* *
* @since 1.5.0 * @since 1.5.0
* @since 5.1.0 Added the return value.
* *
* @param string $name The name of the specialised sidebar. * @param string $name The name of the specialised sidebar.
* @return string The template filename if one is located.
*/ */
function get_sidebar( $name = null ) { function get_sidebar( $name = null ) {
/** /**
@ -108,7 +114,7 @@ function get_sidebar( $name = null ) {
$templates[] = 'sidebar.php'; $templates[] = 'sidebar.php';
locate_template( $templates, true ); return locate_template( $templates, true );
} }
/** /**
@ -128,9 +134,11 @@ function get_sidebar( $name = null ) {
* "special". * "special".
* *
* @since 3.0.0 * @since 3.0.0
* @since 5.1.0 Added the return value.
* *
* @param string $slug The slug name for the generic template. * @param string $slug The slug name for the generic template.
* @param string $name The name of the specialised template. * @param string $name The name of the specialised template.
* @return string The template filename if one is located.
*/ */
function get_template_part( $slug, $name = null ) { function get_template_part( $slug, $name = null ) {
/** /**
@ -154,7 +162,7 @@ function get_template_part( $slug, $name = null ) {
$templates[] = "{$slug}.php"; $templates[] = "{$slug}.php";
locate_template( $templates, true, false ); return locate_template( $templates, true, false );
} }
/** /**