diff --git src/wp-includes/general-template.php src/wp-includes/general-template.php
index 82c138cef7..b0ffabe60e 100644
|
|
|
16 | 16 | * "special". |
17 | 17 | * |
18 | 18 | * @since 1.5.0 |
| 19 | * @since 5.5.0 $wp_tmpl_args parameter added. |
19 | 20 | * |
20 | | * @param string $name The name of the specialised header. |
| 21 | * @param string $name The name of the specialised header. |
| 22 | * @param array $wp_tmpl_args Additional arguments passed to the header template. |
21 | 23 | */ |
22 | | function get_header( $name = null ) { |
| 24 | function get_header( $name = null, $wp_tmpl_args = array() ) { |
23 | 25 | /** |
24 | 26 | * Fires before the header template file is loaded. |
25 | 27 | * |
26 | 28 | * @since 2.1.0 |
27 | 29 | * @since 2.8.0 $name parameter added. |
| 30 | * @since 5.5.0 $wp_tmpl_args parameter added. |
28 | 31 | * |
29 | | * @param string|null $name Name of the specific header file to use. null for the default header. |
| 32 | * @param string|null $name Name of the specific header file to use. null for the default header. |
| 33 | * @param array $wp_tmpl_args Additional arguments passed to the header template. |
30 | 34 | */ |
31 | | do_action( 'get_header', $name ); |
| 35 | do_action( 'get_header', $name, $wp_tmpl_args ); |
32 | 36 | |
33 | 37 | $templates = array(); |
34 | 38 | $name = (string) $name; |
… |
… |
function get_header( $name = null ) { |
38 | 42 | |
39 | 43 | $templates[] = 'header.php'; |
40 | 44 | |
41 | | locate_template( $templates, true ); |
| 45 | locate_template( $templates, true, true, $wp_tmpl_args ); |
42 | 46 | } |
43 | 47 | |
44 | 48 | /** |
… |
… |
function get_header( $name = null ) { |
51 | 55 | * "special". |
52 | 56 | * |
53 | 57 | * @since 1.5.0 |
| 58 | * @since 5.5.0 $wp_tmpl_args parameter added. |
54 | 59 | * |
55 | | * @param string $name The name of the specialised footer. |
| 60 | * @param string $name The name of the specialised footer. |
| 61 | * @param array $wp_tmpl_args Additional arguments passed to the footer template. |
56 | 62 | */ |
57 | | function get_footer( $name = null ) { |
| 63 | function get_footer( $name = null, $wp_tmpl_args = array() ) { |
58 | 64 | /** |
59 | 65 | * Fires before the footer template file is loaded. |
60 | 66 | * |
61 | 67 | * @since 2.1.0 |
62 | 68 | * @since 2.8.0 $name parameter added. |
| 69 | * @since 5.5.0 $wp_tmpl_args parameter added. |
63 | 70 | * |
64 | | * @param string|null $name Name of the specific footer file to use. null for the default footer. |
| 71 | * @param string|null $name Name of the specific footer file to use. null for the default footer. |
| 72 | * @param array $wp_tmpl_args Additional arguments passed to the footer template. |
65 | 73 | */ |
66 | | do_action( 'get_footer', $name ); |
| 74 | do_action( 'get_footer', $name, $wp_tmpl_args ); |
67 | 75 | |
68 | 76 | $templates = array(); |
69 | 77 | $name = (string) $name; |
… |
… |
function get_footer( $name = null ) { |
73 | 81 | |
74 | 82 | $templates[] = 'footer.php'; |
75 | 83 | |
76 | | locate_template( $templates, true ); |
| 84 | locate_template( $templates, true, true, $wp_tmpl_args ); |
77 | 85 | } |
78 | 86 | |
79 | 87 | /** |
… |
… |
function get_footer( $name = null ) { |
86 | 94 | * "special". |
87 | 95 | * |
88 | 96 | * @since 1.5.0 |
| 97 | * @since 5.5.0 $wp_tmpl_args parameter added. |
89 | 98 | * |
90 | | * @param string $name The name of the specialised sidebar. |
| 99 | * @param string $name The name of the specialised sidebar. |
| 100 | * @param array $wp_tmpl_args Additional arguments passed to the sidebar template. |
91 | 101 | */ |
92 | | function get_sidebar( $name = null ) { |
| 102 | function get_sidebar( $name = null, $wp_tmpl_args = array() ) { |
93 | 103 | /** |
94 | 104 | * Fires before the sidebar template file is loaded. |
95 | 105 | * |
96 | 106 | * @since 2.2.0 |
97 | 107 | * @since 2.8.0 $name parameter added. |
| 108 | * @since 5.5.0 $wp_tmpl_args parameter added. |
98 | 109 | * |
99 | | * @param string|null $name Name of the specific sidebar file to use. null for the default sidebar. |
| 110 | * @param string|null $name Name of the specific sidebar file to use. null for the default sidebar. |
| 111 | * @param array $wp_tmpl_args Additional arguments passed to the sidebar template. |
100 | 112 | */ |
101 | | do_action( 'get_sidebar', $name ); |
| 113 | do_action( 'get_sidebar', $name, $wp_tmpl_args ); |
102 | 114 | |
103 | 115 | $templates = array(); |
104 | 116 | $name = (string) $name; |
… |
… |
function get_sidebar( $name = null ) { |
108 | 120 | |
109 | 121 | $templates[] = 'sidebar.php'; |
110 | 122 | |
111 | | locate_template( $templates, true ); |
| 123 | locate_template( $templates, true, true, $wp_tmpl_args ); |
112 | 124 | } |
113 | 125 | |
114 | 126 | /** |
… |
… |
function get_sidebar( $name = null ) { |
128 | 140 | * "special". |
129 | 141 | * |
130 | 142 | * @since 3.0.0 |
| 143 | * @since 5.5.0 $wp_tmpl_args parameter added. |
131 | 144 | * |
132 | | * @param string $slug The slug name for the generic template. |
133 | | * @param string $name The name of the specialised template. |
| 145 | * @param string $slug The slug name for the generic template. |
| 146 | * @param string $name The name of the specialised template. |
| 147 | * @param array $wp_tmpl_args Additional arguments passed to the template. |
134 | 148 | */ |
135 | | function get_template_part( $slug, $name = null ) { |
| 149 | function get_template_part( $slug, $name = null, $wp_tmpl_args = array() ) { |
136 | 150 | /** |
137 | 151 | * Fires before the specified template part file is loaded. |
138 | 152 | * |
… |
… |
function get_template_part( $slug, $name = null ) { |
140 | 154 | * for the generic template part. |
141 | 155 | * |
142 | 156 | * @since 3.0.0 |
| 157 | * @since 5.5.0 $wp_tmpl_args parameter added. |
143 | 158 | * |
144 | | * @param string $slug The slug name for the generic template. |
145 | | * @param string|null $name The name of the specialized template. |
| 159 | * @param string $slug The slug name for the generic template. |
| 160 | * @param string|null $name The name of the specialized template. |
| 161 | * @param array $wp_tmpl_args Additional arguments passed to the template. |
146 | 162 | */ |
147 | | do_action( "get_template_part_{$slug}", $slug, $name ); |
| 163 | do_action( "get_template_part_{$slug}", $slug, $name, $wp_tmpl_args ); |
148 | 164 | |
149 | 165 | $templates = array(); |
150 | 166 | $name = (string) $name; |
… |
… |
function get_template_part( $slug, $name = null ) { |
158 | 174 | * Fires before a template part is loaded. |
159 | 175 | * |
160 | 176 | * @since 5.2.0 |
| 177 | * @since 5.5.0 $wp_tmpl_args parameter added. |
161 | 178 | * |
162 | | * @param string $slug The slug name for the generic template. |
163 | | * @param string $name The name of the specialized template. |
164 | | * @param string[] $templates Array of template files to search for, in order. |
| 179 | * @param string $slug The slug name for the generic template. |
| 180 | * @param string $name The name of the specialized template. |
| 181 | * @param string[] $templates Array of template files to search for, in order. |
| 182 | * @param array $wp_tmpl_args Additional arguments passed to the template. |
165 | 183 | */ |
166 | | do_action( 'get_template_part', $slug, $name, $templates ); |
| 184 | do_action( 'get_template_part', $slug, $name, $templates, $wp_tmpl_args ); |
167 | 185 | |
168 | | locate_template( $templates, true, false ); |
| 186 | locate_template( $templates, true, false, $wp_tmpl_args ); |
169 | 187 | } |
170 | 188 | |
171 | 189 | /** |
… |
… |
function get_search_form( $args = array() ) { |
204 | 222 | * |
205 | 223 | * @since 2.7.0 as 'get_search_form' action. |
206 | 224 | * @since 3.6.0 |
| 225 | * @since 5.5.0 $args parameter added. |
| 226 | * |
| 227 | * @param array $args The array of arguments for building the search form. |
207 | 228 | * |
208 | 229 | * @link https://core.trac.wordpress.org/ticket/19321 |
209 | 230 | */ |
210 | | do_action( 'pre_get_search_form' ); |
| 231 | do_action( 'pre_get_search_form', $args ); |
211 | 232 | |
212 | 233 | $echo = true; |
213 | 234 | |
… |
… |
function get_search_form( $args = array() ) { |
246 | 267 | * Filters the HTML format of the search form. |
247 | 268 | * |
248 | 269 | * @since 3.6.0 |
| 270 | * @since 5.5.0 $args parameter added. |
249 | 271 | * |
250 | 272 | * @param string $format The type of markup to use in the search form. |
251 | 273 | * Accepts 'html5', 'xhtml'. |
| 274 | * @param array $args The array of arguments for building the search form. |
252 | 275 | */ |
253 | | $format = apply_filters( 'search_form_format', $format ); |
| 276 | $format = apply_filters( 'search_form_format', $format, $args ); |
254 | 277 | |
255 | 278 | $search_form_template = locate_template( 'searchform.php' ); |
256 | 279 | |
… |
… |
function get_search_form( $args = array() ) { |
292 | 315 | * Filters the HTML output of the search form. |
293 | 316 | * |
294 | 317 | * @since 2.7.0 |
| 318 | * @since 5.5.0 $args parameter added. |
295 | 319 | * |
296 | 320 | * @param string $form The search form HTML output. |
| 321 | * @param array $args The array of arguments for building the search form. |
297 | 322 | */ |
298 | | $result = apply_filters( 'get_search_form', $form ); |
| 323 | $result = apply_filters( 'get_search_form', $form, $args ); |
299 | 324 | |
300 | 325 | if ( null === $result ) { |
301 | 326 | $result = $form; |
diff --git src/wp-includes/template.php src/wp-includes/template.php
index 51a4c86358..04a5027862 100644
|
|
function get_attachment_template() { |
644 | 644 | * so that themes which inherit from a parent theme can just overload one file. |
645 | 645 | * |
646 | 646 | * @since 2.7.0 |
| 647 | * @since 5.5.0 $wp_tmpl_args parameter added. |
647 | 648 | * |
648 | 649 | * @param string|array $template_names Template file(s) to search for, in order. |
649 | 650 | * @param bool $load If true the template file will be loaded if it is found. |
650 | 651 | * @param bool $require_once Whether to require_once or require. Default true. Has no effect if $load is false. |
| 652 | * @param array $wp_tmpl_args Additional arguments passed to the template. |
651 | 653 | * @return string The template filename if one is located. |
652 | 654 | */ |
653 | | function locate_template( $template_names, $load = false, $require_once = true ) { |
| 655 | function locate_template( $template_names, $load = false, $require_once = true, $wp_tmpl_args = array() ) { |
654 | 656 | $located = ''; |
655 | 657 | foreach ( (array) $template_names as $template_name ) { |
656 | 658 | if ( ! $template_name ) { |
… |
… |
function locate_template( $template_names, $load = false, $require_once = true ) |
669 | 671 | } |
670 | 672 | |
671 | 673 | if ( $load && '' !== $located ) { |
672 | | load_template( $located, $require_once ); |
| 674 | load_template( $located, $require_once, $wp_tmpl_args ); |
673 | 675 | } |
674 | 676 | |
675 | 677 | return $located; |
… |
… |
function locate_template( $template_names, $load = false, $require_once = true ) |
683 | 685 | * also available. |
684 | 686 | * |
685 | 687 | * @since 1.5.0 |
| 688 | * @since 5.5.0 $wp_tmpl_args parameter added. |
686 | 689 | * |
687 | 690 | * @global array $posts |
688 | 691 | * @global WP_Post $post Global post object. |
… |
… |
function locate_template( $template_names, $load = false, $require_once = true ) |
698 | 701 | * |
699 | 702 | * @param string $_template_file Path to template file. |
700 | 703 | * @param bool $require_once Whether to require_once or require. Default true. |
| 704 | * @param array $wp_tmpl_args Additional arguments passed to the template. |
701 | 705 | */ |
702 | | function load_template( $_template_file, $require_once = true ) { |
| 706 | function load_template( $_template_file, $require_once = true, $wp_tmpl_args = array() ) { |
703 | 707 | global $posts, $post, $wp_did_header, $wp_query, $wp_rewrite, $wpdb, $wp_version, $wp, $id, $comment, $user_ID; |
704 | 708 | |
705 | 709 | if ( is_array( $wp_query->query_vars ) ) { |
diff --git tests/phpunit/data/themedir1/theme1/header.php tests/phpunit/data/themedir1/theme1/header.php
new file mode 100644
index 0000000000..9da09ebcb3
-
|
+
|
|
| 1 | <?php |
| 2 | echo json_encode( $wp_tmpl_args ); |
diff --git tests/phpunit/tests/general/template.php tests/phpunit/tests/general/template.php
index 170a86d9f9..82373bd9d5 100644
|
|
class Tests_General_Template extends WP_UnitTestCase { |
642 | 642 | self::assertSame( 'Template Part', trim( $output ) ); |
643 | 643 | self::assertSame( null, $part ); |
644 | 644 | } |
| 645 | |
| 646 | /** |
| 647 | * @ticket 21676 |
| 648 | */ |
| 649 | function test_load_template_with_params() { |
| 650 | load_template( DIR_TESTDATA . '/themedir1/theme1/header.php', false, array( 'foo' => 'baz' ) ); |
| 651 | $this->expectOutputString( '{"foo":"baz"}' ); |
| 652 | } |
645 | 653 | } |