WordPress.org

Make WordPress Core

Changeset 39168


Ignore:
Timestamp:
11/08/2016 10:40:28 PM (5 years ago)
Author:
swissspidy
Message:

Posts, Post Types: Fix post type templates with child themes.

After [38951] added support for post type templates beyond pages, this fixes an issue where an empty meta box would be shown when using child themes.

Fixes #38696.

Location:
trunk
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/edit-form-advanced.php

    r38983 r39168  
    260260}
    261261
    262 if ( post_type_supports( $post_type, 'page-attributes' ) || count( get_page_templates( null, $post_type ) ) > 0 ) {
     262if ( post_type_supports( $post_type, 'page-attributes' ) || count( get_page_templates( $post ) ) > 0 ) {
    263263    add_meta_box( 'pageparentdiv', $post_type_object->labels->attributes, 'page_attributes_meta_box', null, 'side', 'core' );
    264264}
  • trunk/src/wp-includes/class-wp-theme.php

    r38951 r39168  
    10831083
    10841084        if ( $this->parent() ) {
    1085             $post_templates += $this->parent()->get_page_templates( $post );
     1085            $post_templates += $this->parent()->get_page_templates( $post, $post_type );
    10861086        }
    10871087
  • trunk/tests/phpunit/tests/admin/includesTheme.php

    r38951 r39168  
    8686        $this->assertEquals( array(), get_page_templates( null, 'bar' ) );
    8787    }
     88
     89    /**
     90     * @ticket 38696
     91     */
     92    function test_page_templates_child_theme() {
     93        $theme = wp_get_theme( 'page-templates-child' );
     94        $this->assertNotEmpty( $theme );
     95
     96        switch_theme( $theme['Template'], $theme['Stylesheet'] );
     97
     98        $this->assertEqualSetsWithIndex( array(
     99            'Top Level' => 'template-top-level-post-types.php',
     100            'Sub Dir'   => 'subdir/template-sub-dir-post-types.php',
     101        ), get_page_templates( null, 'foo' ) );
     102        $this->assertEqualSetsWithIndex( array(
     103            'Top Level' => 'template-top-level-post-types.php',
     104            'Sub Dir'   => 'subdir/template-sub-dir-post-types.php',
     105        ), get_page_templates( null, 'post' ) );
     106        $this->assertEqualSetsWithIndex( array(
     107            'Top Level'                           => 'template-top-level.php',
     108            'Sub Dir'                             => 'subdir/template-sub-dir.php',
     109            'This Template Header Is On One Line' => 'template-header.php',
     110        ), get_page_templates() );
     111        $this->assertEquals( array(), get_page_templates( null, 'bar' ) );
     112    }
    88113}
Note: See TracChangeset for help on using the changeset viewer.