Themes: Allow template loading functions to pass additional arguments to the template via the $args parameter.

This affects:
* `get_header()`
* `get_footer()`
* `get_sidebar()`
* `get_template_part()`
* `locate_template()`
* `load_template()`

Note: `get_search_form()` already passes additional arguments to the template as of [44956].

Props enrico.sorcinelli, sc0ttkclark, scribu, nacin, wonderboymusic, GeertDD, beatpanda, amaschas, mintindeed, ysalame, caiocrcosta, bigdawggi, julianm, eddiemoya, shawnz, sayedwp, shamai, mboynes, mihai2u, guidobras, Mte90, apedog, stuffradio, overclokk, johnbillion, joyously, afercia, audrasjb, justlevine, SergeyBiryukov.
See #21676.

git-svn-id: https://develop.svn.wordpress.org/trunk@48370 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov
2020-07-07 11:00:21 +00:00
parent 3eb2bd9f5b
commit 4e78b0acd9
4 changed files with 74 additions and 27 deletions
@@ -1 +1,3 @@
Template Part
<?php echo json_encode( $args ); ?>
+9
View File
@@ -678,4 +678,13 @@ class Tests_General_Template extends WP_UnitTestCase {
function test_get_template_part_returns_false_on_failure() {
$this->assertFalse( get_template_part( 'non-existing-template' ) );
}
/**
* @ticket 21676
*/
function test_get_template_part_passes_arguments_to_template() {
$this->expectOutputRegex( '/{"foo":"baz"}/' );
get_template_part( 'template', 'part', array( 'foo' => 'baz' ) );
}
}