<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[38951] trunk: Posts, Post Types: Add support for post type templates.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/38951">38951</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/38951","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>swissspidy</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2016-10-26 08:06:43 +0000 (Wed, 26 Oct 2016)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>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 <a href="https://core.trac.wordpress.org/ticket/18375">#18375</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpadmineditformadvancedphp">trunk/src/wp-admin/edit-form-advanced.php</a></li>
<li><a href="#trunksrcwpadminincludesclasswppostslisttablephp">trunk/src/wp-admin/includes/class-wp-posts-list-table.php</a></li>
<li><a href="#trunksrcwpadminincludesmetaboxesphp">trunk/src/wp-admin/includes/meta-boxes.php</a></li>
<li><a href="#trunksrcwpadminincludestemplatephp">trunk/src/wp-admin/includes/template.php</a></li>
<li><a href="#trunksrcwpadminincludesthemephp">trunk/src/wp-admin/includes/theme.php</a></li>
<li><a href="#trunksrcwpincludesclasswppostphp">trunk/src/wp-includes/class-wp-post.php</a></li>
<li><a href="#trunksrcwpincludesclasswpthemephp">trunk/src/wp-includes/class-wp-theme.php</a></li>
<li><a href="#trunksrcwpincludesposttemplatephp">trunk/src/wp-includes/post-template.php</a></li>
<li><a href="#trunksrcwpincludespostphp">trunk/src/wp-includes/post.php</a></li>
<li><a href="#trunksrcwpincludestemplatephp">trunk/src/wp-includes/template.php</a></li>
<li><a href="#trunktestsphpunittestsadminincludesThemephp">trunk/tests/phpunit/tests/admin/includesTheme.php</a></li>
<li><a href="#trunktestsphpunittestspostgetBodyClassphp">trunk/tests/phpunit/tests/post/getBodyClass.php</a></li>
<li><a href="#trunktestsphpunittestspostobjectsphp">trunk/tests/phpunit/tests/post/objects.php</a></li>
<li><a href="#trunktestsphpunittestsposttemplatephp">trunk/tests/phpunit/tests/post/template.php</a></li>
<li><a href="#trunktestsphpunittestsqueryconditionalsphp">trunk/tests/phpunit/tests/query/conditionals.php</a></li>
<li><a href="#trunktestsphpunitteststemplatephp">trunk/tests/phpunit/tests/template.php</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunktestsphpunitdatathemedir1pagetemplatessubdirtemplatesubdirposttypesphp">trunk/tests/phpunit/data/themedir1/page-templates/subdir/template-sub-dir-post-types.php</a></li>
<li><a href="#trunktestsphpunitdatathemedir1pagetemplatestemplatetoplevelposttypesphp">trunk/tests/phpunit/data/themedir1/page-templates/template-top-level-post-types.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpadmineditformadvancedphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/edit-form-advanced.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/edit-form-advanced.php 2016-10-26 07:51:41 UTC (rev 38950)
+++ trunk/src/wp-admin/edit-form-advanced.php 2016-10-26 08:06:43 UTC (rev 38951)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -259,8 +259,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> add_meta_box( $tax_meta_box_id, $label, $taxonomy->meta_box_cb, null, 'side', 'core', array( 'taxonomy' => $tax_name ) );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-if ( post_type_supports($post_type, 'page-attributes') )
- add_meta_box('pageparentdiv', 'page' == $post_type ? __('Page Attributes') : __('Attributes'), 'page_attributes_meta_box', null, 'side', 'core');
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+if ( post_type_supports( $post_type, 'page-attributes' ) || count( get_page_templates( null, $post_type ) ) > 0 ) {
+ add_meta_box( 'pageparentdiv', $post_type_object->labels->attributes, 'page_attributes_meta_box', null, 'side', 'core' );
+}
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( $thumbnail_support && current_user_can( 'upload_files' ) )
</span><span class="cx" style="display: block; padding: 0 10px"> add_meta_box('postimagediv', esc_html( $post_type_object->labels->featured_image ), 'post_thumbnail_meta_box', null, 'side', 'low');
</span></span></pre></div>
<a id="trunksrcwpadminincludesclasswppostslisttablephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/includes/class-wp-posts-list-table.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/includes/class-wp-posts-list-table.php 2016-10-26 07:51:41 UTC (rev 38950)
+++ trunk/src/wp-admin/includes/class-wp-posts-list-table.php 2016-10-26 08:06:43 UTC (rev 38951)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1528,31 +1528,28 @@
</span><span class="cx" style="display: block; padding: 0 10px"> <span class="input-text-wrap"><input type="text" name="menu_order" class="inline-edit-menu-order-input" value="<?php echo $post->menu_order ?>" /></span>
</span><span class="cx" style="display: block; padding: 0 10px"> </label>
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- <?php endif; // !$bulk
-
- if ( 'page' === $screen->post_type ) :
- ?>
-
- <label>
- <span class="title"><?php _e( 'Template' ); ?></span>
- <select name="page_template">
- <?php if ( $bulk ) : ?>
- <option value="-1"><?php _e( '— No Change —' ); ?></option>
- <?php endif; // $bulk ?>
- <?php
- /** This filter is documented in wp-admin/includes/meta-boxes.php */
- $default_title = apply_filters( 'default_page_template_title', __( 'Default Template' ), 'quick-edit' );
- ?>
- <option value="default"><?php echo esc_html( $default_title ); ?></option>
- <?php page_template_dropdown() ?>
- </select>
- </label>
-
</del><span class="cx" style="display: block; padding: 0 10px"> <?php
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- endif; // page post_type
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ endif; // !$bulk
</ins><span class="cx" style="display: block; padding: 0 10px"> endif; // page-attributes
</span><span class="cx" style="display: block; padding: 0 10px"> ?>
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ <?php if ( 0 < count( get_page_templates( null, $screen->post_type ) ) ) : ?>
+ <label>
+ <span class="title"><?php _e( 'Template' ); ?></span>
+ <select name="page_template">
+<?php if ( $bulk ) : ?>
+ <option value="-1"><?php _e( '— No Change —' ); ?></option>
+<?php endif; // $bulk ?>
+ <?php
+ /** This filter is documented in wp-admin/includes/meta-boxes.php */
+ $default_title = apply_filters( 'default_page_template_title', __( 'Default Template' ), 'quick-edit' );
+ ?>
+ <option value="default"><?php echo esc_html( $default_title ); ?></option>
+ <?php page_template_dropdown( $post->page_template, $screen->post_type ) ?>
+ </select>
+ </label>
+ <?php endif; ?>
+
</ins><span class="cx" style="display: block; padding: 0 10px"> <?php if ( count( $flat_taxonomies ) && !$bulk ) : ?>
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> <?php foreach ( $flat_taxonomies as $taxonomy ) : ?>
</span></span></pre></div>
<a id="trunksrcwpadminincludesmetaboxesphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/includes/meta-boxes.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/includes/meta-boxes.php 2016-10-26 07:51:41 UTC (rev 38950)
+++ trunk/src/wp-admin/includes/meta-boxes.php 2016-10-26 08:06:43 UTC (rev 38951)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -788,8 +788,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param object $post
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function page_attributes_meta_box($post) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $post_type_object = get_post_type_object($post->post_type);
- if ( $post_type_object->hierarchical ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( is_post_type_hierarchical( $post->post_type ) ) :
</ins><span class="cx" style="display: block; padding: 0 10px"> $dropdown_args = array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'post_type' => $post->post_type,
</span><span class="cx" style="display: block; padding: 0 10px"> 'exclude_tree' => $post->ID,
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -812,16 +811,17 @@
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> $dropdown_args = apply_filters( 'page_attributes_dropdown_pages_args', $dropdown_args, $post );
</span><span class="cx" style="display: block; padding: 0 10px"> $pages = wp_dropdown_pages( $dropdown_args );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ! empty($pages) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! empty($pages) ) :
</ins><span class="cx" style="display: block; padding: 0 10px"> ?>
</span><span class="cx" style="display: block; padding: 0 10px"> <p><strong><?php _e('Parent') ?></strong></p>
</span><span class="cx" style="display: block; padding: 0 10px"> <label class="screen-reader-text" for="parent_id"><?php _e('Parent') ?></label>
</span><span class="cx" style="display: block; padding: 0 10px"> <?php echo $pages; ?>
</span><span class="cx" style="display: block; padding: 0 10px"> <?php
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- } // end empty pages check
- } // end hierarchical check.
- if ( 'page' == $post->post_type && 0 != count( get_page_templates( $post ) ) && get_option( 'page_for_posts' ) != $post->ID ) {
- $template = !empty($post->page_template) ? $post->page_template : false;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ endif; // end empty pages check
+ endif; // end hierarchical check.
+
+ if ( count( get_page_templates( $post ) ) > 0 && get_option( 'page_for_posts' ) != $post->ID ) :
+ $template = ! empty( $post->page_template ) ? $post->page_template : false;
</ins><span class="cx" style="display: block; padding: 0 10px"> ?>
</span><span class="cx" style="display: block; padding: 0 10px"> <p><strong><?php _e('Template') ?></strong><?php
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -835,7 +835,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> do_action( 'page_attributes_meta_box_template', $template, $post );
</span><span class="cx" style="display: block; padding: 0 10px"> ?></p>
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-<label class="screen-reader-text" for="page_template"><?php _e('Page Template') ?></label><select name="page_template" id="page_template">
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<label class="screen-reader-text" for="page_template">
+ <?php
+ $post_type_object = get_post_type_object( $post->post_type );
+ echo esc_html( $post_type_object->labels->attributes );
+ ?>
+</label>
+<select name="page_template" id="page_template">
</ins><span class="cx" style="display: block; padding: 0 10px"> <?php
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Filters the title of the default page template displayed in the drop-down.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -849,16 +855,16 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $default_title = apply_filters( 'default_page_template_title', __( 'Default Template' ), 'meta-box' );
</span><span class="cx" style="display: block; padding: 0 10px"> ?>
</span><span class="cx" style="display: block; padding: 0 10px"> <option value="default"><?php echo esc_html( $default_title ); ?></option>
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-<?php page_template_dropdown($template); ?>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php page_template_dropdown( $template, $post->post_type ); ?>
</ins><span class="cx" style="display: block; padding: 0 10px"> </select>
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-<?php
- } ?>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php endif; ?>
+<?php if ( post_type_supports( $post->post_type, 'page-attributes' ) ) : ?>
</ins><span class="cx" style="display: block; padding: 0 10px"> <p><strong><?php _e('Order') ?></strong></p>
</span><span class="cx" style="display: block; padding: 0 10px"> <p><label class="screen-reader-text" for="menu_order"><?php _e('Order') ?></label><input name="menu_order" type="text" size="4" id="menu_order" value="<?php echo esc_attr($post->menu_order) ?>" /></p>
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-<?php if ( 'page' == $post->post_type && get_current_screen()->get_help_tabs() ) { ?>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php if ( 'page' == $post->post_type && get_current_screen()->get_help_tabs() ) : ?>
</ins><span class="cx" style="display: block; padding: 0 10px"> <p><?php _e( 'Need help? Use the Help tab above the screen title.' ); ?></p>
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-<?php
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php endif;
+ endif;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // -- Link related Meta Boxes
</span></span></pre></div>
<a id="trunksrcwpadminincludestemplatephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/includes/template.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/includes/template.php 2016-10-26 07:51:41 UTC (rev 38950)
+++ trunk/src/wp-admin/includes/template.php 2016-10-26 08:06:43 UTC (rev 38951)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -293,14 +293,15 @@
</span><span class="cx" style="display: block; padding: 0 10px"> <div class="ss">' . mysql2date( 's', $post->post_date, false ) . '</div>
</span><span class="cx" style="display: block; padding: 0 10px"> <div class="post_password">' . esc_html( $post->post_password ) . '</div>';
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( $post_type_object->hierarchical )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( $post_type_object->hierarchical ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> echo '<div class="post_parent">' . $post->post_parent . '</div>';
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( $post->post_type == 'page' )
- echo '<div class="page_template">' . esc_html( get_post_meta( $post->ID, '_wp_page_template', true ) ) . '</div>';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ echo '<div class="page_template">' . esc_html( $post->page_template ) . '</div>';
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( post_type_supports( $post->post_type, 'page-attributes' ) )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( post_type_supports( $post->post_type, 'page-attributes' ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> echo '<div class="menu_order">' . $post->menu_order . '</div>';
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $taxonomy_names = get_object_taxonomies( $post->post_type );
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ( $taxonomy_names as $taxonomy_name) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -761,11 +762,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * Print out option HTML elements for the page templates drop-down.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 1.5.0
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 4.7.0 Added the `$post_type` parameter.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param string $default Optional. The template file name. Default empty.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param string $default Optional. The template file name. Default empty.
+ * @param string $post_type Optional. Post type to get templates for. Default 'post'.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-function page_template_dropdown( $default = '' ) {
- $templates = get_page_templates( get_post() );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+function page_template_dropdown( $default = '', $post_type = 'page' ) {
+ $templates = get_page_templates( null, $post_type );
</ins><span class="cx" style="display: block; padding: 0 10px"> ksort( $templates );
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ( array_keys( $templates ) as $template ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $selected = selected( $default, $templates[ $template ], false );
</span></span></pre></div>
<a id="trunksrcwpadminincludesthemephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/includes/theme.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/includes/theme.php 2016-10-26 07:51:41 UTC (rev 38950)
+++ trunk/src/wp-admin/includes/theme.php 2016-10-26 08:06:43 UTC (rev 38951)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -102,12 +102,14 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * Get the Page Templates available in this theme
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 1.5.0
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 4.7.0 Added the `$post_type` parameter.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param WP_Post|null $post Optional. The post being edited, provided for context.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param WP_Post|null $post Optional. The post being edited, provided for context.
+ * @param string $post_type Optional. Post type to get the templates for. Default 'page'.
</ins><span class="cx" style="display: block; padding: 0 10px"> * @return array Key is the template name, value is the filename of the template
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-function get_page_templates( $post = null ) {
- return array_flip( wp_get_theme()->get_page_templates( $post ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+function get_page_templates( $post = null, $post_type = 'page' ) {
+ return array_flip( wp_get_theme()->get_page_templates( $post, $post_type ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span></span></pre></div>
<a id="trunksrcwpincludesclasswppostphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/class-wp-post.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/class-wp-post.php 2016-10-26 07:51:41 UTC (rev 38950)
+++ trunk/src/wp-includes/class-wp-post.php 2016-10-26 08:06:43 UTC (rev 38951)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -254,7 +254,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> return true;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( 'page_template' == $key )
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- return ( 'page' == $this->post_type );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return true;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( 'post_category' == $key )
</span><span class="cx" style="display: block; padding: 0 10px"> return true;
</span></span></pre></div>
<a id="trunksrcwpincludesclasswpthemephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/class-wp-theme.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/class-wp-theme.php 2016-10-26 07:51:41 UTC (rev 38950)
+++ trunk/src/wp-includes/class-wp-theme.php 2016-10-26 08:06:43 UTC (rev 38951)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -538,7 +538,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 3.4.0
</span><span class="cx" style="display: block; padding: 0 10px"> * @access private
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param string $key Type of data to store (theme, screenshot, headers, page_templates)
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param string $key Type of data to store (theme, screenshot, headers, post_templates)
</ins><span class="cx" style="display: block; padding: 0 10px"> * @param string $data Data to store
</span><span class="cx" style="display: block; padding: 0 10px"> * @return bool Return value from wp_cache_add()
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -554,7 +554,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 3.4.0
</span><span class="cx" style="display: block; padding: 0 10px"> * @access private
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param string $key Type of data to retrieve (theme, screenshot, headers, page_templates)
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param string $key Type of data to retrieve (theme, screenshot, headers, post_templates)
</ins><span class="cx" style="display: block; padding: 0 10px"> * @return mixed Retrieved data
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> private function cache_get( $key ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -568,7 +568,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @access public
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function cache_delete() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- foreach ( array( 'theme', 'screenshot', 'headers', 'page_templates' ) as $key )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ foreach ( array( 'theme', 'screenshot', 'headers', 'post_templates' ) as $key )
</ins><span class="cx" style="display: block; padding: 0 10px"> wp_cache_delete( $key . '-' . $this->cache_hash, 'themes' );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->template = $this->textdomain_loaded = $this->theme_root_uri = $this->parent = $this->errors = $this->headers_sanitized = $this->name_translated = null;
</span><span class="cx" style="display: block; padding: 0 10px"> $this->headers = array();
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1006,56 +1006,101 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Returns the theme's page templates.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Returns the theme's post templates.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @since 3.4.0
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 4.7.0
</ins><span class="cx" style="display: block; padding: 0 10px"> * @access public
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param WP_Post|null $post Optional. The post being edited, provided for context.
- * @return array Array of page templates, keyed by filename, with the value of the translated header name.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return array Array of page templates, keyed by filename and post type,
+ * with the value of the translated header name.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- public function get_page_templates( $post = null ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function get_post_templates() {
</ins><span class="cx" style="display: block; padding: 0 10px"> // If you screw up your current theme and we invalidate your parent, most things still work. Let it slide.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( $this->errors() && $this->errors()->get_error_codes() !== array( 'theme_parent_invalid' ) )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( $this->errors() && $this->errors()->get_error_codes() !== array( 'theme_parent_invalid' ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> return array();
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $page_templates = $this->cache_get( 'page_templates' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $post_templates = $this->cache_get( 'post_templates' );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ! is_array( $page_templates ) ) {
- $page_templates = array();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! is_array( $post_templates ) ) {
+ $post_templates = array();
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $files = (array) $this->get_files( 'php', 1 );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ( $files as $file => $full_path ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ! preg_match( '|Template Name:(.*)$|mi', file_get_contents( $full_path ), $header ) )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! preg_match( '|Template Name:(.*)$|mi', file_get_contents( $full_path ), $header ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> continue;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $page_templates[ $file ] = _cleanup_header_comment( $header[1] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ }
+
+ $types = array( 'page' );
+ if ( preg_match( '|Template Post Type:(.*)$|mi', file_get_contents( $full_path ), $type ) ) {
+ $types = explode( ',', _cleanup_header_comment( $type[1] ) );
+ }
+
+ foreach ( $types as $type ) {
+ $type = trim( $type );
+ if ( ! isset( $post_templates[ $type ] ) ) {
+ $post_templates[ $type ] = array();
+ }
+
+ $post_templates[ $type ][ $file ] = _cleanup_header_comment( $header[1] );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->cache_add( 'page_templates', $page_templates );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->cache_add( 'post_templates', $post_templates );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( $this->load_textdomain() ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- foreach ( $page_templates as &$page_template ) {
- $page_template = $this->translate_header( 'Template Name', $page_template );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ foreach ( $post_templates as &$post_type ) {
+ foreach ( $post_type as &$post_template ) {
+ $post_template = $this->translate_header( 'Template Name', $post_template );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( $this->parent() )
- $page_templates += $this->parent()->get_page_templates( $post );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return $post_templates;
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Returns the theme's post templates for a given post type.
+ *
+ * @since 3.4.0
+ * @since 4.7.0 Added the `$post_type` parameter.
+ * @access public
+ *
+ * @param WP_Post|null $post Optional. The post being edited, provided for context.
+ * @param string $post_type Optional. Post type to get the templates for. Default 'page'.
+ * If a post is provided, its post type is used.
+ * @return array Array of page templates, keyed by filename, with the value of the translated header name.
+ */
+ public function get_page_templates( $post = null, $post_type = 'page' ) {
+ if ( $post ) {
+ $post_type = get_post_type( $post );
+ }
+
+ $post_templates = $this->get_post_templates();
+ $post_templates = isset( $post_templates[ $post_type ] ) ? $post_templates[ $post_type ] : array();
+
+ if ( $this->parent() ) {
+ $post_templates += $this->parent()->get_page_templates( $post );
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Filters list of page templates for a theme.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * The dynamic portion of the hook name, `$post_type`, refers to the post type.
+ *
</ins><span class="cx" style="display: block; padding: 0 10px"> * @since 3.9.0
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 4.4.0 Converted to allow complete control over the `$page_templates` array.
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 4.7.0 Added the `$post_type` parameter.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param array $page_templates Array of page templates. Keys are filenames,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param array $post_templates Array of page templates. Keys are filenames,
</ins><span class="cx" style="display: block; padding: 0 10px"> * values are translated names.
</span><span class="cx" style="display: block; padding: 0 10px"> * @param WP_Theme $this The theme object.
</span><span class="cx" style="display: block; padding: 0 10px"> * @param WP_Post|null $post The post being edited, provided for context, or null.
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param string $post_type Post type to get the templates for.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- return (array) apply_filters( 'theme_page_templates', $page_templates, $this, $post );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return (array) apply_filters( "theme_{$post_type}_templates", $post_templates, $this, $post, $post_type );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span></span></pre></div>
<a id="trunksrcwpincludesposttemplatephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/post-template.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/post-template.php 2016-10-26 07:51:41 UTC (rev 38950)
+++ trunk/src/wp-includes/post-template.php 2016-10-26 08:06:43 UTC (rev 38951)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -594,31 +594,65 @@
</span><span class="cx" style="display: block; padding: 0 10px"> if ( is_404() )
</span><span class="cx" style="display: block; padding: 0 10px"> $classes[] = 'error404';
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( is_single() ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( is_singular() ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $post_id = $wp_query->get_queried_object_id();
</span><span class="cx" style="display: block; padding: 0 10px"> $post = $wp_query->get_queried_object();
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $post_type = $post->post_type;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $classes[] = 'single';
- if ( isset( $post->post_type ) ) {
- $classes[] = 'single-' . sanitize_html_class($post->post_type, $post_id);
- $classes[] = 'postid-' . $post_id;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( is_page_template() ) {
+ $classes[] = "{$post_type}-template";
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // Post Format
- if ( post_type_supports( $post->post_type, 'post-formats' ) ) {
- $post_format = get_post_format( $post->ID );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $template_slug = get_page_template_slug( $post_id );
+ $template_parts = explode( '/', $template_slug );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( $post_format && !is_wp_error($post_format) )
- $classes[] = 'single-format-' . sanitize_html_class( $post_format );
- else
- $classes[] = 'single-format-standard';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ foreach ( $template_parts as $part ) {
+ $classes[] = "{$post_type}-template-" . sanitize_html_class( str_replace( array( '.', '/' ), '-', basename( $part, '.php' ) ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $classes[] = "{$post_type}-template-" . sanitize_html_class( str_replace( '.', '-', $template_slug ) );
+ } else {
+ $classes[] = "{$post_type}-template-default";
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( is_single() ) {
+ $classes[] = 'single';
+ if ( isset( $post->post_type ) ) {
+ $classes[] = 'single-' . sanitize_html_class( $post->post_type, $post_id );
+ $classes[] = 'postid-' . $post_id;
+
+ // Post Format
+ if ( post_type_supports( $post->post_type, 'post-formats' ) ) {
+ $post_format = get_post_format( $post->ID );
+
+ if ( $post_format && !is_wp_error($post_format) )
+ $classes[] = 'single-format-' . sanitize_html_class( $post_format );
+ else
+ $classes[] = 'single-format-standard';
+ }
+ }
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( is_attachment() ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $mime_type = get_post_mime_type($post_id);
</span><span class="cx" style="display: block; padding: 0 10px"> $mime_prefix = array( 'application/', 'image/', 'text/', 'audio/', 'video/', 'music/' );
</span><span class="cx" style="display: block; padding: 0 10px"> $classes[] = 'attachmentid-' . $post_id;
</span><span class="cx" style="display: block; padding: 0 10px"> $classes[] = 'attachment-' . str_replace( $mime_prefix, '', $mime_type );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ } elseif ( is_page() ) {
+ $classes[] = 'page';
+
+ $page_id = $wp_query->get_queried_object_id();
+
+ $post = get_post($page_id);
+
+ $classes[] = 'page-id-' . $page_id;
+
+ if ( get_pages( array( 'parent' => $page_id, 'number' => 1 ) ) ) {
+ $classes[] = 'page-parent';
+ }
+
+ if ( $post->post_parent ) {
+ $classes[] = 'page-child';
+ $classes[] = 'parent-pageid-' . $post->post_parent;
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> } elseif ( is_archive() ) {
</span><span class="cx" style="display: block; padding: 0 10px"> if ( is_post_type_archive() ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -671,36 +705,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $classes[] = 'term-' . $term->term_id;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- } elseif ( is_page() ) {
- $classes[] = 'page';
-
- $page_id = $wp_query->get_queried_object_id();
-
- $post = get_post($page_id);
-
- $classes[] = 'page-id-' . $page_id;
-
- if ( get_pages( array( 'parent' => $page_id, 'number' => 1 ) ) ) {
- $classes[] = 'page-parent';
- }
-
- if ( $post->post_parent ) {
- $classes[] = 'page-child';
- $classes[] = 'parent-pageid-' . $post->post_parent;
- }
- if ( is_page_template() ) {
- $classes[] = 'page-template';
-
- $template_slug = get_page_template_slug( $page_id );
- $template_parts = explode( '/', $template_slug );
-
- foreach ( $template_parts as $part ) {
- $classes[] = 'page-template-' . sanitize_html_class( str_replace( array( '.', '/' ), '-', basename( $part, '.php' ) ) );
- }
- $classes[] = 'page-template-' . sanitize_html_class( str_replace( '.', '-', $template_slug ) );
- } else {
- $classes[] = 'page-template-default';
- }
</del><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( is_user_logged_in() )
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1621,14 +1625,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 2.5.0
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 4.2.0 The `$template` parameter was changed to also accept an array of page templates.
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 4.7.0 Now works with any post type, not just pages.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string|array $template The specific template name or array of templates to match.
</span><span class="cx" style="display: block; padding: 0 10px"> * @return bool True on success, false on failure.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function is_page_template( $template = '' ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ! is_page() )
- return false;
-
</del><span class="cx" style="display: block; padding: 0 10px"> $page_template = get_page_template_slug( get_queried_object_id() );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( empty( $template ) )
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1649,21 +1651,28 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Get the specific template name for a page.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Get the specific template name for a given post.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 3.4.0
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 4.7.0 Now works with any post type, not just pages.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param int $post_id Optional. The page ID to check. Defaults to the current post, when used in the loop.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
</ins><span class="cx" style="display: block; padding: 0 10px"> * @return string|false Page template filename. Returns an empty string when the default page template
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * is in use. Returns false if the post is not a page.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * is in use. Returns false if the post does not exist.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-function get_page_template_slug( $post_id = null ) {
- $post = get_post( $post_id );
- if ( ! $post || 'page' != $post->post_type )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+function get_page_template_slug( $post = null ) {
+ $post = get_post( $post );
+
+ if ( ! $post ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> return false;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> $template = get_post_meta( $post->ID, '_wp_page_template', true );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ! $template || 'default' == $template )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ if ( ! $template || 'default' == $template ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> return '';
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> return $template;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span></span></pre></div>
<a id="trunksrcwpincludespostphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/post.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/post.php 2016-10-26 07:51:41 UTC (rev 38950)
+++ trunk/src/wp-includes/post.php 2016-10-26 08:06:43 UTC (rev 38951)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -66,6 +66,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'add_new' => _x( 'Add New', 'add new media' ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'edit_item' => __( 'Edit Media' ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'view_item' => __( 'View Attachment Page' ),
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'attributes' => __( 'Attachment Attributes' ),
</ins><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'public' => true,
</span><span class="cx" style="display: block; padding: 0 10px"> 'show_ui' => true,
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1326,6 +1327,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * post types. Default is 'Parent Page:'.
</span><span class="cx" style="display: block; padding: 0 10px"> * - `all_items` - Label to signify all items in a submenu link. Default is 'All Posts' / 'All Pages'.
</span><span class="cx" style="display: block; padding: 0 10px"> * - `archives` - Label for archives in nav menus. Default is 'Post Archives' / 'Page Archives'.
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * - `attributes` - Label for the attributes meta box. Default is 'Post Attributes' / 'Page Attributes'.
</ins><span class="cx" style="display: block; padding: 0 10px"> * - `insert_into_item` - Label for the media frame button. Default is 'Insert into post' / 'Insert into page'.
</span><span class="cx" style="display: block; padding: 0 10px"> * - `uploaded_to_this_item` - Label for the media frame filter. Default is 'Uploaded to this post' /
</span><span class="cx" style="display: block; padding: 0 10px"> * 'Uploaded to this page'.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1351,7 +1353,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 4.4.0 Added the `insert_into_item`, `uploaded_to_this_item`, `filter_items_list`,
</span><span class="cx" style="display: block; padding: 0 10px"> * `items_list_navigation`, and `items_list` labels.
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 4.6.0 Converted the `$post_type` parameter to accept a WP_Post_Type object.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @since 4.7.0 Added the `view_items` label.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 4.7.0 Added the `view_items` and `attributes` labels.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @access private
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1374,6 +1376,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'parent_item_colon' => array( null, __('Parent Page:') ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'all_items' => array( __( 'All Posts' ), __( 'All Pages' ) ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'archives' => array( __( 'Post Archives' ), __( 'Page Archives' ) ),
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'attributes' => array( __( 'Post Attributes' ), __( 'Page Attributes' ) ),
</ins><span class="cx" style="display: block; padding: 0 10px"> 'insert_into_item' => array( __( 'Insert into post' ), __( 'Insert into page' ) ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'uploaded_to_this_item' => array( __( 'Uploaded to this post' ), __( 'Uploaded to this page' ) ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'featured_image' => array( __( 'Featured Image' ), __( 'Featured Image' ) ),
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3393,7 +3396,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $post = get_post( $post_ID );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ! empty( $postarr['page_template'] ) && 'page' == $data['post_type'] ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! empty( $postarr['page_template'] ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $post->page_template = $postarr['page_template'];
</span><span class="cx" style="display: block; padding: 0 10px"> $page_templates = wp_get_theme()->get_page_templates( $post );
</span><span class="cx" style="display: block; padding: 0 10px"> if ( 'default' != $postarr['page_template'] && ! isset( $page_templates[ $postarr['page_template'] ] ) ) {
</span></span></pre></div>
<a id="trunksrcwpincludestemplatephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/template.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/template.php 2016-10-26 07:51:41 UTC (rev 38950)
+++ trunk/src/wp-includes/template.php 2016-10-26 08:06:43 UTC (rev 38951)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -449,15 +449,17 @@
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * The hierarchy for this template looks like:
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * 1. single-{post_type}-{post_name}.php
- * 2. single-{post_type}.php
- * 3. single.php
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * 1. {Post Type Template}.php
+ * 2. single-{post_type}-{post_name}.php
+ * 3. single-{post_type}.php
+ * 4. single.php
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * An example of this is:
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * 1. single-post-hello-world.php
- * 2. single-post.php
- * 3. single.php
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * 1. templates/full-width.php
+ * 2. single-post-hello-world.php
+ * 3. single-post.php
+ * 4. single.php
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * The template hierarchy is filterable via the {@see 'single_template_hierarchy'} hook.
</span><span class="cx" style="display: block; padding: 0 10px"> * The template path is filterable via the {@see 'single_template'} hook.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -466,6 +468,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 4.4.0 `single-{post_type}-{post_name}.php` was added to the top of the template hierarchy.
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 4.7.0 The decoded form of `single-{post_type}-{post_name}.php` was added to the top of the
</span><span class="cx" style="display: block; padding: 0 10px"> * template hierarchy when the post name contains multibyte characters.
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 4.7.0 {Post Type Template}.php was added to the top of the template hierarchy.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @see get_query_template()
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -477,6 +480,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $templates = array();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! empty( $object->post_type ) ) {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $template = get_page_template_slug( $object );
+ if ( $template && 0 === validate_file( $template ) ) {
+ $templates[] = $template;
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $name_decoded = urldecode( $object->post_name );
</span><span class="cx" style="display: block; padding: 0 10px"> if ( $name_decoded !== $object->post_name ) {
</span></span></pre></div>
<a id="trunktestsphpunitdatathemedir1pagetemplatessubdirtemplatesubdirposttypesphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: trunk/tests/phpunit/data/themedir1/page-templates/subdir/template-sub-dir-post-types.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/data/themedir1/page-templates/subdir/template-sub-dir-post-types.php (rev 0)
+++ trunk/tests/phpunit/data/themedir1/page-templates/subdir/template-sub-dir-post-types.php 2016-10-26 08:06:43 UTC (rev 38951)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,5 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+/*
+ Template Name: Sub Dir
+ Template Post Type: foo, post
+ */
</ins></span></pre></div>
<a id="trunktestsphpunitdatathemedir1pagetemplatestemplatetoplevelposttypesphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: trunk/tests/phpunit/data/themedir1/page-templates/template-top-level-post-types.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/data/themedir1/page-templates/template-top-level-post-types.php (rev 0)
+++ trunk/tests/phpunit/data/themedir1/page-templates/template-top-level-post-types.php 2016-10-26 08:06:43 UTC (rev 38951)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,5 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+/*
+ Template Name: Top Level
+ Template Post Type: foo, post
+ */
</ins></span></pre></div>
<a id="trunktestsphpunittestsadminincludesThemephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/admin/includesTheme.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/admin/includesTheme.php 2016-10-26 07:51:41 UTC (rev 38950)
+++ trunk/tests/phpunit/tests/admin/includesTheme.php 2016-10-26 08:06:43 UTC (rev 38951)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -48,21 +48,41 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> switch_theme( $theme['Template'], $theme['Stylesheet'] );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $templates = get_page_templates();
- $this->assertCount( 3, $templates );
- $this->assertEquals( "template-top-level.php", $templates['Top Level'] );
- $this->assertEquals( "subdir/template-sub-dir.php", $templates['Sub Dir'] );
- $this->assertEquals( "template-header.php", $templates['This Template Header Is On One Line'] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $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() );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $theme = wp_get_theme( 'page-templates' );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertNotEmpty( $theme );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> switch_theme( $theme['Template'], $theme['Stylesheet'] );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $templates = get_page_templates();
- $this->assertCount( 3, $templates );
- $this->assertEquals( "template-top-level.php", $templates['Top Level'] );
- $this->assertEquals( "subdir/template-sub-dir.php", $templates['Sub Dir'] );
- $this->assertEquals( "template-header.php", $templates['This Template Header Is On One Line'] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $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() );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ /**
+ * @ticket 18375
+ */
+ function test_page_templates_different_post_types() {
+ $theme = wp_get_theme( 'page-templates' );
+ $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->assertEquals( array(), get_page_templates( null, 'bar' ) );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="trunktestsphpunittestspostgetBodyClassphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/post/getBodyClass.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/post/getBodyClass.php 2016-10-26 07:51:41 UTC (rev 38950)
+++ trunk/tests/phpunit/tests/post/getBodyClass.php 2016-10-26 08:06:43 UTC (rev 38951)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -92,4 +92,70 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertContains( "single-format-standard", $class );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function test_page_template_body_classes_no_template() {
+ $post_id = self::factory()->post->create( array(
+ 'post_type' => 'page',
+ ) );
+ $this->go_to( get_permalink( $post_id ) );
+
+ $class = get_body_class();
+
+ $this->assertNotContains( 'page-template', $class );
+ $this->assertContains( 'page-template-default', $class );
+ }
+
+ public function test_page_template_body_classes() {
+ $post_id = self::factory()->post->create( array(
+ 'post_type' => 'page',
+ ) );
+
+ add_post_meta( $post_id, '_wp_page_template', 'templates/cpt.php' );
+
+ $this->go_to( get_permalink( $post_id ) );
+
+ $class = get_body_class();
+
+ $this->assertContains( 'page-template', $class );
+ $this->assertContains( 'page-template-templates', $class );
+ $this->assertContains( 'page-template-cpt', $class );
+ $this->assertContains( 'page-template-templatescpt-php', $class );
+ }
+
+ /**
+ * @ticket 18375
+ */
+ public function test_page_template_body_classes_attachment() {
+ $post_id = self::factory()->post->create( array(
+ 'post_type' => 'attachment',
+ ) );
+
+ add_post_meta( $post_id, '_wp_page_template', 'templates/cpt.php' );
+
+ $this->go_to( get_permalink( $post_id ) );
+
+ $class = get_body_class();
+
+ $this->assertContains( 'attachment-template', $class );
+ $this->assertContains( 'attachment-template-templates', $class );
+ $this->assertContains( 'attachment-template-cpt', $class );
+ $this->assertContains( 'attachment-template-templatescpt-php', $class );
+ }
+
+ /**
+ * @ticket 18375
+ */
+ public function test_page_template_body_classes_post() {
+ $post_id = self::factory()->post->create();
+
+ add_post_meta( $post_id, '_wp_page_template', 'templates/cpt.php' );
+
+ $this->go_to( get_permalink( $post_id ) );
+
+ $class = get_body_class();
+
+ $this->assertContains( 'post-template', $class );
+ $this->assertContains( 'post-template-templates', $class );
+ $this->assertContains( 'post-template-cpt', $class );
+ $this->assertContains( 'post-template-templatescpt-php', $class );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="trunktestsphpunittestspostobjectsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/post/objects.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/post/objects.php 2016-10-26 07:51:41 UTC (rev 38950)
+++ trunk/tests/phpunit/tests/post/objects.php 2016-10-26 08:06:43 UTC (rev 38951)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -145,12 +145,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> update_post_meta( $post_id, '_wp_page_template', 'foo.php' );
</span><span class="cx" style="display: block; padding: 0 10px"> $template = get_post_meta( $post->ID, '_wp_page_template', true );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( 'foo.php', $template );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // The post is not a page so the template is still empty
- $this->assertEquals( '', $post->page_template );
-
- // Now the post is a page and should retrieve the template
- wp_update_post( array( 'ID' => $post->ID, 'post_type' => 'page' ) );
- $post = get_post( $post_id );
</del><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( $template, $post->page_template );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span></span></pre></div>
<a id="trunktestsphpunittestsposttemplatephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/post/template.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/post/template.php 2016-10-26 07:51:41 UTC (rev 38950)
+++ trunk/tests/phpunit/tests/post/template.php 2016-10-26 08:06:43 UTC (rev 38951)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -271,16 +271,32 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * @ticket 31389
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @ticket 18375
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_get_page_template_slug_non_page() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $post_id = self::factory()->post->create( array(
- 'post_type' => 'post',
- ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $post_id = self::factory()->post->create();
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->assertFalse( get_page_template_slug( $post_id ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->assertEquals( '', get_page_template_slug( $post_id ) );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ update_post_meta( $post_id, '_wp_page_template', 'default' );
+
+ $this->assertEquals( '', get_page_template_slug( $post_id ) );
+
+ update_post_meta( $post_id, '_wp_page_template', 'example.php' );
+ $this->assertEquals( 'example.php', get_page_template_slug( $post_id ) );
+ }
+
+ /**
+ * @ticket 18375
+ */
+ public function test_get_page_template_slug_non_page_from_loop() {
+ $post_id = self::factory()->post->create();
+
+ update_post_meta( $post_id, '_wp_page_template', 'example.php' );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> $this->go_to( get_permalink( $post_id ) );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->assertFalse( get_page_template_slug() );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ $this->assertEquals( 'example.php', get_page_template_slug() );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span></span></pre></div>
<a id="trunktestsphpunittestsqueryconditionalsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/query/conditionals.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/query/conditionals.php 2016-10-26 07:51:41 UTC (rev 38950)
+++ trunk/tests/phpunit/tests/query/conditionals.php 2016-10-26 08:06:43 UTC (rev 38951)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1044,6 +1044,17 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @ticket 18375
+ */
+ function test_is_page_template_other_post_type() {
+ $post_id = self::factory()->post->create( array( 'post_type' => 'post' ) );
+ update_post_meta( $post_id, '_wp_page_template', 'example.php' );
+ $this->go_to( get_post_permalink( $post_id ) );
+ $this->assertFalse( is_page_template( array( 'test.php' ) ) );
+ $this->assertTrue( is_page_template( array( 'test.php', 'example.php' ) ) );
+ }
+
+ /**
</ins><span class="cx" style="display: block; padding: 0 10px"> * @ticket 35902
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_is_attachment_should_not_match_numeric_id_to_post_title_beginning_with_id() {
</span></span></pre></div>
<a id="trunktestsphpunitteststemplatephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/template.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/template.php 2016-10-26 07:51:41 UTC (rev 38950)
+++ trunk/tests/phpunit/tests/template.php 2016-10-26 08:06:43 UTC (rev 38951)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -36,6 +36,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'post_date' => '1984-02-25 12:34:56',
</span><span class="cx" style="display: block; padding: 0 10px"> ) );
</span><span class="cx" style="display: block; padding: 0 10px"> set_post_format( self::$post, 'quote' );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ add_post_meta( self::$post->ID, '_wp_page_template', 'templates/post.php' );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> public function setUp() {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -203,8 +204,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> ) );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * @ticket 18375
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> public function test_single_template_hierarchy_for_post() {
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertTemplateHierarchy( get_permalink( self::$post ), array(
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'templates/post.php',
</ins><span class="cx" style="display: block; padding: 0 10px"> 'single-post-post-name-😀.php',
</span><span class="cx" style="display: block; padding: 0 10px"> 'single-post-post-name-%f0%9f%98%80.php',
</span><span class="cx" style="display: block; padding: 0 10px"> 'single-post.php',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -228,6 +233,26 @@
</span><span class="cx" style="display: block; padding: 0 10px"> ) );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * @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',
+ ) );
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> public function test_attachment_template_hierarchy() {
</span><span class="cx" style="display: block; padding: 0 10px"> $attachment = self::factory()->attachment->create_and_get( array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'post_name' => 'attachment-name-😀',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -247,11 +272,37 @@
</span><span class="cx" style="display: block; padding: 0 10px"> ) );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * @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',
+ ) );
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> public function test_embed_template_hierarchy_for_post() {
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertTemplateHierarchy( get_post_embed_url( self::$post ), array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'embed-post-quote.php',
</span><span class="cx" style="display: block; padding: 0 10px"> 'embed-post.php',
</span><span class="cx" style="display: block; padding: 0 10px"> 'embed.php',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'templates/post.php',
</ins><span class="cx" style="display: block; padding: 0 10px"> 'single-post-post-name-😀.php',
</span><span class="cx" style="display: block; padding: 0 10px"> 'single-post-post-name-%f0%9f%98%80.php',
</span><span class="cx" style="display: block; padding: 0 10px"> 'single-post.php',
</span></span></pre>
</div>
</div>
</body>
</html>