diff --git a/src/wp-includes/general-template.php b/src/wp-includes/general-template.php
index ca2dbc0..7a356c0 100644
|
a
|
b
|
|
| 16 | 16 | * "special". |
| 17 | 17 | * |
| 18 | 18 | * @since 1.5.0 |
| | 19 | * @since 5.0.0 $params paramenter 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 $params Additional arguments passed to the header template. |
| 21 | 23 | */ |
| 22 | | function get_header( $name = null ) { |
| | 24 | function get_header( $name = null, $params = 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.0.0 $params paramenter 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 $params Additional arguments passed to the header template. |
| 30 | 34 | */ |
| 31 | | do_action( 'get_header', $name ); |
| | 35 | do_action( 'get_header', $name, $params ); |
| 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, $params ); |
| 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.0.0 $params paramenter 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 $params Additional arguments passed to the footer template. |
| 56 | 62 | */ |
| 57 | | function get_footer( $name = null ) { |
| | 63 | function get_footer( $name = null, $params = 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.0.0 $params paramenter 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 $params Additional arguments passed to the footer template. |
| 65 | 73 | */ |
| 66 | | do_action( 'get_footer', $name ); |
| | 74 | do_action( 'get_footer', $name, $params ); |
| 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, $params ); |
| 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.0.0 $params paramenter 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 $params Additional arguments passed to the sidebar template. |
| 91 | 101 | */ |
| 92 | | function get_sidebar( $name = null ) { |
| | 102 | function get_sidebar( $name = null, $params = 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.0.0 $params paramenter 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 $params Additional arguments passed to the sidebar template. |
| 100 | 112 | */ |
| 101 | | do_action( 'get_sidebar', $name ); |
| | 113 | do_action( 'get_sidebar', $name, $params ); |
| 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, $params ); |
| 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.0.0 $params paramenter 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 $params Additional arguments passed to the template. |
| 134 | 148 | */ |
| 135 | | function get_template_part( $slug, $name = null ) { |
| | 149 | function get_template_part( $slug, $name = null, $params = 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.0.0 $params paramenter 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 $params 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, $params ); |
| 148 | 164 | |
| 149 | 165 | $templates = array(); |
| 150 | 166 | $name = (string) $name; |
| … |
… |
function get_template_part( $slug, $name = null ) { |
| 154 | 170 | |
| 155 | 171 | $templates[] = "{$slug}.php"; |
| 156 | 172 | |
| 157 | | locate_template( $templates, true, false ); |
| | 173 | locate_template( $templates, true, false, $params ); |
| 158 | 174 | } |
| 159 | 175 | |
| 160 | 176 | /** |
| … |
… |
function get_template_part( $slug, $name = null ) { |
| 175 | 191 | * search. To give a few examples of what it can be used for. |
| 176 | 192 | * |
| 177 | 193 | * @since 2.7.0 |
| | 194 | * @since 5.0.0 $params paramenter added. |
| 178 | 195 | * |
| 179 | | * @param bool $echo Default to echo and not return the form. |
| | 196 | * @param bool $echo Default to echo and not return the form. |
| | 197 | * @param array $params Additional arguments passed to the search form template. |
| 180 | 198 | * @return string|void String when $echo is false. |
| 181 | 199 | */ |
| 182 | | function get_search_form( $echo = true ) { |
| | 200 | function get_search_form( $echo = true, $params = array() ) { |
| 183 | 201 | /** |
| 184 | 202 | * Fires before the search form is retrieved, at the start of get_search_form(). |
| 185 | 203 | * |
| 186 | 204 | * @since 2.7.0 as 'get_search_form' action. |
| 187 | 205 | * @since 3.6.0 |
| | 206 | * @since 5.0.0 $params paramenter added. |
| | 207 | * |
| | 208 | * @param array $params Additional arguments passed to the search form template. |
| 188 | 209 | * |
| 189 | 210 | * @link https://core.trac.wordpress.org/ticket/19321 |
| 190 | 211 | */ |
| 191 | | do_action( 'pre_get_search_form' ); |
| | 212 | do_action( 'pre_get_search_form', $params ); |
| 192 | 213 | |
| 193 | 214 | $format = current_theme_supports( 'html5', 'search-form' ) ? 'html5' : 'xhtml'; |
| 194 | 215 | |
| … |
… |
function get_search_form( $echo = true ) { |
| 196 | 217 | * Filters the HTML format of the search form. |
| 197 | 218 | * |
| 198 | 219 | * @since 3.6.0 |
| | 220 | * @since 5.0.0 $params paramenter added. |
| 199 | 221 | * |
| 200 | 222 | * @param string $format The type of markup to use in the search form. |
| 201 | 223 | * Accepts 'html5', 'xhtml'. |
| | 224 | * @param array $params Additional arguments passed to the search form template. |
| 202 | 225 | */ |
| 203 | | $format = apply_filters( 'search_form_format', $format ); |
| | 226 | $format = apply_filters( 'search_form_format', $format, $params ); |
| 204 | 227 | |
| 205 | 228 | $search_form_template = locate_template( 'searchform.php' ); |
| 206 | 229 | if ( '' != $search_form_template ) { |
| … |
… |
function get_search_form( $echo = true ) { |
| 231 | 254 | * Filters the HTML output of the search form. |
| 232 | 255 | * |
| 233 | 256 | * @since 2.7.0 |
| | 257 | * @since 5.0.0 $params paramenter added. |
| 234 | 258 | * |
| 235 | | * @param string $form The search form HTML output. |
| | 259 | * @param string $form The search form HTML output. |
| | 260 | * @param array $params Additional arguments passed to the search form template. |
| 236 | 261 | */ |
| 237 | | $result = apply_filters( 'get_search_form', $form ); |
| | 262 | $result = apply_filters( 'get_search_form', $form, $params ); |
| 238 | 263 | |
| 239 | 264 | if ( null === $result ) { |
| 240 | 265 | $result = $form; |
diff --git a/src/wp-includes/template.php b/src/wp-includes/template.php
index b0b49fe..86f647f 100644
|
a
|
b
|
function get_attachment_template() { |
| 625 | 625 | * so that themes which inherit from a parent theme can just overload one file. |
| 626 | 626 | * |
| 627 | 627 | * @since 2.7.0 |
| | 628 | * @since 5.0.0 $params paramenter added. |
| 628 | 629 | * |
| 629 | 630 | * @param string|array $template_names Template file(s) to search for, in order. |
| 630 | 631 | * @param bool $load If true the template file will be loaded if it is found. |
| 631 | 632 | * @param bool $require_once Whether to require_once or require. Default true. Has no effect if $load is false. |
| | 633 | * @param array $params Additional arguments passed to the template. |
| 632 | 634 | * @return string The template filename if one is located. |
| 633 | 635 | */ |
| 634 | | function locate_template( $template_names, $load = false, $require_once = true ) { |
| | 636 | function locate_template( $template_names, $load = false, $require_once = true, $params = array() ) { |
| 635 | 637 | $located = ''; |
| 636 | 638 | foreach ( (array) $template_names as $template_name ) { |
| 637 | 639 | if ( ! $template_name ) { |
| … |
… |
function locate_template( $template_names, $load = false, $require_once = true ) |
| 650 | 652 | } |
| 651 | 653 | |
| 652 | 654 | if ( $load && '' != $located ) { |
| 653 | | load_template( $located, $require_once ); |
| | 655 | load_template( $located, $require_once, $params ); |
| 654 | 656 | } |
| 655 | 657 | |
| 656 | 658 | return $located; |
| … |
… |
function locate_template( $template_names, $load = false, $require_once = true ) |
| 664 | 666 | * also available. |
| 665 | 667 | * |
| 666 | 668 | * @since 1.5.0 |
| | 669 | * @since 5.0.0 $params paramenter added. |
| 667 | 670 | * |
| 668 | 671 | * @global array $posts |
| 669 | 672 | * @global WP_Post $post |
| … |
… |
function locate_template( $template_names, $load = false, $require_once = true ) |
| 679 | 682 | * |
| 680 | 683 | * @param string $_template_file Path to template file. |
| 681 | 684 | * @param bool $require_once Whether to require_once or require. Default true. |
| | 685 | * @param array $params Additional arguments passed to the template. |
| 682 | 686 | */ |
| 683 | | function load_template( $_template_file, $require_once = true ) { |
| | 687 | function load_template( $_template_file, $require_once = true, $params = array() ) { |
| 684 | 688 | global $posts, $post, $wp_did_header, $wp_query, $wp_rewrite, $wpdb, $wp_version, $wp, $id, $comment, $user_ID; |
| 685 | 689 | |
| 686 | 690 | if ( is_array( $wp_query->query_vars ) ) { |
diff --git a/tests/phpunit/data/themedir1/theme1/header.php b/tests/phpunit/data/themedir1/theme1/header.php
new file mode 100644
index 0000000..cba948b
|
-
|
+
|
|
| | 1 | <?php |
| | 2 | echo json_encode($params); |
diff --git a/tests/phpunit/tests/general/template.php b/tests/phpunit/tests/general/template.php
index 05ef977..b07caf3 100644
|
a
|
b
|
class Tests_General_Template extends WP_UnitTestCase { |
| 612 | 612 | |
| 613 | 613 | $this->assertSame( $expected, $result ); |
| 614 | 614 | } |
| | 615 | |
| | 616 | /** |
| | 617 | * @ticket 21676 |
| | 618 | */ |
| | 619 | function test_load_template_with_params () { |
| | 620 | load_template( DIR_TESTDATA . '/themedir1/theme1/header.php', false, array( 'foo' => 'baz' ) ); |
| | 621 | $this->expectOutputString( '{"foo":"baz"}' ); |
| | 622 | } |
| 615 | 623 | } |