mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-30 23:30:05 +00:00
Posts, Post Types: Add support for post type templates.
WordPress has supported custom page templates for over 12 years, allowing developers to create various layouts for specific pages. While this feature is very helpful, it has always been limited to the 'page' post type and not was not available to other post types. By opening up the page template functionality to all post types, we continue to improve the template hierarchy's flexibility. In addition to the `Template Name` file header, the post types supported by a template can be specified using `Template Post Type: post, foo, bar`. When at least one template exists for a post type, the 'Post Attributes' meta box will be displayed in the back end, without the need to add post type support for `'page-attributes'`. 'Post Attributes' can be customized per post type using the `'attributes'` label when registering a post type. Props johnbillion, Mte90, dipesh.kakadiya, swissspidy. Fixes #18375. git-svn-id: https://develop.svn.wordpress.org/trunk@38951 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -36,6 +36,7 @@ class Tests_Template extends WP_UnitTestCase {
|
||||
'post_date' => '1984-02-25 12:34:56',
|
||||
) );
|
||||
set_post_format( self::$post, 'quote' );
|
||||
add_post_meta( self::$post->ID, '_wp_page_template', 'templates/post.php' );
|
||||
}
|
||||
|
||||
public function setUp() {
|
||||
@@ -203,8 +204,12 @@ class Tests_Template extends WP_UnitTestCase {
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 18375
|
||||
*/
|
||||
public function test_single_template_hierarchy_for_post() {
|
||||
$this->assertTemplateHierarchy( get_permalink( self::$post ), array(
|
||||
'templates/post.php',
|
||||
'single-post-post-name-😀.php',
|
||||
'single-post-post-name-%f0%9f%98%80.php',
|
||||
'single-post.php',
|
||||
@@ -228,6 +233,26 @@ class Tests_Template extends WP_UnitTestCase {
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 18375
|
||||
*/
|
||||
public function test_single_template_hierarchy_for_custom_post_type_with_template() {
|
||||
$cpt = self::factory()->post->create_and_get( array(
|
||||
'post_type' => 'cpt',
|
||||
'post_name' => 'cpt-name-😀',
|
||||
) );
|
||||
add_post_meta( $cpt->ID, '_wp_page_template', 'templates/cpt.php' );
|
||||
|
||||
$this->assertTemplateHierarchy( get_permalink( $cpt ), array(
|
||||
'templates/cpt.php',
|
||||
'single-cpt-cpt-name-😀.php',
|
||||
'single-cpt-cpt-name-%f0%9f%98%80.php',
|
||||
'single-cpt.php',
|
||||
'single.php',
|
||||
'singular.php',
|
||||
) );
|
||||
}
|
||||
|
||||
public function test_attachment_template_hierarchy() {
|
||||
$attachment = self::factory()->attachment->create_and_get( array(
|
||||
'post_name' => 'attachment-name-😀',
|
||||
@@ -247,11 +272,37 @@ class Tests_Template extends WP_UnitTestCase {
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 18375
|
||||
*/
|
||||
public function test_attachment_template_hierarchy_with_template() {
|
||||
$attachment = self::factory()->attachment->create_and_get( array(
|
||||
'post_name' => 'attachment-name-😀',
|
||||
'file' => 'image.jpg',
|
||||
'post_mime_type' => 'image/jpeg',
|
||||
) );
|
||||
|
||||
add_post_meta( $attachment, '_wp_page_template', 'templates/cpt.php' );
|
||||
|
||||
$this->assertTemplateHierarchy( get_permalink( $attachment ), array(
|
||||
'image-jpeg.php',
|
||||
'jpeg.php',
|
||||
'image.php',
|
||||
'attachment.php',
|
||||
'single-attachment-attachment-name-😀.php',
|
||||
'single-attachment-attachment-name-%f0%9f%98%80.php',
|
||||
'single-attachment.php',
|
||||
'single.php',
|
||||
'singular.php',
|
||||
) );
|
||||
}
|
||||
|
||||
public function test_embed_template_hierarchy_for_post() {
|
||||
$this->assertTemplateHierarchy( get_post_embed_url( self::$post ), array(
|
||||
'embed-post-quote.php',
|
||||
'embed-post.php',
|
||||
'embed.php',
|
||||
'templates/post.php',
|
||||
'single-post-post-name-😀.php',
|
||||
'single-post-post-name-%f0%9f%98%80.php',
|
||||
'single-post.php',
|
||||
|
||||
Reference in New Issue
Block a user