Changeset 48370
- Timestamp:
- 07/07/2020 11:00:21 AM (4 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/general-template.php
r48311 r48370 18 18 * @since 1.5.0 19 19 * @since 5.5.0 A return value was added. 20 * @since 5.5.0 The `$args` parameter was added. 20 21 * 21 22 * @param string $name The name of the specialised header. 23 * @param array $args Optional. Additional arguments passed to the header template. 24 * Default empty array. 22 25 * @return void|false Void on success, false if the template does not exist. 23 26 */ 24 function get_header( $name = null ) {27 function get_header( $name = null, $args = array() ) { 25 28 /** 26 29 * Fires before the header template file is loaded. 27 30 * 28 31 * @since 2.1.0 29 * @since 2.8.0 $name parameter added. 30 * 31 * @param string|null $name Name of the specific header file to use. null for the default header. 32 */ 33 do_action( 'get_header', $name ); 32 * @since 2.8.0 The `$name` parameter was added. 33 * @since 5.5.0 The `$args` parameter was added. 34 * 35 * @param string|null $name Name of the specific header file to use. Null for the default header. 36 * @param array $args Additional arguments passed to the header template. 37 */ 38 do_action( 'get_header', $name, $args ); 34 39 35 40 $templates = array(); … … 41 46 $templates[] = 'header.php'; 42 47 43 if ( ! locate_template( $templates, true ) ) {48 if ( ! locate_template( $templates, true, true, $args ) ) { 44 49 return false; 45 50 } … … 57 62 * @since 1.5.0 58 63 * @since 5.5.0 A return value was added. 64 * @since 5.5.0 The `$args` parameter was added. 59 65 * 60 66 * @param string $name The name of the specialised footer. 67 * @param array $args Optional. Additional arguments passed to the footer template. 68 * Default empty array. 61 69 * @return void|false Void on success, false if the template does not exist. 62 70 */ 63 function get_footer( $name = null ) {71 function get_footer( $name = null, $args = array() ) { 64 72 /** 65 73 * Fires before the footer template file is loaded. 66 74 * 67 75 * @since 2.1.0 68 * @since 2.8.0 $name parameter added. 69 * 70 * @param string|null $name Name of the specific footer file to use. null for the default footer. 71 */ 72 do_action( 'get_footer', $name ); 76 * @since 2.8.0 The `$name` parameter was added. 77 * @since 5.5.0 The `$args` parameter was added. 78 * 79 * @param string|null $name Name of the specific footer file to use. Null for the default footer. 80 * @param array $args Additional arguments passed to the footer template. 81 */ 82 do_action( 'get_footer', $name, $args ); 73 83 74 84 $templates = array(); … … 80 90 $templates[] = 'footer.php'; 81 91 82 if ( ! locate_template( $templates, true ) ) {92 if ( ! locate_template( $templates, true, true, $args ) ) { 83 93 return false; 84 94 } … … 96 106 * @since 1.5.0 97 107 * @since 5.5.0 A return value was added. 108 * @since 5.5.0 The `$args` parameter was added. 98 109 * 99 110 * @param string $name The name of the specialised sidebar. 111 * @param array $args Optional. Additional arguments passed to the sidebar template. 112 * Default empty array. 100 113 * @return void|false Void on success, false if the template does not exist. 101 114 */ 102 function get_sidebar( $name = null ) {115 function get_sidebar( $name = null, $args = array() ) { 103 116 /** 104 117 * Fires before the sidebar template file is loaded. 105 118 * 106 119 * @since 2.2.0 107 * @since 2.8.0 $name parameter added. 108 * 109 * @param string|null $name Name of the specific sidebar file to use. null for the default sidebar. 110 */ 111 do_action( 'get_sidebar', $name ); 120 * @since 2.8.0 The `$name` parameter was added. 121 * @since 5.5.0 The `$args` parameter was added. 122 * 123 * @param string|null $name Name of the specific sidebar file to use. Null for the default sidebar. 124 * @param array $args Additional arguments passed to the sidebar template. 125 */ 126 do_action( 'get_sidebar', $name, $args ); 112 127 113 128 $templates = array(); … … 119 134 $templates[] = 'sidebar.php'; 120 135 121 if ( ! locate_template( $templates, true ) ) {136 if ( ! locate_template( $templates, true, true, $args ) ) { 122 137 return false; 123 138 } … … 142 157 * @since 3.0.0 143 158 * @since 5.5.0 A return value was added. 159 * @since 5.5.0 The `$args` parameter was added. 144 160 * 145 161 * @param string $slug The slug name for the generic template. 146 162 * @param string $name The name of the specialised template. 163 * @param array $args Optional. Additional arguments passed to the template. 164 * Default empty array. 147 165 * @return void|false Void on success, false if the template does not exist. 148 166 */ 149 function get_template_part( $slug, $name = null ) {167 function get_template_part( $slug, $name = null, $args = array() ) { 150 168 /** 151 169 * Fires before the specified template part file is loaded. … … 155 173 * 156 174 * @since 3.0.0 175 * @since 5.5.0 The `$args` parameter was added. 157 176 * 158 177 * @param string $slug The slug name for the generic template. 159 178 * @param string|null $name The name of the specialized template. 160 */ 161 do_action( "get_template_part_{$slug}", $slug, $name ); 179 * @param array $args Additional arguments passed to the template. 180 */ 181 do_action( "get_template_part_{$slug}", $slug, $name, $args ); 162 182 163 183 $templates = array(); … … 173 193 * 174 194 * @since 5.2.0 195 * @since 5.5.0 The `$args` parameter was added. 175 196 * 176 197 * @param string $slug The slug name for the generic template. 177 198 * @param string $name The name of the specialized template. 178 199 * @param string[] $templates Array of template files to search for, in order. 179 */ 180 do_action( 'get_template_part', $slug, $name, $templates ); 181 182 if ( ! locate_template( $templates, true, false ) ) { 200 * @param array $args Additional arguments passed to the template. 201 */ 202 do_action( 'get_template_part', $slug, $name, $templates, $args ); 203 204 if ( ! locate_template( $templates, true, false, $args ) ) { 183 205 return false; 184 206 } … … 203 225 * 204 226 * @since 2.7.0 205 * @since 5.2.0 The $args array parameter was added in place of an $echoboolean flag.227 * @since 5.2.0 The `$args` array parameter was added in place of an `$echo` boolean flag. 206 228 * 207 229 * @param array $args { … … 221 243 * @since 2.7.0 as 'get_search_form' action. 222 244 * @since 3.6.0 245 * @since 5.5.0 The `$args` parameter was added. 223 246 * 224 247 * @link https://core.trac.wordpress.org/ticket/19321 225 */ 226 do_action( 'pre_get_search_form' ); 248 * 249 * @param array $args The array of arguments for building the search form. 250 */ 251 do_action( 'pre_get_search_form', $args ); 227 252 228 253 $echo = true; … … 263 288 * 264 289 * @since 3.6.0 290 * @since 5.5.0 The `$args` parameter was added. 265 291 * 266 292 * @param string $format The type of markup to use in the search form. 267 293 * Accepts 'html5', 'xhtml'. 268 */ 269 $format = apply_filters( 'search_form_format', $format ); 294 * @param array $args The array of arguments for building the search form. 295 */ 296 $format = apply_filters( 'search_form_format', $format, $args ); 270 297 271 298 $search_form_template = locate_template( 'searchform.php' ); … … 309 336 * 310 337 * @since 2.7.0 338 * @since 5.5.0 The `$args` parameter was added. 311 339 * 312 340 * @param string $form The search form HTML output. 313 */ 314 $result = apply_filters( 'get_search_form', $form ); 341 * @param array $args The array of arguments for building the search form. 342 */ 343 $result = apply_filters( 'get_search_form', $form, $args ); 315 344 316 345 if ( null === $result ) { -
trunk/src/wp-includes/template.php
r47808 r48370 645 645 * 646 646 * @since 2.7.0 647 * @since 5.5.0 The `$args` parameter was 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 * @param bool $require_once Whether to require_once or require. Default true. Has no effect if $load is false. 651 * @param bool $require_once Whether to require_once or require. Has no effect if `$load` is false. 652 * Default true. 653 * @param array $args Optional. Additional arguments passed to the template. 654 * Default empty array. 651 655 * @return string The template filename if one is located. 652 656 */ 653 function locate_template( $template_names, $load = false, $require_once = true ) {657 function locate_template( $template_names, $load = false, $require_once = true, $args = array() ) { 654 658 $located = ''; 655 659 foreach ( (array) $template_names as $template_name ) { … … 670 674 671 675 if ( $load && '' !== $located ) { 672 load_template( $located, $require_once );676 load_template( $located, $require_once, $args ); 673 677 } 674 678 … … 684 688 * 685 689 * @since 1.5.0 690 * @since 5.5.0 The `$args` parameter was added. 686 691 * 687 692 * @global array $posts … … 699 704 * @param string $_template_file Path to template file. 700 705 * @param bool $require_once Whether to require_once or require. Default true. 701 */ 702 function load_template( $_template_file, $require_once = true ) { 706 * @param array $args Optional. Additional arguments passed to the template. 707 * Default empty array. 708 */ 709 function load_template( $_template_file, $require_once = true, $args = array() ) { 703 710 global $posts, $post, $wp_did_header, $wp_query, $wp_rewrite, $wpdb, $wp_version, $wp, $id, $comment, $user_ID; 704 711 -
trunk/tests/phpunit/data/themedir1/default/template-part.php
r46586 r48370 1 1 Template Part 2 3 <?php echo json_encode( $args ); ?> -
trunk/tests/phpunit/tests/general/template.php
r48209 r48370 679 679 $this->assertFalse( get_template_part( 'non-existing-template' ) ); 680 680 } 681 682 /** 683 * @ticket 21676 684 */ 685 function test_get_template_part_passes_arguments_to_template() { 686 $this->expectOutputRegex( '/{"foo":"baz"}/' ); 687 688 get_template_part( 'template', 'part', array( 'foo' => 'baz' ) ); 689 } 681 690 }
Note: See TracChangeset
for help on using the changeset viewer.