Ticket #21676: 21676.6.patch
File 21676.6.patch, 9.2 KB (added by , 8 years ago) |
---|
-
src/wp-includes/general-template.php
16 16 * "special". 17 17 * 18 18 * @since 1.5.0 19 * @since 4.8.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 * … … 29 31 * 30 32 * @since 2.1.0 31 33 * @since 2.8.0 $name parameter added. 34 * @since 4.8.0 $params parameter added. 32 35 * 33 * @param string|null $name Name of the specific header file to use. null for the default header. 36 * @param string|null $name Name of the specific header file to use. null for the default header. 37 * @param array $params Additional arguments passed to the header template. 34 38 */ 35 do_action( 'get_header', $name );39 do_action( 'get_header', $name, $params ); 36 40 37 41 $templates = array(); 38 42 $name = (string) $name; … … 42 46 43 47 $templates[] = 'header.php'; 44 48 45 locate_template( $templates, true );49 locate_template( $templates, true, true, $params ); 46 50 } 47 51 48 52 /** … … 55 59 * "special". 56 60 * 57 61 * @since 1.5.0 62 * @since 4.8.0 $params parameter added. 58 63 * 59 * @param string $name The name of the specialised footer. 64 * @param string $name The name of the specialised footer. 65 * @param array $params Additional arguments passed to the footer template. 60 66 */ 61 function get_footer( $name = null ) {67 function get_footer( $name = null, $params = array() ) { 62 68 /** 63 69 * Fires before the footer template file is loaded. 64 70 * … … 68 74 * 69 75 * @since 2.1.0 70 76 * @since 2.8.0 $name parameter added. 77 * @since 4.8.0 $params parameter added. 71 78 * 72 * @param string|null $name Name of the specific footer file to use. null for the default footer. 79 * @param string|null $name Name of the specific footer file to use. null for the default footer. 80 * @param array $params Additional arguments passed to the header template. 73 81 */ 74 do_action( 'get_footer', $name );82 do_action( 'get_footer', $name, $params ); 75 83 76 84 $templates = array(); 77 85 $name = (string) $name; … … 81 89 82 90 $templates[] = 'footer.php'; 83 91 84 locate_template( $templates, true );92 locate_template( $templates, true, true, $params ); 85 93 } 86 94 87 95 /** … … 94 102 * "special". 95 103 * 96 104 * @since 1.5.0 105 * @since 4.8.0 $params parameter added. 97 106 * 98 * @param string $name The name of the specialised sidebar. 107 * @param string $name The name of the specialised sidebar. 108 * @param array $params Additional arguments passed to the sidebar template. 99 109 */ 100 function get_sidebar( $name = null ) {110 function get_sidebar( $name = null, $params = array() ) { 101 111 /** 102 112 * Fires before the sidebar template file is loaded. 103 113 * … … 107 117 * 108 118 * @since 2.2.0 109 119 * @since 2.8.0 $name parameter added. 120 * @since 4.8.0 $params parameter added. 110 121 * 111 * @param string|null $name Name of the specific sidebar file to use. null for the default sidebar. 122 * @param string|null $name Name of the specific sidebar file to use. null for the default sidebar. 123 * @param array $params Additional arguments passed to the sidebar template. 112 124 */ 113 do_action( 'get_sidebar', $name );125 do_action( 'get_sidebar', $name, $params ); 114 126 115 127 $templates = array(); 116 128 $name = (string) $name; … … 119 131 120 132 $templates[] = 'sidebar.php'; 121 133 122 locate_template( $templates, true );134 locate_template( $templates, true, true, $params ); 123 135 } 124 136 125 137 /** … … 139 151 * "special". 140 152 * 141 153 * @since 3.0.0 154 * @since 4.8.0 $params parameter added. 142 155 * 143 * @param string $slug The slug name for the generic template. 144 * @param string $name The name of the specialised template. 156 * @param string $slug The slug name for the generic template. 157 * @param string $name The name of the specialised template. 158 * @param array $params Additional arguments passed to the template. 145 159 */ 146 function get_template_part( $slug, $name = null ) {160 function get_template_part( $slug, $name = null, $params = array() ) { 147 161 /** 148 162 * Fires before the specified template part file is loaded. 149 163 * … … 151 165 * for the generic template part. 152 166 * 153 167 * @since 3.0.0 154 * 155 * @param string $slug The slug name for the generic template. 156 * @param string|null $name The name of the specialized template. 168 * @since 4.5.0 $params parameter added 169 * 170 * @param string $slug The slug name for the generic template. 171 * @param string|null $name The name of the specialized template. 172 * @param array $params Additional arguments passed to the template. 157 173 */ 158 do_action( "get_template_part_{$slug}", $slug, $name );174 do_action( "get_template_part_{$slug}", $slug, $name, $params ); 159 175 160 176 $templates = array(); 161 177 $name = (string) $name; … … 164 180 165 181 $templates[] = "{$slug}.php"; 166 182 167 locate_template($templates, true, false );183 locate_template($templates, true, false, $params); 168 184 } 169 185 170 186 /** … … 185 201 * search. To give a few examples of what it can be used for. 186 202 * 187 203 * @since 2.7.0 188 * 189 * @param bool $echo Default to echo and not return the form. 204 * @since 4.8.0 $params parameter added. 205 * 206 * @param bool $echo Default to echo and not return the form. 207 * @param array $params Additional arguments passed to the template. 190 208 * @return string|void String when $echo is false. 191 209 */ 192 function get_search_form( $echo = true ) {210 function get_search_form( $echo = true, $params = array() ) { 193 211 /** 194 212 * Fires before the search form is retrieved, at the start of get_search_form(). 195 213 * … … 197 215 * @since 3.6.0 198 216 * 199 217 * @link https://core.trac.wordpress.org/ticket/19321 218 * 219 * @param array $params Additional arguments passed to the template. 200 220 */ 201 do_action( 'pre_get_search_form' );221 do_action( 'pre_get_search_form', $params ); 202 222 203 223 $format = current_theme_supports( 'html5', 'search-form' ) ? 'html5' : 'xhtml'; 204 224 … … 243 263 * @since 2.7.0 244 264 * 245 265 * @param string $form The search form HTML output. 266 * @param array $params Additional arguments passed to the template. 246 267 */ 247 $result = apply_filters( 'get_search_form', $form );268 $result = apply_filters( 'get_search_form', $form, $params ); 248 269 249 270 if ( null === $result ) 250 271 $result = $form; -
src/wp-includes/template.php
617 617 * so that themes which inherit from a parent theme can just overload one file. 618 618 * 619 619 * @since 2.7.0 620 * @since 4.8.0 $params parameter added. 620 621 * 621 622 * @param string|array $template_names Template file(s) to search for, in order. 622 623 * @param bool $load If true the template file will be loaded if it is found. 623 624 * @param bool $require_once Whether to require_once or require. Default true. Has no effect if $load is false. 625 * @param array $params Additional arguments passed to the template. 624 626 * @return string The template filename if one is located. 625 627 */ 626 function locate_template($template_names, $load = false, $require_once = true ) {628 function locate_template($template_names, $load = false, $require_once = true, $params = array() ) { 627 629 $located = ''; 628 630 foreach ( (array) $template_names as $template_name ) { 629 631 if ( !$template_name ) … … 641 643 } 642 644 643 645 if ( $load && '' != $located ) 644 load_template( $located, $require_once );646 load_template( $located, $require_once, $params ); 645 647 646 648 return $located; 647 649 } … … 654 656 * also available. 655 657 * 656 658 * @since 1.5.0 659 * @since 4.8.0 $params parameter added. 657 660 * 658 661 * @global array $posts 659 662 * @global WP_Post $post … … 669 672 * 670 673 * @param string $_template_file Path to template file. 671 674 * @param bool $require_once Whether to require_once or require. Default true. 675 * @param array $params Additional arguments passed to the template. 672 676 */ 673 function load_template( $_template_file, $require_once = true ) {677 function load_template( $_template_file, $require_once = true, $params = array() ) { 674 678 global $posts, $post, $wp_did_header, $wp_query, $wp_rewrite, $wpdb, $wp_version, $wp, $id, $comment, $user_ID; 675 679 676 680 if ( is_array( $wp_query->query_vars ) ) { -
tests/phpunit/tests/general/template.php
597 597 598 598 $this->assertSame( $expected, $result ); 599 599 } 600 601 /** 602 * @ticket 36187 603 */ 604 function test_load_template_with_params () { 605 load_template( DIR_TESTDATA . '/themedir1/theme1/header.php', false, array( 'foo' => 'baz' ) ); 606 $this->expectOutputString( '{"foo":"baz"}' ); 607 } 600 608 } -
tests/phpunit/data/themedir1/theme1/header.php
1 <?php 2 echo json_encode($params);