Ticket #21676: 21676.9.patch
File 21676.9.patch, 9.2 KB (added by , 7 years ago) |
---|
-
src/wp-includes/general-template.php
16 16 * "special". 17 17 * 18 18 * @since 1.5.0 19 * @since 4.9.0 `$params` 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 $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 4.9.0 `$params` 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 $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; … … 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 /** … … 51 55 * "special". 52 56 * 53 57 * @since 1.5.0 58 * @since 4.9.0 `$params` 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 $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 4.9.0 `$params` 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 $params Additional arguments passed to the header 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; … … 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 /** … … 86 94 * "special". 87 95 * 88 96 * @since 1.5.0 97 * @since 4.9.0 `$params` 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 $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 4.9.0 `$params` 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 $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; … … 107 119 108 120 $templates[] = 'sidebar.php'; 109 121 110 locate_template( $templates, true );122 locate_template( $templates, true, true, $params ); 111 123 } 112 124 113 125 /** … … 127 139 * "special". 128 140 * 129 141 * @since 3.0.0 142 * @since 4.9.0 `$params` parameter added. 130 143 * 131 * @param string $slug The slug name for the generic template. 132 * @param string $name The name of the specialised template. 144 * @param string $slug The slug name for the generic template. 145 * @param string $name The name of the specialised template. 146 * @param array $params Additional arguments passed to the template. 133 147 */ 134 function get_template_part( $slug, $name = null ) {148 function get_template_part( $slug, $name = null, $params = array() ) { 135 149 /** 136 150 * Fires before the specified template part file is loaded. 137 151 * … … 139 153 * for the generic template part. 140 154 * 141 155 * @since 3.0.0 142 * 143 * @param string $slug The slug name for the generic template. 144 * @param string|null $name The name of the specialized template. 156 * @since 4.9.0 `$params` parameter added 157 * 158 * @param string $slug The slug name for the generic template. 159 * @param string|null $name The name of the specialized template. 160 * @param array $params Additional arguments passed to the template. 145 161 */ 146 do_action( "get_template_part_{$slug}", $slug, $name );162 do_action( "get_template_part_{$slug}", $slug, $name, $params ); 147 163 148 164 $templates = array(); 149 165 $name = (string) $name; … … 152 168 153 169 $templates[] = "{$slug}.php"; 154 170 155 locate_template($templates, true, false );171 locate_template($templates, true, false, $params); 156 172 } 157 173 158 174 /** … … 173 189 * search. To give a few examples of what it can be used for. 174 190 * 175 191 * @since 2.7.0 176 * 177 * @param bool $echo Default to echo and not return the form. 192 * @since 4.9.0 `$params` parameter added. 193 * 194 * @param bool $echo Default to echo and not return the form. 195 * @param array $params Additional arguments passed to the template. 178 196 * @return string|void String when $echo is false. 179 197 */ 180 function get_search_form( $echo = true ) {198 function get_search_form( $echo = true, $params = array() ) { 181 199 /** 182 200 * Fires before the search form is retrieved, at the start of get_search_form(). 183 201 * … … 185 203 * @since 3.6.0 186 204 * 187 205 * @link https://core.trac.wordpress.org/ticket/19321 206 * 207 * @param array $params Additional arguments passed to the template. 188 208 */ 189 do_action( 'pre_get_search_form' );209 do_action( 'pre_get_search_form', $params ); 190 210 191 211 $format = current_theme_supports( 'html5', 'search-form' ) ? 'html5' : 'xhtml'; 192 212 … … 231 251 * @since 2.7.0 232 252 * 233 253 * @param string $form The search form HTML output. 254 * @param array $params Additional arguments passed to the template. 234 255 */ 235 $result = apply_filters( 'get_search_form', $form );256 $result = apply_filters( 'get_search_form', $form, $params ); 236 257 237 258 if ( null === $result ) 238 259 $result = $form; -
src/wp-includes/template.php
620 620 * so that themes which inherit from a parent theme can just overload one file. 621 621 * 622 622 * @since 2.7.0 623 * @since 4.9.0 `$params` parameter added. 623 624 * 624 625 * @param string|array $template_names Template file(s) to search for, in order. 625 626 * @param bool $load If true the template file will be loaded if it is found. 626 627 * @param bool $require_once Whether to require_once or require. Default true. Has no effect if $load is false. 628 * @param array $params Additional arguments passed to the template. 627 629 * @return string The template filename if one is located. 628 630 */ 629 function locate_template($template_names, $load = false, $require_once = true ) {631 function locate_template($template_names, $load = false, $require_once = true, $params = array() ) { 630 632 $located = ''; 631 633 foreach ( (array) $template_names as $template_name ) { 632 634 if ( !$template_name ) … … 644 646 } 645 647 646 648 if ( $load && '' != $located ) 647 load_template( $located, $require_once );649 load_template( $located, $require_once, $params ); 648 650 649 651 return $located; 650 652 } … … 657 659 * also available. 658 660 * 659 661 * @since 1.5.0 662 * @since 4.9.0 `$params` parameter added. 660 663 * 661 664 * @global array $posts 662 665 * @global WP_Post $post … … 672 675 * 673 676 * @param string $_template_file Path to template file. 674 677 * @param bool $require_once Whether to require_once or require. Default true. 678 * @param array $params Additional arguments passed to the template. 675 679 */ 676 function load_template( $_template_file, $require_once = true ) {680 function load_template( $_template_file, $require_once = true, $params = array() ) { 677 681 global $posts, $post, $wp_did_header, $wp_query, $wp_rewrite, $wpdb, $wp_version, $wp, $id, $comment, $user_ID; 678 682 679 683 if ( is_array( $wp_query->query_vars ) ) { -
tests/phpunit/tests/general/template.php
611 611 612 612 $this->assertSame( $expected, $result ); 613 613 } 614 615 /** 616 * @ticket 21676 617 */ 618 function test_load_template_with_params () { 619 load_template( DIR_TESTDATA . '/themedir1/theme1/header.php', false, array( 'foo' => 'baz' ) ); 620 $this->expectOutputString( '{"foo":"baz"}' ); 621 } 614 622 } -
tests/phpunit/data/themedir1/theme1/header.php
1 <?php 2 echo json_encode($params);