WordPress.org

Make WordPress Core

Ticket #15086: 15086.001.diff

File 15086.001.diff, 1.4 KB (added by aaroncampbell, 8 years ago)
  • wp-includes/general-template.php

     
    116116 * @param string $slug The slug name for the generic template.
    117117 * @param string $name The name of the specialised template.
    118118 */
    119 function get_template_part( $slug, $name = null ) {
    120         do_action( "get_template_part_{$slug}", $slug, $name );
     119function get_template_part( $slug, $name = null, $directory = null ) {
     120        if ( false !== strpos( $slug, DIRECTORY_SEPARATOR ) ) {
     121                $original_slug = $slug;
     122                $slug = substr( strrchr( $slug, DIRECTORY_SEPARATOR ), 1 );
     123                if ( empty( $directory ) ) {
     124                        $directory = substr( $original_slug, 0, strrpos( $original_slug, DIRECTORY_SEPARATOR ) );
     125                }
     126        }
     127        $slug = sanitize_file_name( $slug );
    121128
     129        // @todo sanitize here
     130        $directory = rtrim( $directory, DIRECTORY_SEPARATOR );
     131
     132        do_action( "get_template_part_{$slug}", $slug, $name, $directory );
     133
    122134        $templates = array();
     135        if ( ! empty( $directory ) ) {
     136                if ( isset($name) )
     137                        $templates[] = $directory . DIRECTORY_SEPARATOR . "{$slug}-{$name}.php";
     138
     139                $templates[] = $directory . DIRECTORY_SEPARATOR . "{$slug}.php";
     140        }
     141
    123142        if ( isset($name) )
    124143                $templates[] = "{$slug}-{$name}.php";
    125144
    126145        $templates[] = "{$slug}.php";
    127146
    128         locate_template($templates, true, false);
     147        locate_template( $templates, true, false );
    129148}
    130149
    131150/**