WordPress.org

Make WordPress Core

Ticket #21676: 21676.10.patch

File 21676.10.patch, 10.7 KB (added by enrico.sorcinelli, 4 years ago)
  • src/wp-includes/general-template.php

    diff --git a/src/wp-includes/general-template.php b/src/wp-includes/general-template.php
    index ca2dbc0..7a356c0 100644
    a b  
    1616 * "special".
    1717 *
    1818 * @since 1.5.0
     19 * @since 5.0.0 $params paramenter 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 5.0.0 $params paramenter 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;
    function get_header( $name = null ) { 
    3842
    3943        $templates[] = 'header.php';
    4044
    41         locate_template( $templates, true );
     45        locate_template( $templates, true, true, $params );
    4246}
    4347
    4448/**
    function get_header( $name = null ) { 
    5155 * "special".
    5256 *
    5357 * @since 1.5.0
     58 * @since 5.0.0 $params paramenter 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 5.0.0 $params paramenter 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 footer template.
    6573         */
    66         do_action( 'get_footer', $name );
     74        do_action( 'get_footer', $name, $params );
    6775
    6876        $templates = array();
    6977        $name      = (string) $name;
    function get_footer( $name = null ) { 
    7381
    7482        $templates[] = 'footer.php';
    7583
    76         locate_template( $templates, true );
     84        locate_template( $templates, true, true, $params );
    7785}
    7886
    7987/**
    function get_footer( $name = null ) { 
    8694 * "special".
    8795 *
    8896 * @since 1.5.0
     97 * @since 5.0.0 $params paramenter 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 5.0.0 $params paramenter 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;
    function get_sidebar( $name = null ) { 
    108120
    109121        $templates[] = 'sidebar.php';
    110122
    111         locate_template( $templates, true );
     123        locate_template( $templates, true, true, $params );
    112124}
    113125
    114126/**
    function get_sidebar( $name = null ) { 
    128140 * "special".
    129141 *
    130142 * @since 3.0.0
     143 * @since 5.0.0 $params paramenter added.
    131144 *
    132  * @param string $slug The slug name for the generic template.
    133  * @param string $name The name of the specialised template.
     145 * @param string $slug   The slug name for the generic template.
     146 * @param string $name   The name of the specialised template.
     147 * @param array  $params Additional arguments passed to the template.
    134148 */
    135 function get_template_part( $slug, $name = null ) {
     149function get_template_part( $slug, $name = null, $params = array() ) {
    136150        /**
    137151         * Fires before the specified template part file is loaded.
    138152         *
    function get_template_part( $slug, $name = null ) { 
    140154         * for the generic template part.
    141155         *
    142156         * @since 3.0.0
     157         * @since 5.0.0 $params paramenter added.
    143158         *
    144          * @param string      $slug The slug name for the generic template.
    145          * @param string|null $name The name of the specialized template.
     159         * @param string      $slug   The slug name for the generic template.
     160         * @param string|null $name   The name of the specialized template.
     161         * @param array       $params Additional arguments passed to the template.
    146162         */
    147         do_action( "get_template_part_{$slug}", $slug, $name );
     163        do_action( "get_template_part_{$slug}", $slug, $name, $params );
    148164
    149165        $templates = array();
    150166        $name      = (string) $name;
    function get_template_part( $slug, $name = null ) { 
    154170
    155171        $templates[] = "{$slug}.php";
    156172
    157         locate_template( $templates, true, false );
     173        locate_template( $templates, true, false, $params );
    158174}
    159175
    160176/**
    function get_template_part( $slug, $name = null ) { 
    175191 * search. To give a few examples of what it can be used for.
    176192 *
    177193 * @since 2.7.0
     194 * @since 5.0.0 $params paramenter added.
    178195 *
    179  * @param bool $echo Default to echo and not return the form.
     196 * @param bool   $echo   Default to echo and not return the form.
     197 * @param array  $params Additional arguments passed to the search form template.
    180198 * @return string|void String when $echo is false.
    181199 */
    182 function get_search_form( $echo = true ) {
     200function get_search_form( $echo = true, $params = array() ) {
    183201        /**
    184202         * Fires before the search form is retrieved, at the start of get_search_form().
    185203         *
    186204         * @since 2.7.0 as 'get_search_form' action.
    187205         * @since 3.6.0
     206         * @since 5.0.0 $params paramenter added.
     207         *
     208         * @param array $params Additional arguments passed to the search form template.
    188209         *
    189210         * @link https://core.trac.wordpress.org/ticket/19321
    190211         */
    191         do_action( 'pre_get_search_form' );
     212        do_action( 'pre_get_search_form', $params );
    192213
    193214        $format = current_theme_supports( 'html5', 'search-form' ) ? 'html5' : 'xhtml';
    194215
    function get_search_form( $echo = true ) { 
    196217         * Filters the HTML format of the search form.
    197218         *
    198219         * @since 3.6.0
     220         * @since 5.0.0 $params paramenter added.
    199221         *
    200222         * @param string $format The type of markup to use in the search form.
    201223         *                       Accepts 'html5', 'xhtml'.
     224         * @param array  $params Additional arguments passed to the search form template.
    202225         */
    203         $format = apply_filters( 'search_form_format', $format );
     226        $format = apply_filters( 'search_form_format', $format, $params );
    204227
    205228        $search_form_template = locate_template( 'searchform.php' );
    206229        if ( '' != $search_form_template ) {
    function get_search_form( $echo = true ) { 
    231254         * Filters the HTML output of the search form.
    232255         *
    233256         * @since 2.7.0
     257         * @since 5.0.0 $params paramenter added.
    234258         *
    235          * @param string $form The search form HTML output.
     259         * @param string $form   The search form HTML output.
     260         * @param array  $params Additional arguments passed to the search form template.
    236261         */
    237         $result = apply_filters( 'get_search_form', $form );
     262        $result = apply_filters( 'get_search_form', $form, $params );
    238263
    239264        if ( null === $result ) {
    240265                $result = $form;
  • src/wp-includes/template.php

    diff --git a/src/wp-includes/template.php b/src/wp-includes/template.php
    index b0b49fe..86f647f 100644
    a b function get_attachment_template() { 
    625625 * so that themes which inherit from a parent theme can just overload one file.
    626626 *
    627627 * @since 2.7.0
     628 * @since 5.0.0 $params paramenter added.
    628629 *
    629630 * @param string|array $template_names Template file(s) to search for, in order.
    630631 * @param bool         $load           If true the template file will be loaded if it is found.
    631632 * @param bool         $require_once   Whether to require_once or require. Default true. Has no effect if $load is false.
     633 * @param array        $params         Additional arguments passed to the template.
    632634 * @return string The template filename if one is located.
    633635 */
    634 function locate_template( $template_names, $load = false, $require_once = true ) {
     636function locate_template( $template_names, $load = false, $require_once = true, $params = array() ) {
    635637        $located = '';
    636638        foreach ( (array) $template_names as $template_name ) {
    637639                if ( ! $template_name ) {
    function locate_template( $template_names, $load = false, $require_once = true ) 
    650652        }
    651653
    652654        if ( $load && '' != $located ) {
    653                 load_template( $located, $require_once );
     655                load_template( $located, $require_once, $params );
    654656        }
    655657
    656658        return $located;
    function locate_template( $template_names, $load = false, $require_once = true ) 
    664666 * also available.
    665667 *
    666668 * @since 1.5.0
     669 * @since 5.0.0 $params paramenter added.
    667670 *
    668671 * @global array      $posts
    669672 * @global WP_Post    $post
    function locate_template( $template_names, $load = false, $require_once = true ) 
    679682 *
    680683 * @param string $_template_file Path to template file.
    681684 * @param bool   $require_once   Whether to require_once or require. Default true.
     685 * @param array  $params         Additional arguments passed to the template.
    682686 */
    683 function load_template( $_template_file, $require_once = true ) {
     687function load_template( $_template_file, $require_once = true, $params = array() ) {
    684688        global $posts, $post, $wp_did_header, $wp_query, $wp_rewrite, $wpdb, $wp_version, $wp, $id, $comment, $user_ID;
    685689
    686690        if ( is_array( $wp_query->query_vars ) ) {
  • new file tests/phpunit/data/themedir1/theme1/header.php

    diff --git a/tests/phpunit/data/themedir1/theme1/header.php b/tests/phpunit/data/themedir1/theme1/header.php
    new file mode 100644
    index 0000000..cba948b
    - +  
     1<?php
     2echo json_encode($params);
  • tests/phpunit/tests/general/template.php

    diff --git a/tests/phpunit/tests/general/template.php b/tests/phpunit/tests/general/template.php
    index 05ef977..b07caf3 100644
    a b class Tests_General_Template extends WP_UnitTestCase { 
    612612
    613613                $this->assertSame( $expected, $result );
    614614        }
     615
     616        /**
     617         * @ticket 21676
     618         */
     619        function test_load_template_with_params () {
     620                load_template( DIR_TESTDATA . '/themedir1/theme1/header.php', false, array( 'foo' => 'baz' ) );
     621                $this->expectOutputString( '{"foo":"baz"}' );
     622        }
    615623}