WordPress.org

Make WordPress Core

Ticket #21676: 21676.9.patch

File 21676.9.patch, 9.2 KB (added by enrico.sorcinelli, 4 years ago)

I just updated the patch to the current trunk.

  • src/wp-includes/general-template.php

     
    1616 * "special".
    1717 *
    1818 * @since 1.5.0
     19 * @since 4.9.0 `$params` parameter added.
    1920 *
    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.
    2123 */
    22 function get_header( $name = null ) {
     24function get_header( $name = null, $params = array() ) {
    2325        /**
    2426         * Fires before the header template file is loaded.
    2527         *
    2628         * @since 2.1.0
    2729         * @since 2.8.0 $name parameter added.
     30         * @since 4.9.0 `$params` parameter added.
    2831         *
    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.
    3034         */
    31         do_action( 'get_header', $name );
     35        do_action( 'get_header', $name, $params );
    3236
    3337        $templates = array();
    3438        $name = (string) $name;
     
    3842
    3943        $templates[] = 'header.php';
    4044
    41         locate_template( $templates, true );
     45        locate_template( $templates, true, true, $params );
    4246}
    4347
    4448/**
     
    5155 * "special".
    5256 *
    5357 * @since 1.5.0
     58 * @since 4.9.0 `$params` parameter added.
    5459 *
    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.
    5662 */
    57 function get_footer( $name = null ) {
     63function get_footer( $name = null, $params = array() ) {
    5864        /**
    5965         * Fires before the footer template file is loaded.
    6066         *
    6167         * @since 2.1.0
    6268         * @since 2.8.0 $name parameter added.
     69         * @since 4.9.0 `$params` parameter added.
    6370         *
    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.
    6573         */
    66         do_action( 'get_footer', $name );
     74        do_action( 'get_footer', $name, $params );
    6775
    6876        $templates = array();
    6977        $name = (string) $name;
     
    7381
    7482        $templates[]    = 'footer.php';
    7583
    76         locate_template( $templates, true );
     84        locate_template( $templates, true, true, $params );
    7785}
    7886
    7987/**
     
    8694 * "special".
    8795 *
    8896 * @since 1.5.0
     97 * @since 4.9.0 `$params` parameter added.
    8998 *
    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.
    91101 */
    92 function get_sidebar( $name = null ) {
     102function get_sidebar( $name = null, $params = array() ) {
    93103        /**
    94104         * Fires before the sidebar template file is loaded.
    95105         *
    96106         * @since 2.2.0
    97107         * @since 2.8.0 $name parameter added.
     108         * @since 4.9.0 `$params` parameter added.
    98109         *
    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.
    100112         */
    101         do_action( 'get_sidebar', $name );
     113        do_action( 'get_sidebar', $name, $params );
    102114
    103115        $templates = array();
    104116        $name = (string) $name;
     
    107119
    108120        $templates[] = 'sidebar.php';
    109121
    110         locate_template( $templates, true );
     122        locate_template( $templates, true, true, $params );
    111123}
    112124
    113125/**
     
    127139 * "special".
    128140 *
    129141 * @since 3.0.0
     142 * @since 4.9.0 `$params` parameter added.
    130143 *
    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.
    133147 */
    134 function get_template_part( $slug, $name = null ) {
     148function get_template_part( $slug, $name = null, $params = array() ) {
    135149        /**
    136150         * Fires before the specified template part file is loaded.
    137151         *
     
    139153         * for the generic template part.
    140154         *
    141155         * @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.
    145161         */
    146         do_action( "get_template_part_{$slug}", $slug, $name );
     162        do_action( "get_template_part_{$slug}", $slug, $name, $params );
    147163
    148164        $templates = array();
    149165        $name = (string) $name;
     
    152168
    153169        $templates[] = "{$slug}.php";
    154170
    155         locate_template($templates, true, false);
     171        locate_template($templates, true, false, $params);
    156172}
    157173
    158174/**
     
    173189 * search. To give a few examples of what it can be used for.
    174190 *
    175191 * @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.
    178196 * @return string|void String when $echo is false.
    179197 */
    180 function get_search_form( $echo = true ) {
     198function get_search_form( $echo = true, $params = array() ) {
    181199        /**
    182200         * Fires before the search form is retrieved, at the start of get_search_form().
    183201         *
     
    185203         * @since 3.6.0
    186204         *
    187205         * @link https://core.trac.wordpress.org/ticket/19321
     206         *
     207         * @param array  $params Additional arguments passed to the template.
    188208         */
    189         do_action( 'pre_get_search_form' );
     209        do_action( 'pre_get_search_form', $params );
    190210
    191211        $format = current_theme_supports( 'html5', 'search-form' ) ? 'html5' : 'xhtml';
    192212
     
    231251         * @since 2.7.0
    232252         *
    233253         * @param string $form The search form HTML output.
     254         * @param array  $params Additional arguments passed to the template.
    234255         */
    235         $result = apply_filters( 'get_search_form', $form );
     256        $result = apply_filters( 'get_search_form', $form, $params );
    236257
    237258        if ( null === $result )
    238259                $result = $form;
  • src/wp-includes/template.php

     
    620620 * so that themes which inherit from a parent theme can just overload one file.
    621621 *
    622622 * @since 2.7.0
     623 * @since 4.9.0 `$params` parameter added.
    623624 *
    624625 * @param string|array $template_names Template file(s) to search for, in order.
    625626 * @param bool         $load           If true the template file will be loaded if it is found.
    626627 * @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.
    627629 * @return string The template filename if one is located.
    628630 */
    629 function locate_template($template_names, $load = false, $require_once = true ) {
     631function locate_template($template_names, $load = false, $require_once = true, $params = array() ) {
    630632        $located = '';
    631633        foreach ( (array) $template_names as $template_name ) {
    632634                if ( !$template_name )
     
    644646        }
    645647
    646648        if ( $load && '' != $located )
    647                 load_template( $located, $require_once );
     649                load_template( $located, $require_once, $params );
    648650
    649651        return $located;
    650652}
     
    657659 * also available.
    658660 *
    659661 * @since 1.5.0
     662 * @since 4.9.0 `$params` parameter added.
    660663 *
    661664 * @global array      $posts
    662665 * @global WP_Post    $post
     
    672675 *
    673676 * @param string $_template_file Path to template file.
    674677 * @param bool   $require_once   Whether to require_once or require. Default true.
     678 * @param array  $params         Additional arguments passed to the template.
    675679 */
    676 function load_template( $_template_file, $require_once = true ) {
     680function load_template( $_template_file, $require_once = true, $params = array() ) {
    677681        global $posts, $post, $wp_did_header, $wp_query, $wp_rewrite, $wpdb, $wp_version, $wp, $id, $comment, $user_ID;
    678682
    679683        if ( is_array( $wp_query->query_vars ) ) {
  • tests/phpunit/tests/general/template.php

     
    611611
    612612                $this->assertSame( $expected, $result );
    613613        }
     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        }
    614622}
  • tests/phpunit/data/themedir1/theme1/header.php

     
     1<?php
     2echo json_encode($params);