Make WordPress Core

Ticket #21676: 21676.11.patch

File 21676.11.patch, 11.0 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 82c138cef7..b0ffabe60e 100644
     
    1616 * "special".
    1717 *
    1818 * @since 1.5.0
     19 * @since 5.5.0 $wp_tmpl_args 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  $wp_tmpl_args Additional arguments passed to the header template.
    2123 */
    22 function get_header( $name = null ) {
     24function get_header( $name = null, $wp_tmpl_args = 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.5.0 $wp_tmpl_args 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       $wp_tmpl_args Additional arguments passed to the header template.
    3034         */
    31         do_action( 'get_header', $name );
     35        do_action( 'get_header', $name, $wp_tmpl_args );
    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, $wp_tmpl_args );
    4246}
    4347
    4448/**
    function get_header( $name = null ) { 
    5155 * "special".
    5256 *
    5357 * @since 1.5.0
     58 * @since 5.5.0 $wp_tmpl_args 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  $wp_tmpl_args Additional arguments passed to the footer template.
    5662 */
    57 function get_footer( $name = null ) {
     63function get_footer( $name = null, $wp_tmpl_args = 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.5.0 $wp_tmpl_args 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       $wp_tmpl_args Additional arguments passed to the footer template.
    6573         */
    66         do_action( 'get_footer', $name );
     74        do_action( 'get_footer', $name, $wp_tmpl_args );
    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, $wp_tmpl_args );
    7785}
    7886
    7987/**
    function get_footer( $name = null ) { 
    8694 * "special".
    8795 *
    8896 * @since 1.5.0
     97 * @since 5.5.0 $wp_tmpl_args 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  $wp_tmpl_args Additional arguments passed to the sidebar template.
    91101 */
    92 function get_sidebar( $name = null ) {
     102function get_sidebar( $name = null, $wp_tmpl_args = 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.5.0 $wp_tmpl_args 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       $wp_tmpl_args Additional arguments passed to the sidebar template.
    100112         */
    101         do_action( 'get_sidebar', $name );
     113        do_action( 'get_sidebar', $name, $wp_tmpl_args );
    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, $wp_tmpl_args );
    112124}
    113125
    114126/**
    function get_sidebar( $name = null ) { 
    128140 * "special".
    129141 *
    130142 * @since 3.0.0
     143 * @since 5.5.0 $wp_tmpl_args parameter 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  $wp_tmpl_args Additional arguments passed to the template.
    134148 */
    135 function get_template_part( $slug, $name = null ) {
     149function get_template_part( $slug, $name = null, $wp_tmpl_args = 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.5.0 $wp_tmpl_args parameter 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       $wp_tmpl_args 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, $wp_tmpl_args );
    148164
    149165        $templates = array();
    150166        $name      = (string) $name;
    function get_template_part( $slug, $name = null ) { 
    158174         * Fires before a template part is loaded.
    159175         *
    160176         * @since 5.2.0
     177         * @since 5.5.0 $wp_tmpl_args parameter added.
    161178         *
    162          * @param string   $slug      The slug name for the generic template.
    163          * @param string   $name      The name of the specialized template.
    164          * @param string[] $templates Array of template files to search for, in order.
     179         * @param string   $slug         The slug name for the generic template.
     180         * @param string   $name         The name of the specialized template.
     181         * @param string[] $templates    Array of template files to search for, in order.
     182         * @param array    $wp_tmpl_args Additional arguments passed to the template.
    165183         */
    166         do_action( 'get_template_part', $slug, $name, $templates );
     184        do_action( 'get_template_part', $slug, $name, $templates, $wp_tmpl_args );
    167185
    168         locate_template( $templates, true, false );
     186        locate_template( $templates, true, false, $wp_tmpl_args );
    169187}
    170188
    171189/**
    function get_search_form( $args = array() ) { 
    204222         *
    205223         * @since 2.7.0 as 'get_search_form' action.
    206224         * @since 3.6.0
     225         * @since 5.5.0 $args parameter added.
     226         *
     227         * @param array $args The array of arguments for building the search form.
    207228         *
    208229         * @link https://core.trac.wordpress.org/ticket/19321
    209230         */
    210         do_action( 'pre_get_search_form' );
     231        do_action( 'pre_get_search_form', $args );
    211232
    212233        $echo = true;
    213234
    function get_search_form( $args = array() ) { 
    246267         * Filters the HTML format of the search form.
    247268         *
    248269         * @since 3.6.0
     270         * @since 5.5.0 $args parameter added.
    249271         *
    250272         * @param string $format The type of markup to use in the search form.
    251273         *                       Accepts 'html5', 'xhtml'.
     274         * @param array  $args   The array of arguments for building the search form.
    252275         */
    253         $format = apply_filters( 'search_form_format', $format );
     276        $format = apply_filters( 'search_form_format', $format, $args );
    254277
    255278        $search_form_template = locate_template( 'searchform.php' );
    256279
    function get_search_form( $args = array() ) { 
    292315         * Filters the HTML output of the search form.
    293316         *
    294317         * @since 2.7.0
     318         * @since 5.5.0 $args parameter added.
    295319         *
    296320         * @param string $form The search form HTML output.
     321         * @param array $args The array of arguments for building the search form.
    297322         */
    298         $result = apply_filters( 'get_search_form', $form );
     323        $result = apply_filters( 'get_search_form', $form, $args );
    299324
    300325        if ( null === $result ) {
    301326                $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 170a86d9f9..82373bd9d5 100644
    class Tests_General_Template extends WP_UnitTestCase { 
    642642                self::assertSame( 'Template Part', trim( $output ) );
    643643                self::assertSame( null, $part );
    644644        }
     645
     646        /**
     647         * @ticket 21676
     648         */
     649        function test_load_template_with_params() {
     650                load_template( DIR_TESTDATA . '/themedir1/theme1/header.php', false, array( 'foo' => 'baz' ) );
     651                $this->expectOutputString( '{"foo":"baz"}' );
     652        }
    645653}