WordPress.org

Make WordPress Core

Ticket #15141: get_templates_filter.patch

File get_templates_filter.patch, 2.6 KB (added by 5ubliminal, 8 years ago)

Patch file with new feature.

  • wp-includes/general-template.php

     
    11<?php
    22/**
     3 * Stub function allowing filters on get_(header|footer|sidebar|template_part) functions.
     4 * Plugins can take over template elements giving a lot more versatility to template designers.
     5 *
     6 * @author 5ubliminal
     7 * @internal
     8 * @param string $template
     9 * @param array $templates
     10 * @return array
     11 */
     12function apply_templates_filter($template, $templates){
     13        // If plugins don't return a valid array just return the defaults
     14        if(!is_array($tpls = apply_filters("{$template}_templates", $templates)) || empty($tpls)) return $templates;
     15        // Try and validate existance of a file in new template array... if not found fade back to defaults
     16        if((!$tpl = locate_template($tpls)) || empty($tpl)) return $templates;
     17        // Return the new array here (previous line can be skipped but better safe than sorry)
     18        return $tpls;
     19}
     20
     21/**
    322 * General template tags that can go anywhere in a template.
    423 *
    524 * @package WordPress
     
    2948                $templates[] = "header-{$name}.php";
    3049
    3150        $templates[] = "header.php";
     51       
     52        /**
     53         * Allow plugins to hook in here and add / remove templates.
     54         * @see apply_templates_filter()
     55         */
     56        $templates = apply_templates_filter('header', $templates);
    3257
    3358        // Backward compat code will be removed in a future release
    3459        if ('' == locate_template($templates, true))
     
    5984
    6085        $templates[] = "footer.php";
    6186
     87        /**
     88         * Allow plugins to hook in here and add / remove templates.
     89         * @see apply_templates_filter()
     90         */
     91        $templates = apply_templates_filter('footer', $templates);
     92
    6293        // Backward compat code will be removed in a future release
    6394        if ('' == locate_template($templates, true))
    6495                load_template( ABSPATH . WPINC . '/theme-compat/footer.php');
     
    88119
    89120        $templates[] = "sidebar.php";
    90121
     122        /**
     123         * Allow plugins to hook in here and add / remove templates.
     124         * @see apply_templates_filter()
     125         */
     126        $templates = apply_templates_filter('sidebar', $templates);
     127
    91128        // Backward compat code will be removed in a future release
    92129        if ('' == locate_template($templates, true))
    93130                load_template( ABSPATH . WPINC . '/theme-compat/sidebar.php');
     
    125162
    126163        $templates[] = "{$slug}.php";
    127164
     165        /**
     166         * Allow plugins to hook in here and add / remove templates.
     167         * @see apply_templates_filter()
     168         */
     169        $templates = apply_templates_filter("part-{$slug}", $templates);
     170       
    128171        locate_template($templates, true, false);
    129172}
    130173