Make WordPress Core

Ticket #21676: 21676.7.patch

File 21676.7.patch, 9.3 KB (added by enrico.sorcinelli, 8 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         *
     
    2931         *
    3032         * @since 2.1.0
    3133         * @since 2.8.0 $name parameter added.
     34         * @since 4.9.0 `$params` parameter added.
    3235         *
    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.
    3438         */
    35         do_action( 'get_header', $name );
     39        do_action( 'get_header', $name, $params );
    3640
    3741        $templates = array();
    3842        $name = (string) $name;
     
    4246
    4347        $templates[] = 'header.php';
    4448
    45         locate_template( $templates, true );
     49        locate_template( $templates, true, true, $params );
    4650}
    4751
    4852/**
     
    5559 * "special".
    5660 *
    5761 * @since 1.5.0
     62 * @since 4.9.0 `$params` parameter added.
    5863 *
    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.
    6066 */
    61 function get_footer( $name = null ) {
     67function get_footer( $name = null, $params = array() ) {
    6268        /**
    6369         * Fires before the footer template file is loaded.
    6470         *
     
    6874         *
    6975         * @since 2.1.0
    7076         * @since 2.8.0 $name parameter added.
     77         * @since 4.9.0 `$params` parameter added.
    7178         *
    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.
    7381         */
    74         do_action( 'get_footer', $name );
     82        do_action( 'get_footer', $name, $params );
    7583
    7684        $templates = array();
    7785        $name = (string) $name;
     
    8189
    8290        $templates[]    = 'footer.php';
    8391
    84         locate_template( $templates, true );
     92        locate_template( $templates, true, true, $params );
    8593}
    8694
    8795/**
     
    94102 * "special".
    95103 *
    96104 * @since 1.5.0
     105 * @since 4.9.0 `$params` parameter added.
    97106 *
    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.
    99109 */
    100 function get_sidebar( $name = null ) {
     110function get_sidebar( $name = null, $params = array() ) {
    101111        /**
    102112         * Fires before the sidebar template file is loaded.
    103113         *
     
    107117         *
    108118         * @since 2.2.0
    109119         * @since 2.8.0 $name parameter added.
     120         * @since 4.9.0 `$params` parameter added.
    110121         *
    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.
    112124         */
    113         do_action( 'get_sidebar', $name );
     125        do_action( 'get_sidebar', $name, $params );
    114126
    115127        $templates = array();
    116128        $name = (string) $name;
     
    119131
    120132        $templates[] = 'sidebar.php';
    121133
    122         locate_template( $templates, true );
     134        locate_template( $templates, true, true, $params );
    123135}
    124136
    125137/**
     
    139151 * "special".
    140152 *
    141153 * @since 3.0.0
     154 * @since 4.9.0 `$params` parameter added.
    142155 *
    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.
    145159 */
    146 function get_template_part( $slug, $name = null ) {
     160function get_template_part( $slug, $name = null, $params = array() ) {
    147161        /**
    148162         * Fires before the specified template part file is loaded.
    149163         *
     
    151165         * for the generic template part.
    152166         *
    153167         * @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.9.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.
    157173         */
    158         do_action( "get_template_part_{$slug}", $slug, $name );
     174        do_action( "get_template_part_{$slug}", $slug, $name, $params );
    159175
    160176        $templates = array();
    161177        $name = (string) $name;
     
    164180
    165181        $templates[] = "{$slug}.php";
    166182
    167         locate_template($templates, true, false);
     183        locate_template($templates, true, false, $params);
    168184}
    169185
    170186/**
     
    185201 * search. To give a few examples of what it can be used for.
    186202 *
    187203 * @since 2.7.0
    188  *
    189  * @param bool $echo Default to echo and not return the form.
     204 * @since 4.9.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.
    190208 * @return string|void String when $echo is false.
    191209 */
    192 function get_search_form( $echo = true ) {
     210function get_search_form( $echo = true, $params = array() ) {
    193211        /**
    194212         * Fires before the search form is retrieved, at the start of get_search_form().
    195213         *
     
    197215         * @since 3.6.0
    198216         *
    199217         * @link https://core.trac.wordpress.org/ticket/19321
     218         *
     219         * @param array  $params Additional arguments passed to the template.
    200220         */
    201         do_action( 'pre_get_search_form' );
     221        do_action( 'pre_get_search_form', $params );
    202222
    203223        $format = current_theme_supports( 'html5', 'search-form' ) ? 'html5' : 'xhtml';
    204224
     
    243263         * @since 2.7.0
    244264         *
    245265         * @param string $form The search form HTML output.
     266         * @param array  $params Additional arguments passed to the template.
    246267         */
    247         $result = apply_filters( 'get_search_form', $form );
     268        $result = apply_filters( 'get_search_form', $form, $params );
    248269
    249270        if ( null === $result )
    250271                $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);