Make WordPress Core

Ticket #36187: 36187.patch

File 36187.patch, 7.2 KB (added by enrico.sorcinelli, 10 years ago)
  • src/wp-includes/general-template.php

     
    1616 * "special".
    1717 *
    1818 * @since 1.5.0
     19 * @since 4.5.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.5.0 $params parameter added
    3235         *
    33          * @param string $name Name of the specific header file to use.
     36         * @param string $name    Name of the specific header file to use.
     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, $params );
    4650}
    4751
    4852/**
     
    5559 * "special".
    5660 *
    5761 * @since 1.5.0
     62 * @since 4.5.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.5.0 $params parameter added
    7178         *
    72          * @param string $name Name of the specific footer file to use.
     79         * @param string $name    Name of the specific footer file to use.
     80         * @param array  $params  Additional arguments passed to the footer 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, $params );
    8593}
    8694
    8795/**
     
    94102 * "special".
    95103 *
    96104 * @since 1.5.0
     105 * @since 4.5.0 $params parameter added
    97106 *
    98107 * @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.5.0 $params parameter added
    110121         *
    111122         * @param string $name Name of the specific sidebar file to use.
     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, $params );
    123135}
    124136
    125137/**
     
    140152 *
    141153 * @since 3.0.0
    142154 *
    143  * @param string $slug The slug name for the generic template.
    144  * @param string $name The name of the specialised template.
     155 * @param string $slug   The slug name for the generic template.
     156 * @param string $name   The name of the specialised template.
     157 * @param array  $params Additional arguments passed to the template.
    145158 */
    146 function get_template_part( $slug, $name = null ) {
     159function get_template_part( $slug, $name = null, $params = array() ) {
    147160        /**
    148161         * Fires before the specified template part file is loaded.
    149162         *
     
    151164         * for the generic template part.
    152165         *
    153166         * @since 3.0.0
    154          *
    155          * @param string $slug The slug name for the generic template.
    156          * @param string $name The name of the specialized template.
     167         * @since 4.5.0 $params parameter added
     168         *
     169         * @param string $slug   The slug name for the generic template.
     170         * @param string $name   The name of the specialized template.
     171         * @param array  $params Additional arguments passed to the template.
    157172         */
    158         do_action( "get_template_part_{$slug}", $slug, $name );
     173        do_action( "get_template_part_{$slug}", $slug, $name, $params );
    159174
    160175        $templates = array();
    161176        $name = (string) $name;
     
    164179
    165180        $templates[] = "{$slug}.php";
    166181
    167         locate_template($templates, true, false);
     182        locate_template($templates, true, false, $params);
    168183}
    169184
    170185/**
  • src/wp-includes/template.php

     
    507507 * @param string|array $template_names Template file(s) to search for, in order.
    508508 * @param bool         $load           If true the template file will be loaded if it is found.
    509509 * @param bool         $require_once   Whether to require_once or require. Default true. Has no effect if $load is false.
     510 * @param array        $params         Additional arguments passed to the template.
    510511 * @return string The template filename if one is located.
    511512 */
    512 function locate_template($template_names, $load = false, $require_once = true ) {
     513function locate_template($template_names, $load = false, $require_once = true, $params = array() ) {
    513514        $located = '';
    514515        foreach ( (array) $template_names as $template_name ) {
    515516                if ( !$template_name )
     
    527528        }
    528529
    529530        if ( $load && '' != $located )
    530                 load_template( $located, $require_once );
     531                load_template( $located, $require_once, $params );
    531532
    532533        return $located;
    533534}
     
    555556 *
    556557 * @param string $_template_file Path to template file.
    557558 * @param bool   $require_once   Whether to require_once or require. Default true.
     559 * @param array  $params         Additional arguments passed to the template.
    558560 */
    559 function load_template( $_template_file, $require_once = true ) {
     561function load_template( $_template_file, $require_once = true, $params = array() ) {
    560562        global $posts, $post, $wp_did_header, $wp_query, $wp_rewrite, $wpdb, $wp_version, $wp, $id, $comment, $user_ID;
    561563
    562564        if ( is_array( $wp_query->query_vars ) ) {
  • tests/phpunit/tests/general/template.php

     
    138138        }
    139139
    140140        /**
     141         * @ticket
     142         */
     143        function test_load_template_with_params () {
     144                load_template( DIR_TESTDATA . '/themedir1/theme1/header.php', false, array( 'foo' => 'baz' ) );
     145                $this->expectOutputString( '{"foo":"baz"}' );
     146        }
     147
     148        /**
    141149         * Builds and retrieves a custom site icon meta tag.
    142150         *
    143151         * @since 4.3.0
  • tests/phpunit/data/themedir1/theme1/header.php

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