WordPress.org

Make WordPress Core

Ticket #13691: get_template_part.3.diff

File get_template_part.3.diff, 3.5 KB (added by wjm, 8 years ago)

implements get_template_part() in get_header(), get_footer() and get_sidebar()

  • general-template.php

     
    1919 * @since 1.5.0
    2020 * @uses do_action() Calls 'get_header' action.
    2121 *
    22  * @param string $name The name of the specialised header.
     22 * @param mixed $names The names of the specialised header templates (it can be a string, or an array of names to search for in priority order.).
    2323 */
    24 function get_header( $name = null ) {
    25         do_action( 'get_header', $name );
     24function get_header( $names = array() ) {
     25        do_action( 'get_header', $names );
    2626
    27         $templates = array();
    28         if ( isset($name) )
    29                 $templates[] = "header-{$name}.php";
    30 
    31         $templates[] = "header.php";
    32 
    3327        // Backward compat code will be removed in a future release
    34         if ('' == locate_template($templates, true))
     28        if ('' == get_template_part( 'header', $names ) )
    3529                load_template( WPINC . '/theme-compat/header.php');
    3630}
    3731
     
    4842 * @since 1.5.0
    4943 * @uses do_action() Calls 'get_footer' action.
    5044 *
    51  * @param string $name The name of the specialised footer.
     45 * @param mixed $names The names of the specialised footer templates (it can be a string, or an array of names to search for in priority order.).
    5246 */
    53 function get_footer( $name = null ) {
    54         do_action( 'get_footer', $name );
     47function get_footer( $names = null ) {
     48        do_action( 'get_footer', $names );
    5549
    56         $templates = array();
    57         if ( isset($name) )
    58                 $templates[] = "footer-{$name}.php";
    59 
    60         $templates[] = "footer.php";
    61 
    6250        // Backward compat code will be removed in a future release
    63         if ('' == locate_template($templates, true))
     51        if ('' == get_template_part( 'footer', $names ) )
    6452                load_template( WPINC . '/theme-compat/footer.php');
    6553}
    6654
     
    7765 * @since 1.5.0
    7866 * @uses do_action() Calls 'get_sidebar' action.
    7967 *
    80  * @param string $name The name of the specialised sidebar.
     68 * @param mixed $names The names of the specialised sidebar templates (it can be a string, or an array of names to search for in priority order.).
    8169 */
    82 function get_sidebar( $name = null ) {
    83         do_action( 'get_sidebar', $name );
     70function get_sidebar( $names = array() ) {
     71        do_action( 'get_sidebar', $names );
    8472
    85         $templates = array();
    86         if ( isset($name) )
    87                 $templates[] = "sidebar-{$name}.php";
    88 
    89         $templates[] = "sidebar.php";
    90 
    9173        // Backward compat code will be removed in a future release
    92         if ('' == locate_template($templates, true))
     74        if ('' == get_template_part( 'sidebar', $names ) )
    9375                load_template( WPINC . '/theme-compat/sidebar.php');
    9476}
    9577
     
    11193 *
    11294 * @uses locate_template()
    11395 * @since 3.0.0
    114  * @uses do_action() Calls 'get_template_part{$slug}' action.
     96 * @uses do_action() Calls 'get_template_part_{$slug}' action.
    11597 *
    11698 * @param string $slug The slug name for the generic template.
    117  * @param string $name The name of the specialised template.
     99 * @param mixed $names The names of the specialised templates (it can be a string, or an array of names to search for in priority order.).
    118100 */
    119 function get_template_part( $slug, $name = null ) {
    120         do_action( "get_template_part_{$slug}", $slug, $name );
    121 
     101function get_template_part( $slug, $names = array() ) {
     102        do_action( "get_template_part_{$slug}", $slug, $names );
     103       
    122104        $templates = array();
    123         if ( isset($name) )
     105        foreach ( (array)$names as $name ) {
    124106                $templates[] = "{$slug}-{$name}.php";
    125 
     107        }
    126108        $templates[] = "{$slug}.php";
    127109
    128         locate_template($templates, true, false);
     110        return locate_template($templates, true, false);
    129111}
    130112
    131113/**