Ticket #21676: 21676.13.diff
File 21676.13.diff, 11.1 KB (added by , 4 years ago) |
---|
-
src/wp-includes/general-template.php
17 17 * 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. 32 * @since 2.8.0 The `$name` parameter was added. 33 * @since 5.5.0 The `$args` parameter was added. 30 34 * 31 * @param string|null $name Name of the specific header file to use. null for the default header. 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. 32 37 */ 33 do_action( 'get_header', $name );38 do_action( 'get_header', $name, $args ); 34 39 35 40 $templates = array(); 36 41 $name = (string) $name; … … 40 45 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 } 46 51 } … … 56 61 * 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. 76 * @since 2.8.0 The `$name` parameter was added. 77 * @since 5.5.0 The `$args` parameter was added. 69 78 * 70 * @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 $args Additional arguments passed to the footer template. 71 81 */ 72 do_action( 'get_footer', $name );82 do_action( 'get_footer', $name, $args ); 73 83 74 84 $templates = array(); 75 85 $name = (string) $name; … … 79 89 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 } 85 95 } … … 95 105 * 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. 120 * @since 2.8.0 The `$name` parameter was added. 121 * @since 5.5.0 The `$args` parameter was added. 108 122 * 109 * @param string|null $name Name of the specific sidebar file to use. null for the default sidebar. 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. 110 125 */ 111 do_action( 'get_sidebar', $name );126 do_action( 'get_sidebar', $name, $args ); 112 127 113 128 $templates = array(); 114 129 $name = (string) $name; … … 118 133 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 } 124 139 } … … 141 156 * 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. 152 170 * … … 154 172 * for the generic template part. 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. 179 * @param array $args Additional arguments passed to the template. 160 180 */ 161 do_action( "get_template_part_{$slug}", $slug, $name );181 do_action( "get_template_part_{$slug}", $slug, $name, $args ); 162 182 163 183 $templates = array(); 164 184 $name = (string) $name; … … 172 192 * Fires before a template part is loaded. 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. 200 * @param array $args Additional arguments passed to the template. 179 201 */ 180 do_action( 'get_template_part', $slug, $name, $templates );202 do_action( 'get_template_part', $slug, $name, $templates, $args ); 181 203 182 if ( ! locate_template( $templates, true, false ) ) {204 if ( ! locate_template( $templates, true, false, $args ) ) { 183 205 return false; 184 206 } 185 207 } … … 202 224 * search. To give a few examples of what it can be used for. 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 { 208 230 * Optional. Array of display arguments. … … 220 242 * 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 248 * 249 * @param array $args The array of arguments for building the search form. 225 250 */ 226 do_action( 'pre_get_search_form' );251 do_action( 'pre_get_search_form', $args ); 227 252 228 253 $echo = true; 229 254 … … 262 287 * Filters the HTML format of the search form. 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'. 294 * @param array $args The array of arguments for building the search form. 268 295 */ 269 $format = apply_filters( 'search_form_format', $format );296 $format = apply_filters( 'search_form_format', $format, $args ); 270 297 271 298 $search_form_template = locate_template( 'searchform.php' ); 272 299 … … 308 335 * Filters the HTML output of the search form. 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. 341 * @param array $args The array of arguments for building the search form. 313 342 */ 314 $result = apply_filters( 'get_search_form', $form );343 $result = apply_filters( 'get_search_form', $form, $args ); 315 344 316 345 if ( null === $result ) { 317 346 $result = $form; -
src/wp-includes/template.php
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 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 ) { 656 660 if ( ! $template_name ) { … … 669 673 } 670 674 671 675 if ( $load && '' !== $located ) { 672 load_template( $located, $require_once );676 load_template( $located, $require_once, $args ); 673 677 } 674 678 675 679 return $located; … … 683 687 * also available. 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 688 693 * @global WP_Post $post Global post object. … … 698 703 * 699 704 * @param string $_template_file Path to template file. 700 705 * @param bool $require_once Whether to require_once or require. Default true. 706 * @param array $args Optional. Additional arguments passed to the template. 707 * Default empty array. 701 708 */ 702 function load_template( $_template_file, $require_once = true ) {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 705 712 if ( is_array( $wp_query->query_vars ) ) { -
tests/phpunit/data/themedir1/default/template-part.php
1 1 Template Part 2 3 <?php echo json_encode( $args ); ?> -
tests/phpunit/tests/general/template.php
678 678 function test_get_template_part_returns_false_on_failure() { 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 }