diff --git a/src/wp-admin/edit-form-advanced.php b/src/wp-admin/edit-form-advanced.php index 392b51406d..1627439518 100644 --- a/src/wp-admin/edit-form-advanced.php +++ b/src/wp-admin/edit-form-advanced.php @@ -259,7 +259,7 @@ foreach ( get_object_taxonomies( $post ) as $tax_name ) { add_meta_box( $tax_meta_box_id, $label, $taxonomy->meta_box_cb, null, 'side', 'core', array( 'taxonomy' => $tax_name ) ); } -if ( post_type_supports( $post_type, 'page-attributes' ) || count( get_page_templates( null, $post_type ) ) > 0 ) { +if ( post_type_supports( $post_type, 'page-attributes' ) || count( get_page_templates( $post ) ) > 0 ) { add_meta_box( 'pageparentdiv', $post_type_object->labels->attributes, 'page_attributes_meta_box', null, 'side', 'core' ); } diff --git a/src/wp-includes/class-wp-theme.php b/src/wp-includes/class-wp-theme.php index 66f623ee90..8b3661a888 100644 --- a/src/wp-includes/class-wp-theme.php +++ b/src/wp-includes/class-wp-theme.php @@ -1082,7 +1082,7 @@ final class WP_Theme implements ArrayAccess { $post_templates = isset( $post_templates[ $post_type ] ) ? $post_templates[ $post_type ] : array(); if ( $this->parent() ) { - $post_templates += $this->parent()->get_page_templates( $post ); + $post_templates += $this->parent()->get_page_templates( $post, $post_type ); } /** diff --git a/tests/phpunit/data/themedir1/page-templates-child/style.css b/tests/phpunit/data/themedir1/page-templates-child/style.css new file mode 100644 index 0000000000..2b54037472 --- /dev/null +++ b/tests/phpunit/data/themedir1/page-templates-child/style.css @@ -0,0 +1,12 @@ +/* +Theme Name: Page Template Child Theme +Theme URI: http://example.org/ +Description: An example child theme with page templates +Version: 0.1 +Author: Mr. WordPress +Author URI: http://wordpress.org/ +Template: page-templates + +This is just a stub to test the loading of the above metadata. + +*/ diff --git a/tests/phpunit/tests/admin/includesTheme.php b/tests/phpunit/tests/admin/includesTheme.php index ba76bf15c7..5319006865 100644 --- a/tests/phpunit/tests/admin/includesTheme.php +++ b/tests/phpunit/tests/admin/includesTheme.php @@ -85,4 +85,29 @@ class Tests_Admin_includesTheme extends WP_UnitTestCase { ), get_page_templates( null, 'post' ) ); $this->assertEquals( array(), get_page_templates( null, 'bar' ) ); } + + /** + * @ticket 38696 + */ + function test_page_templates_child_theme() { + $theme = wp_get_theme( 'page-templates-child' ); + $this->assertNotEmpty( $theme ); + + switch_theme( $theme['Template'], $theme['Stylesheet'] ); + + $this->assertEqualSetsWithIndex( array( + 'Top Level' => 'template-top-level-post-types.php', + 'Sub Dir' => 'subdir/template-sub-dir-post-types.php', + ), get_page_templates( null, 'foo' ) ); + $this->assertEqualSetsWithIndex( array( + 'Top Level' => 'template-top-level-post-types.php', + 'Sub Dir' => 'subdir/template-sub-dir-post-types.php', + ), get_page_templates( null, 'post' ) ); + $this->assertEqualSetsWithIndex( array( + 'Top Level' => 'template-top-level.php', + 'Sub Dir' => 'subdir/template-sub-dir.php', + 'This Template Header Is On One Line' => 'template-header.php', + ), get_page_templates() ); + $this->assertEquals( array(), get_page_templates( null, 'bar' ) ); + } }