WordPress.org

Make WordPress Core

Ticket #28094: 28094.diff

File 28094.diff, 1.6 KB (added by iamfriendly, 5 years ago)

Added a filter at the top of get_template_part() to bail if we wish to, add an action after locate_template

  • wp-includes/general-template.php

    diff --git wp-includes/general-template.php wp-includes/general-template.php
    index 48b8de9..bf83178 100644
    function get_sidebar( $name = null ) { 
    148148 * @param string $name The name of the specialised template.
    149149 */
    150150function get_template_part( $slug, $name = null ) {
     151
     152        /**
     153         * Filters whether get_template_part() will continue
     154         *
     155         * @since 4.4.0
     156         *
     157         * @param bool Whether get_template_part will continue to locate the template part
     158         * @param string $slug The slug name for the generic template.
     159         * @param string $name The name of the specialised template.
     160         */
     161        $get_template_part = apply_filters( "get_template_part_{$slug}", true, $slug, $name );
     162
     163        if ( ! $get_template_part ) {
     164                return;
     165        }
     166
    151167        /**
    152168         * Fires before the specified template part file is loaded.
    153169         *
    function get_template_part( $slug, $name = null ) { 
    163179
    164180        $templates = array();
    165181        $name = (string) $name;
    166         if ( '' !== $name )
     182        if ( '' !== $name ) {
    167183                $templates[] = "{$slug}-{$name}.php";
     184        }
    168185
    169186        $templates[] = "{$slug}.php";
    170187
    171         locate_template($templates, true, false);
     188        locate_template( $templates, true, false );
     189
     190        /**
     191         * Fires after the specified template part file is loaded.
     192         *
     193         * The dynamic portion of the hook name, `$slug`, refers to the slug name
     194         * for the generic template part.
     195         *
     196         * @since 4.4.0
     197         *
     198         * @param string $slug The slug name for the generic template.
     199         * @param string $name The name of the specialized template.
     200         */
     201        do_action( "after_get_template_part_{$slug}", $slug, $name );
    172202}
    173203
    174204/**