Make WordPress Core

Ticket #21676: 21676.12.patch

File 21676.12.patch, 11.6 KB (added by enrico.sorcinelli, 5 years ago)
  • src/wp-includes/general-template.php

    diff --git src/wp-includes/general-template.php src/wp-includes/general-template.php
    index d2eccbb617..009c5c9f99 100644
     
    1717 *
    1818 * @since 1.5.0
    1919 * @since 5.5.0 A return value was added.
     20 * @since 5.5.0 $wp_tmpl_args parameter added.
    2021 *
    21  * @param string $name The name of the specialised header.
     22 * @param string $name         The name of the specialised header.
     23 * @param array  $wp_tmpl_args Additional arguments passed to the header template.
    2224 * @return void|false Void on success, false if the template does not exist.
    2325 */
    24 function get_header( $name = null ) {
     26function get_header( $name = null, $wp_tmpl_args = array() ) {
    2527        /**
    2628         * Fires before the header template file is loaded.
    2729         *
    2830         * @since 2.1.0
    2931         * @since 2.8.0 $name parameter added.
     32         * @since 5.5.0 $wp_tmpl_args parameter added.
    3033         *
    31          * @param string|null $name Name of the specific header file to use. null for the default header.
     34         * @param string|null $name         Name of the specific header file to use. null for the default header.
     35         * @param array       $wp_tmpl_args Additional arguments passed to the header template.
    3236         */
    33         do_action( 'get_header', $name );
     37        do_action( 'get_header', $name, $wp_tmpl_args );
    3438
    3539        $templates = array();
    3640        $name      = (string) $name;
    function get_header( $name = null ) { 
    4044
    4145        $templates[] = 'header.php';
    4246
    43         if ( ! locate_template( $templates, true ) ) {
     47        if ( ! locate_template( $templates, true, true, $wp_tmpl_args ) ) {
    4448                return false;
    4549        }
    4650}
    function get_header( $name = null ) { 
    5660 *
    5761 * @since 1.5.0
    5862 * @since 5.5.0 A return value was added.
     63 * @since 5.5.0 $wp_tmpl_args parameter added.
    5964 *
    60  * @param string $name The name of the specialised footer.
     65 * @param string $name         The name of the specialised footer.
     66 * @param array  $wp_tmpl_args Additional arguments passed to the footer template.
    6167 * @return void|false Void on success, false if the template does not exist.
    6268 */
    63 function get_footer( $name = null ) {
     69function get_footer( $name = null, $wp_tmpl_args = array() ) {
    6470        /**
    6571         * Fires before the footer template file is loaded.
    6672         *
    6773         * @since 2.1.0
    6874         * @since 2.8.0 $name parameter added.
     75         * @since 5.5.0 $wp_tmpl_args parameter added.
    6976         *
    70          * @param string|null $name Name of the specific footer file to use. null for the default footer.
     77         * @param string|null $name         Name of the specific footer file to use. null for the default footer.
     78         * @param array       $wp_tmpl_args Additional arguments passed to the footer template.
    7179         */
    72         do_action( 'get_footer', $name );
     80        do_action( 'get_footer', $name, $wp_tmpl_args );
    7381
    7482        $templates = array();
    7583        $name      = (string) $name;
    function get_footer( $name = null ) { 
    7987
    8088        $templates[] = 'footer.php';
    8189
    82         if ( ! locate_template( $templates, true ) ) {
     90        if ( ! locate_template( $templates, true, true, $wp_tmpl_args ) ) {
    8391                return false;
    8492        }
    8593}
    function get_footer( $name = null ) { 
    95103 *
    96104 * @since 1.5.0
    97105 * @since 5.5.0 A return value was added.
     106 * @since 5.5.0 $wp_tmpl_args parameter added.
    98107 *
    99  * @param string $name The name of the specialised sidebar.
     108 * @param string $name         The name of the specialised sidebar.
     109 * @param array  $wp_tmpl_args Additional arguments passed to the sidebar template.
    100110 * @return void|false Void on success, false if the template does not exist.
    101111 */
    102 function get_sidebar( $name = null ) {
     112function get_sidebar( $name = null, $wp_tmpl_args = array() ) {
    103113        /**
    104114         * Fires before the sidebar template file is loaded.
    105115         *
    106116         * @since 2.2.0
    107117         * @since 2.8.0 $name parameter added.
     118         * @since 5.5.0 $wp_tmpl_args parameter added.
    108119         *
    109          * @param string|null $name Name of the specific sidebar file to use. null for the default sidebar.
     120         * @param string|null $name         Name of the specific sidebar file to use. null for the default sidebar.
     121         * @param array       $wp_tmpl_args Additional arguments passed to the sidebar template.
    110122         */
    111         do_action( 'get_sidebar', $name );
     123        do_action( 'get_sidebar', $name, $wp_tmpl_args );
    112124
    113125        $templates = array();
    114126        $name      = (string) $name;
    function get_sidebar( $name = null ) { 
    118130
    119131        $templates[] = 'sidebar.php';
    120132
    121         if ( ! locate_template( $templates, true ) ) {
     133        if ( ! locate_template( $templates, true, true, $wp_tmpl_args ) ) {
    122134                return false;
    123135        }
    124136}
    function get_sidebar( $name = null ) { 
    141153 *
    142154 * @since 3.0.0
    143155 * @since 5.5.0 A return value was added.
     156 * @since 5.5.0 $wp_tmpl_args parameter added.
    144157 *
    145  * @param string $slug The slug name for the generic template.
    146  * @param string $name The name of the specialised template.
     158 * @param string $slug         The slug name for the generic template.
     159 * @param string $name         The name of the specialised template.
     160 * @param array  $wp_tmpl_args Additional arguments passed to the template.
    147161 * @return void|false Void on success, false if the template does not exist.
    148162 */
    149 function get_template_part( $slug, $name = null ) {
     163function get_template_part( $slug, $name = null, $wp_tmpl_args = array() ) {
    150164        /**
    151165         * Fires before the specified template part file is loaded.
    152166         *
    function get_template_part( $slug, $name = null ) { 
    154168         * for the generic template part.
    155169         *
    156170         * @since 3.0.0
     171         * @since 5.5.0 $wp_tmpl_args parameter added.
    157172         *
    158          * @param string      $slug The slug name for the generic template.
    159          * @param string|null $name The name of the specialized template.
     173         * @param string      $slug         The slug name for the generic template.
     174         * @param string|null $name         The name of the specialized template.
     175         * @param array       $wp_tmpl_args Additional arguments passed to the template.
    160176         */
    161         do_action( "get_template_part_{$slug}", $slug, $name );
     177        do_action( "get_template_part_{$slug}", $slug, $name, $wp_tmpl_args );
    162178
    163179        $templates = array();
    164180        $name      = (string) $name;
    function get_template_part( $slug, $name = null ) { 
    172188         * Fires before a template part is loaded.
    173189         *
    174190         * @since 5.2.0
     191         * @since 5.5.0 $wp_tmpl_args parameter added.
    175192         *
    176          * @param string   $slug      The slug name for the generic template.
    177          * @param string   $name      The name of the specialized template.
    178          * @param string[] $templates Array of template files to search for, in order.
     193         * @param string   $slug         The slug name for the generic template.
     194         * @param string   $name         The name of the specialized template.
     195         * @param string[] $templates    Array of template files to search for, in order.
     196         * @param array    $wp_tmpl_args Additional arguments passed to the template.
    179197         */
    180         do_action( 'get_template_part', $slug, $name, $templates );
     198        do_action( 'get_template_part', $slug, $name, $templates, $wp_tmpl_args );
    181199
    182         if ( ! locate_template( $templates, true, false ) ) {
     200        if ( ! locate_template( $templates, true, false, $wp_tmpl_args ) ) {
    183201                return false;
    184202        }
    185203}
    function get_search_form( $args = array() ) { 
    220238         *
    221239         * @since 2.7.0 as 'get_search_form' action.
    222240         * @since 3.6.0
     241         * @since 5.5.0 $args parameter added.
     242         *
     243         * @param array $args The array of arguments for building the search form.
    223244         *
    224245         * @link https://core.trac.wordpress.org/ticket/19321
    225246         */
    226         do_action( 'pre_get_search_form' );
     247        do_action( 'pre_get_search_form', $args );
    227248
    228249        $echo = true;
    229250
    function get_search_form( $args = array() ) { 
    262283         * Filters the HTML format of the search form.
    263284         *
    264285         * @since 3.6.0
     286         * @since 5.5.0 $args parameter added.
    265287         *
    266288         * @param string $format The type of markup to use in the search form.
    267289         *                       Accepts 'html5', 'xhtml'.
     290         * @param array  $args   The array of arguments for building the search form.
    268291         */
    269         $format = apply_filters( 'search_form_format', $format );
     292        $format = apply_filters( 'search_form_format', $format, $args );
    270293
    271294        $search_form_template = locate_template( 'searchform.php' );
    272295
    function get_search_form( $args = array() ) { 
    308331         * Filters the HTML output of the search form.
    309332         *
    310333         * @since 2.7.0
     334         * @since 5.5.0 $args parameter added.
    311335         *
    312336         * @param string $form The search form HTML output.
     337         * @param array $args The array of arguments for building the search form.
    313338         */
    314         $result = apply_filters( 'get_search_form', $form );
     339        $result = apply_filters( 'get_search_form', $form, $args );
    315340
    316341        if ( null === $result ) {
    317342                $result = $form;
  • src/wp-includes/template.php

    diff --git src/wp-includes/template.php src/wp-includes/template.php
    index 51a4c86358..04a5027862 100644
    function get_attachment_template() { 
    644644 * so that themes which inherit from a parent theme can just overload one file.
    645645 *
    646646 * @since 2.7.0
     647 * @since 5.5.0 $wp_tmpl_args parameter added.
    647648 *
    648649 * @param string|array $template_names Template file(s) to search for, in order.
    649650 * @param bool         $load           If true the template file will be loaded if it is found.
    650651 * @param bool         $require_once   Whether to require_once or require. Default true. Has no effect if $load is false.
     652 * @param array        $wp_tmpl_args   Additional arguments passed to the template.
    651653 * @return string The template filename if one is located.
    652654 */
    653 function locate_template( $template_names, $load = false, $require_once = true ) {
     655function locate_template( $template_names, $load = false, $require_once = true, $wp_tmpl_args = array() ) {
    654656        $located = '';
    655657        foreach ( (array) $template_names as $template_name ) {
    656658                if ( ! $template_name ) {
    function locate_template( $template_names, $load = false, $require_once = true ) 
    669671        }
    670672
    671673        if ( $load && '' !== $located ) {
    672                 load_template( $located, $require_once );
     674                load_template( $located, $require_once, $wp_tmpl_args );
    673675        }
    674676
    675677        return $located;
    function locate_template( $template_names, $load = false, $require_once = true ) 
    683685 * also available.
    684686 *
    685687 * @since 1.5.0
     688 * @since 5.5.0 $wp_tmpl_args parameter added.
    686689 *
    687690 * @global array      $posts
    688691 * @global WP_Post    $post          Global post object.
    function locate_template( $template_names, $load = false, $require_once = true ) 
    698701 *
    699702 * @param string $_template_file Path to template file.
    700703 * @param bool   $require_once   Whether to require_once or require. Default true.
     704 * @param array  $wp_tmpl_args   Additional arguments passed to the template.
    701705 */
    702 function load_template( $_template_file, $require_once = true ) {
     706function load_template( $_template_file, $require_once = true, $wp_tmpl_args = array() ) {
    703707        global $posts, $post, $wp_did_header, $wp_query, $wp_rewrite, $wpdb, $wp_version, $wp, $id, $comment, $user_ID;
    704708
    705709        if ( is_array( $wp_query->query_vars ) ) {
  • new file tests/phpunit/data/themedir1/theme1/header.php

    diff --git tests/phpunit/data/themedir1/theme1/header.php tests/phpunit/data/themedir1/theme1/header.php
    new file mode 100644
    index 0000000000..9da09ebcb3
    - +  
     1<?php
     2echo json_encode( $wp_tmpl_args );
  • tests/phpunit/tests/general/template.php

    diff --git tests/phpunit/tests/general/template.php tests/phpunit/tests/general/template.php
    index e387a49944..0871cbd290 100644
    class Tests_General_Template extends WP_UnitTestCase { 
    678678        function test_get_template_part_returns_false_on_failure() {
    679679                $this->assertFalse( get_template_part( 'non-existing-template' ) );
    680680        }
     681
     682        /**
     683         * @ticket 21676
     684         */
     685        function test_load_template_with_params() {
     686                load_template( DIR_TESTDATA . '/themedir1/theme1/header.php', false, array( 'foo' => 'baz' ) );
     687                $this->expectOutputString( '{"foo":"baz"}' );
     688        }
    681689}