Ticket #36187: 36187.patch
| File 36187.patch, 7.2 KB (added by , 10 years ago) |
|---|
-
src/wp-includes/general-template.php
16 16 * "special". 17 17 * 18 18 * @since 1.5.0 19 * @since 4.5.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.5.0 $params parameter added 32 35 * 33 * @param string $name Name of the specific header file to use. 36 * @param string $name Name of the specific header file to use. 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, $params ); 46 50 } 47 51 48 52 /** … … 55 59 * "special". 56 60 * 57 61 * @since 1.5.0 62 * @since 4.5.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.5.0 $params parameter added 71 78 * 72 * @param string $name Name of the specific footer file to use. 79 * @param string $name Name of the specific footer file to use. 80 * @param array $params Additional arguments passed to the footer 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, $params ); 85 93 } 86 94 87 95 /** … … 94 102 * "special". 95 103 * 96 104 * @since 1.5.0 105 * @since 4.5.0 $params parameter added 97 106 * 98 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.5.0 $params parameter added 110 121 * 111 122 * @param string $name Name of the specific sidebar file to use. 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, $params ); 123 135 } 124 136 125 137 /** … … 140 152 * 141 153 * @since 3.0.0 142 154 * 143 * @param string $slug The slug name for the generic template. 144 * @param string $name The name of the specialised template. 155 * @param string $slug The slug name for the generic template. 156 * @param string $name The name of the specialised template. 157 * @param array $params Additional arguments passed to the template. 145 158 */ 146 function get_template_part( $slug, $name = null ) {159 function get_template_part( $slug, $name = null, $params = array() ) { 147 160 /** 148 161 * Fires before the specified template part file is loaded. 149 162 * … … 151 164 * for the generic template part. 152 165 * 153 166 * @since 3.0.0 154 * 155 * @param string $slug The slug name for the generic template. 156 * @param string $name The name of the specialized template. 167 * @since 4.5.0 $params parameter added 168 * 169 * @param string $slug The slug name for the generic template. 170 * @param string $name The name of the specialized template. 171 * @param array $params Additional arguments passed to the template. 157 172 */ 158 do_action( "get_template_part_{$slug}", $slug, $name );173 do_action( "get_template_part_{$slug}", $slug, $name, $params ); 159 174 160 175 $templates = array(); 161 176 $name = (string) $name; … … 164 179 165 180 $templates[] = "{$slug}.php"; 166 181 167 locate_template($templates, true, false );182 locate_template($templates, true, false, $params); 168 183 } 169 184 170 185 /** -
src/wp-includes/template.php
507 507 * @param string|array $template_names Template file(s) to search for, in order. 508 508 * @param bool $load If true the template file will be loaded if it is found. 509 509 * @param bool $require_once Whether to require_once or require. Default true. Has no effect if $load is false. 510 * @param array $params Additional arguments passed to the template. 510 511 * @return string The template filename if one is located. 511 512 */ 512 function locate_template($template_names, $load = false, $require_once = true ) {513 function locate_template($template_names, $load = false, $require_once = true, $params = array() ) { 513 514 $located = ''; 514 515 foreach ( (array) $template_names as $template_name ) { 515 516 if ( !$template_name ) … … 527 528 } 528 529 529 530 if ( $load && '' != $located ) 530 load_template( $located, $require_once );531 load_template( $located, $require_once, $params ); 531 532 532 533 return $located; 533 534 } … … 555 556 * 556 557 * @param string $_template_file Path to template file. 557 558 * @param bool $require_once Whether to require_once or require. Default true. 559 * @param array $params Additional arguments passed to the template. 558 560 */ 559 function load_template( $_template_file, $require_once = true ) {561 function load_template( $_template_file, $require_once = true, $params = array() ) { 560 562 global $posts, $post, $wp_did_header, $wp_query, $wp_rewrite, $wpdb, $wp_version, $wp, $id, $comment, $user_ID; 561 563 562 564 if ( is_array( $wp_query->query_vars ) ) { -
tests/phpunit/tests/general/template.php
138 138 } 139 139 140 140 /** 141 * @ticket 142 */ 143 function test_load_template_with_params () { 144 load_template( DIR_TESTDATA . '/themedir1/theme1/header.php', false, array( 'foo' => 'baz' ) ); 145 $this->expectOutputString( '{"foo":"baz"}' ); 146 } 147 148 /** 141 149 * Builds and retrieves a custom site icon meta tag. 142 150 * 143 151 * @since 4.3.0 -
tests/phpunit/data/themedir1/theme1/header.php
1 <?php 2 echo json_encode($params);