Changeset 38951
- Timestamp:
- 10/26/2016 08:06:43 AM (8 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/edit-form-advanced.php
r38725 r38951 260 260 } 261 261 262 if ( post_type_supports($post_type, 'page-attributes') ) 263 add_meta_box('pageparentdiv', 'page' == $post_type ? __('Page Attributes') : __('Attributes'), 'page_attributes_meta_box', null, 'side', 'core'); 262 if ( post_type_supports( $post_type, 'page-attributes' ) || count( get_page_templates( null, $post_type ) ) > 0 ) { 263 add_meta_box( 'pageparentdiv', $post_type_object->labels->attributes, 'page_attributes_meta_box', null, 'side', 'core' ); 264 } 264 265 265 266 if ( $thumbnail_support && current_user_can( 'upload_files' ) ) -
trunk/src/wp-admin/includes/class-wp-posts-list-table.php
r38854 r38951 1529 1529 </label> 1530 1530 1531 <?php endif; // !$bulk1532 1533 if ( 'page' === $screen->post_type ) :1534 ?>1535 1536 <label>1537 <span class="title"><?php _e( 'Template' ); ?></span>1538 <select name="page_template">1539 <?php if ( $bulk ) : ?>1540 <option value="-1"><?php _e( '— No Change —' ); ?></option>1541 <?php endif; // $bulk ?>1542 <?php1543 /** This filter is documented in wp-admin/includes/meta-boxes.php */1544 $default_title = apply_filters( 'default_page_template_title', __( 'Default Template' ), 'quick-edit' );1545 ?>1546 <option value="default"><?php echo esc_html( $default_title ); ?></option>1547 <?php page_template_dropdown() ?>1548 </select>1549 </label>1550 1551 1531 <?php 1552 endif; // page post_type1532 endif; // !$bulk 1553 1533 endif; // page-attributes 1554 1534 ?> 1535 1536 <?php if ( 0 < count( get_page_templates( null, $screen->post_type ) ) ) : ?> 1537 <label> 1538 <span class="title"><?php _e( 'Template' ); ?></span> 1539 <select name="page_template"> 1540 <?php if ( $bulk ) : ?> 1541 <option value="-1"><?php _e( '— No Change —' ); ?></option> 1542 <?php endif; // $bulk ?> 1543 <?php 1544 /** This filter is documented in wp-admin/includes/meta-boxes.php */ 1545 $default_title = apply_filters( 'default_page_template_title', __( 'Default Template' ), 'quick-edit' ); 1546 ?> 1547 <option value="default"><?php echo esc_html( $default_title ); ?></option> 1548 <?php page_template_dropdown( $post->page_template, $screen->post_type ) ?> 1549 </select> 1550 </label> 1551 <?php endif; ?> 1555 1552 1556 1553 <?php if ( count( $flat_taxonomies ) && !$bulk ) : ?> -
trunk/src/wp-admin/includes/meta-boxes.php
r38880 r38951 789 789 */ 790 790 function page_attributes_meta_box($post) { 791 $post_type_object = get_post_type_object($post->post_type); 792 if ( $post_type_object->hierarchical ) { 791 if ( is_post_type_hierarchical( $post->post_type ) ) : 793 792 $dropdown_args = array( 794 793 'post_type' => $post->post_type, … … 813 812 $dropdown_args = apply_filters( 'page_attributes_dropdown_pages_args', $dropdown_args, $post ); 814 813 $pages = wp_dropdown_pages( $dropdown_args ); 815 if ( ! empty($pages) ) {814 if ( ! empty($pages) ) : 816 815 ?> 817 816 <p><strong><?php _e('Parent') ?></strong></p> … … 819 818 <?php echo $pages; ?> 820 819 <?php 821 } // end empty pages check 822 } // end hierarchical check. 823 if ( 'page' == $post->post_type && 0 != count( get_page_templates( $post ) ) && get_option( 'page_for_posts' ) != $post->ID ) { 824 $template = !empty($post->page_template) ? $post->page_template : false; 820 endif; // end empty pages check 821 endif; // end hierarchical check. 822 823 if ( count( get_page_templates( $post ) ) > 0 && get_option( 'page_for_posts' ) != $post->ID ) : 824 $template = ! empty( $post->page_template ) ? $post->page_template : false; 825 825 ?> 826 826 <p><strong><?php _e('Template') ?></strong><?php … … 836 836 do_action( 'page_attributes_meta_box_template', $template, $post ); 837 837 ?></p> 838 <label class="screen-reader-text" for="page_template"><?php _e('Page Template') ?></label><select name="page_template" id="page_template"> 838 <label class="screen-reader-text" for="page_template"> 839 <?php 840 $post_type_object = get_post_type_object( $post->post_type ); 841 echo esc_html( $post_type_object->labels->attributes ); 842 ?> 843 </label> 844 <select name="page_template" id="page_template"> 839 845 <?php 840 846 /** … … 850 856 ?> 851 857 <option value="default"><?php echo esc_html( $default_title ); ?></option> 852 <?php page_template_dropdown( $template); ?>858 <?php page_template_dropdown( $template, $post->post_type ); ?> 853 859 </select> 854 <?php 855 }?>860 <?php endif; ?> 861 <?php if ( post_type_supports( $post->post_type, 'page-attributes' ) ) : ?> 856 862 <p><strong><?php _e('Order') ?></strong></p> 857 863 <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> 858 <?php if ( 'page' == $post->post_type && get_current_screen()->get_help_tabs() ) {?>864 <?php if ( 'page' == $post->post_type && get_current_screen()->get_help_tabs() ) : ?> 859 865 <p><?php _e( 'Need help? Use the Help tab above the screen title.' ); ?></p> 860 <?php 861 }866 <?php endif; 867 endif; 862 868 } 863 869 -
trunk/src/wp-admin/includes/template.php
r38831 r38951 294 294 <div class="post_password">' . esc_html( $post->post_password ) . '</div>'; 295 295 296 if ( $post_type_object->hierarchical ) 296 if ( $post_type_object->hierarchical ) { 297 297 echo '<div class="post_parent">' . $post->post_parent . '</div>'; 298 299 if ( $post->post_type == 'page' ) 300 echo '<div class="page_template">' . esc_html( get_post_meta( $post->ID, '_wp_page_template', true )) . '</div>';301 302 if ( post_type_supports( $post->post_type, 'page-attributes' ) ) 298 } 299 300 echo '<div class="page_template">' . esc_html( $post->page_template ) . '</div>'; 301 302 if ( post_type_supports( $post->post_type, 'page-attributes' ) ) { 303 303 echo '<div class="menu_order">' . $post->menu_order . '</div>'; 304 } 304 305 305 306 $taxonomy_names = get_object_taxonomies( $post->post_type ); … … 762 763 * 763 764 * @since 1.5.0 764 * 765 * @param string $default Optional. The template file name. Default empty. 766 */ 767 function page_template_dropdown( $default = '' ) { 768 $templates = get_page_templates( get_post() ); 765 * @since 4.7.0 Added the `$post_type` parameter. 766 * 767 * @param string $default Optional. The template file name. Default empty. 768 * @param string $post_type Optional. Post type to get templates for. Default 'post'. 769 */ 770 function page_template_dropdown( $default = '', $post_type = 'page' ) { 771 $templates = get_page_templates( null, $post_type ); 769 772 ksort( $templates ); 770 773 foreach ( array_keys( $templates ) as $template ) { -
trunk/src/wp-admin/includes/theme.php
r38813 r38951 103 103 * 104 104 * @since 1.5.0 105 * 106 * @param WP_Post|null $post Optional. The post being edited, provided for context. 105 * @since 4.7.0 Added the `$post_type` parameter. 106 * 107 * @param WP_Post|null $post Optional. The post being edited, provided for context. 108 * @param string $post_type Optional. Post type to get the templates for. Default 'page'. 107 109 * @return array Key is the template name, value is the filename of the template 108 110 */ 109 function get_page_templates( $post = null ) {110 return array_flip( wp_get_theme()->get_page_templates( $post ) );111 function get_page_templates( $post = null, $post_type = 'page' ) { 112 return array_flip( wp_get_theme()->get_page_templates( $post, $post_type ) ); 111 113 } 112 114 -
trunk/src/wp-includes/class-wp-post.php
r38381 r38951 255 255 256 256 if ( 'page_template' == $key ) 257 return ( 'page' == $this->post_type );257 return true; 258 258 259 259 if ( 'post_category' == $key ) -
trunk/src/wp-includes/class-wp-theme.php
r38839 r38951 539 539 * @access private 540 540 * 541 * @param string $key Type of data to store (theme, screenshot, headers, p age_templates)541 * @param string $key Type of data to store (theme, screenshot, headers, post_templates) 542 542 * @param string $data Data to store 543 543 * @return bool Return value from wp_cache_add() … … 555 555 * @access private 556 556 * 557 * @param string $key Type of data to retrieve (theme, screenshot, headers, p age_templates)557 * @param string $key Type of data to retrieve (theme, screenshot, headers, post_templates) 558 558 * @return mixed Retrieved data 559 559 */ … … 569 569 */ 570 570 public function cache_delete() { 571 foreach ( array( 'theme', 'screenshot', 'headers', 'p age_templates' ) as $key )571 foreach ( array( 'theme', 'screenshot', 'headers', 'post_templates' ) as $key ) 572 572 wp_cache_delete( $key . '-' . $this->cache_hash, 'themes' ); 573 573 $this->template = $this->textdomain_loaded = $this->theme_root_uri = $this->parent = $this->errors = $this->headers_sanitized = $this->name_translated = null; … … 1007 1007 1008 1008 /** 1009 * Returns the theme's page templates. 1010 * 1011 * @since 3.4.0 1012 * @access public 1013 * 1014 * @param WP_Post|null $post Optional. The post being edited, provided for context. 1009 * Returns the theme's post templates. 1010 * 1011 * @since 4.7.0 1012 * @access public 1013 * 1014 * @return array Array of page templates, keyed by filename and post type, 1015 * with the value of the translated header name. 1016 */ 1017 public function get_post_templates() { 1018 // If you screw up your current theme and we invalidate your parent, most things still work. Let it slide. 1019 if ( $this->errors() && $this->errors()->get_error_codes() !== array( 'theme_parent_invalid' ) ) { 1020 return array(); 1021 } 1022 1023 $post_templates = $this->cache_get( 'post_templates' ); 1024 1025 if ( ! is_array( $post_templates ) ) { 1026 $post_templates = array(); 1027 1028 $files = (array) $this->get_files( 'php', 1 ); 1029 1030 foreach ( $files as $file => $full_path ) { 1031 if ( ! preg_match( '|Template Name:(.*)$|mi', file_get_contents( $full_path ), $header ) ) { 1032 continue; 1033 } 1034 1035 $types = array( 'page' ); 1036 if ( preg_match( '|Template Post Type:(.*)$|mi', file_get_contents( $full_path ), $type ) ) { 1037 $types = explode( ',', _cleanup_header_comment( $type[1] ) ); 1038 } 1039 1040 foreach ( $types as $type ) { 1041 $type = trim( $type ); 1042 if ( ! isset( $post_templates[ $type ] ) ) { 1043 $post_templates[ $type ] = array(); 1044 } 1045 1046 $post_templates[ $type ][ $file ] = _cleanup_header_comment( $header[1] ); 1047 } 1048 } 1049 1050 $this->cache_add( 'post_templates', $post_templates ); 1051 } 1052 1053 if ( $this->load_textdomain() ) { 1054 foreach ( $post_templates as &$post_type ) { 1055 foreach ( $post_type as &$post_template ) { 1056 $post_template = $this->translate_header( 'Template Name', $post_template ); 1057 } 1058 } 1059 } 1060 1061 return $post_templates; 1062 } 1063 1064 /** 1065 * Returns the theme's post templates for a given post type. 1066 * 1067 * @since 3.4.0 1068 * @since 4.7.0 Added the `$post_type` parameter. 1069 * @access public 1070 * 1071 * @param WP_Post|null $post Optional. The post being edited, provided for context. 1072 * @param string $post_type Optional. Post type to get the templates for. Default 'page'. 1073 * If a post is provided, its post type is used. 1015 1074 * @return array Array of page templates, keyed by filename, with the value of the translated header name. 1016 1075 */ 1017 public function get_page_templates( $post = null ) { 1018 // If you screw up your current theme and we invalidate your parent, most things still work. Let it slide. 1019 if ( $this->errors() && $this->errors()->get_error_codes() !== array( 'theme_parent_invalid' ) ) 1020 return array(); 1021 1022 $page_templates = $this->cache_get( 'page_templates' ); 1023 1024 if ( ! is_array( $page_templates ) ) { 1025 $page_templates = array(); 1026 1027 $files = (array) $this->get_files( 'php', 1 ); 1028 1029 foreach ( $files as $file => $full_path ) { 1030 if ( ! preg_match( '|Template Name:(.*)$|mi', file_get_contents( $full_path ), $header ) ) 1031 continue; 1032 $page_templates[ $file ] = _cleanup_header_comment( $header[1] ); 1033 } 1034 1035 $this->cache_add( 'page_templates', $page_templates ); 1036 } 1037 1038 if ( $this->load_textdomain() ) { 1039 foreach ( $page_templates as &$page_template ) { 1040 $page_template = $this->translate_header( 'Template Name', $page_template ); 1041 } 1042 } 1043 1044 if ( $this->parent() ) 1045 $page_templates += $this->parent()->get_page_templates( $post ); 1076 public function get_page_templates( $post = null, $post_type = 'page' ) { 1077 if ( $post ) { 1078 $post_type = get_post_type( $post ); 1079 } 1080 1081 $post_templates = $this->get_post_templates(); 1082 $post_templates = isset( $post_templates[ $post_type ] ) ? $post_templates[ $post_type ] : array(); 1083 1084 if ( $this->parent() ) { 1085 $post_templates += $this->parent()->get_page_templates( $post ); 1086 } 1046 1087 1047 1088 /** 1048 1089 * Filters list of page templates for a theme. 1049 1090 * 1091 * The dynamic portion of the hook name, `$post_type`, refers to the post type. 1092 * 1050 1093 * @since 3.9.0 1051 1094 * @since 4.4.0 Converted to allow complete control over the `$page_templates` array. 1095 * @since 4.7.0 Added the `$post_type` parameter. 1052 1096 * 1053 * @param array $p age_templates Array of page templates. Keys are filenames,1097 * @param array $post_templates Array of page templates. Keys are filenames, 1054 1098 * values are translated names. 1055 1099 * @param WP_Theme $this The theme object. 1056 1100 * @param WP_Post|null $post The post being edited, provided for context, or null. 1101 * @param string $post_type Post type to get the templates for. 1057 1102 */ 1058 return (array) apply_filters( 'theme_page_templates', $page_templates, $this, $post);1103 return (array) apply_filters( "theme_{$post_type}_templates", $post_templates, $this, $post, $post_type ); 1059 1104 } 1060 1105 -
trunk/src/wp-includes/post-template.php
r38798 r38951 595 595 $classes[] = 'error404'; 596 596 597 if ( is_sing le() ) {597 if ( is_singular() ) { 598 598 $post_id = $wp_query->get_queried_object_id(); 599 599 $post = $wp_query->get_queried_object(); 600 601 $classes[] = 'single'; 602 if ( isset( $post->post_type ) ) { 603 $classes[] = 'single-' . sanitize_html_class($post->post_type, $post_id); 604 $classes[] = 'postid-' . $post_id; 605 606 // Post Format 607 if ( post_type_supports( $post->post_type, 'post-formats' ) ) { 608 $post_format = get_post_format( $post->ID ); 609 610 if ( $post_format && !is_wp_error($post_format) ) 611 $classes[] = 'single-format-' . sanitize_html_class( $post_format ); 612 else 613 $classes[] = 'single-format-standard'; 600 $post_type = $post->post_type; 601 602 if ( is_page_template() ) { 603 $classes[] = "{$post_type}-template"; 604 605 $template_slug = get_page_template_slug( $post_id ); 606 $template_parts = explode( '/', $template_slug ); 607 608 foreach ( $template_parts as $part ) { 609 $classes[] = "{$post_type}-template-" . sanitize_html_class( str_replace( array( '.', '/' ), '-', basename( $part, '.php' ) ) ); 610 } 611 $classes[] = "{$post_type}-template-" . sanitize_html_class( str_replace( '.', '-', $template_slug ) ); 612 } else { 613 $classes[] = "{$post_type}-template-default"; 614 } 615 616 if ( is_single() ) { 617 $classes[] = 'single'; 618 if ( isset( $post->post_type ) ) { 619 $classes[] = 'single-' . sanitize_html_class( $post->post_type, $post_id ); 620 $classes[] = 'postid-' . $post_id; 621 622 // Post Format 623 if ( post_type_supports( $post->post_type, 'post-formats' ) ) { 624 $post_format = get_post_format( $post->ID ); 625 626 if ( $post_format && !is_wp_error($post_format) ) 627 $classes[] = 'single-format-' . sanitize_html_class( $post_format ); 628 else 629 $classes[] = 'single-format-standard'; 630 } 614 631 } 615 632 } … … 620 637 $classes[] = 'attachmentid-' . $post_id; 621 638 $classes[] = 'attachment-' . str_replace( $mime_prefix, '', $mime_type ); 639 } elseif ( is_page() ) { 640 $classes[] = 'page'; 641 642 $page_id = $wp_query->get_queried_object_id(); 643 644 $post = get_post($page_id); 645 646 $classes[] = 'page-id-' . $page_id; 647 648 if ( get_pages( array( 'parent' => $page_id, 'number' => 1 ) ) ) { 649 $classes[] = 'page-parent'; 650 } 651 652 if ( $post->post_parent ) { 653 $classes[] = 'page-child'; 654 $classes[] = 'parent-pageid-' . $post->post_parent; 655 } 622 656 } 623 657 } elseif ( is_archive() ) { … … 671 705 $classes[] = 'term-' . $term->term_id; 672 706 } 673 }674 } elseif ( is_page() ) {675 $classes[] = 'page';676 677 $page_id = $wp_query->get_queried_object_id();678 679 $post = get_post($page_id);680 681 $classes[] = 'page-id-' . $page_id;682 683 if ( get_pages( array( 'parent' => $page_id, 'number' => 1 ) ) ) {684 $classes[] = 'page-parent';685 }686 687 if ( $post->post_parent ) {688 $classes[] = 'page-child';689 $classes[] = 'parent-pageid-' . $post->post_parent;690 }691 if ( is_page_template() ) {692 $classes[] = 'page-template';693 694 $template_slug = get_page_template_slug( $page_id );695 $template_parts = explode( '/', $template_slug );696 697 foreach ( $template_parts as $part ) {698 $classes[] = 'page-template-' . sanitize_html_class( str_replace( array( '.', '/' ), '-', basename( $part, '.php' ) ) );699 }700 $classes[] = 'page-template-' . sanitize_html_class( str_replace( '.', '-', $template_slug ) );701 } else {702 $classes[] = 'page-template-default';703 707 } 704 708 } … … 1622 1626 * @since 2.5.0 1623 1627 * @since 4.2.0 The `$template` parameter was changed to also accept an array of page templates. 1628 * @since 4.7.0 Now works with any post type, not just pages. 1624 1629 * 1625 1630 * @param string|array $template The specific template name or array of templates to match. … … 1627 1632 */ 1628 1633 function is_page_template( $template = '' ) { 1629 if ( ! is_page() )1630 return false;1631 1632 1634 $page_template = get_page_template_slug( get_queried_object_id() ); 1633 1635 … … 1650 1652 1651 1653 /** 1652 * Get the specific template name for a page.1654 * Get the specific template name for a given post. 1653 1655 * 1654 1656 * @since 3.4.0 1655 * 1656 * @param int $post_id Optional. The page ID to check. Defaults to the current post, when used in the loop. 1657 * @since 4.7.0 Now works with any post type, not just pages. 1658 * 1659 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post. 1657 1660 * @return string|false Page template filename. Returns an empty string when the default page template 1658 * is in use. Returns false if the post is not a page. 1659 */ 1660 function get_page_template_slug( $post_id = null ) { 1661 $post = get_post( $post_id ); 1662 if ( ! $post || 'page' != $post->post_type ) 1661 * is in use. Returns false if the post does not exist. 1662 */ 1663 function get_page_template_slug( $post = null ) { 1664 $post = get_post( $post ); 1665 1666 if ( ! $post ) { 1663 1667 return false; 1668 } 1669 1664 1670 $template = get_post_meta( $post->ID, '_wp_page_template', true ); 1665 if ( ! $template || 'default' == $template ) 1671 1672 if ( ! $template || 'default' == $template ) { 1666 1673 return ''; 1674 } 1675 1667 1676 return $template; 1668 1677 } -
trunk/src/wp-includes/post.php
r38925 r38951 67 67 'edit_item' => __( 'Edit Media' ), 68 68 'view_item' => __( 'View Attachment Page' ), 69 'attributes' => __( 'Attachment Attributes' ), 69 70 ), 70 71 'public' => true, … … 1327 1328 * - `all_items` - Label to signify all items in a submenu link. Default is 'All Posts' / 'All Pages'. 1328 1329 * - `archives` - Label for archives in nav menus. Default is 'Post Archives' / 'Page Archives'. 1330 * - `attributes` - Label for the attributes meta box. Default is 'Post Attributes' / 'Page Attributes'. 1329 1331 * - `insert_into_item` - Label for the media frame button. Default is 'Insert into post' / 'Insert into page'. 1330 1332 * - `uploaded_to_this_item` - Label for the media frame filter. Default is 'Uploaded to this post' / … … 1352 1354 * `items_list_navigation`, and `items_list` labels. 1353 1355 * @since 4.6.0 Converted the `$post_type` parameter to accept a WP_Post_Type object. 1354 * @since 4.7.0 Added the `view_items` label.1356 * @since 4.7.0 Added the `view_items` and `attributes` labels. 1355 1357 * 1356 1358 * @access private … … 1375 1377 'all_items' => array( __( 'All Posts' ), __( 'All Pages' ) ), 1376 1378 'archives' => array( __( 'Post Archives' ), __( 'Page Archives' ) ), 1379 'attributes' => array( __( 'Post Attributes' ), __( 'Page Attributes' ) ), 1377 1380 'insert_into_item' => array( __( 'Insert into post' ), __( 'Insert into page' ) ), 1378 1381 'uploaded_to_this_item' => array( __( 'Uploaded to this post' ), __( 'Uploaded to this page' ) ), … … 3394 3397 $post = get_post( $post_ID ); 3395 3398 3396 if ( ! empty( $postarr['page_template'] ) && 'page' == $data['post_type']) {3399 if ( ! empty( $postarr['page_template'] ) ) { 3397 3400 $post->page_template = $postarr['page_template']; 3398 3401 $page_templates = wp_get_theme()->get_page_templates( $post ); -
trunk/src/wp-includes/template.php
r38789 r38951 450 450 * The hierarchy for this template looks like: 451 451 * 452 * 1. single-{post_type}-{post_name}.php 453 * 2. single-{post_type}.php 454 * 3. single.php 455 * 456 * An example of this is: 457 * 458 * 1. single-post-hello-world.php 459 * 2. single-post.php 460 * 3. single.php 452 * 1. {Post Type Template}.php 453 * 2. single-{post_type}-{post_name}.php 454 * 3. single-{post_type}.php 455 * 4. single.php 456 * 457 * An example of this is: 458 * 459 * 1. templates/full-width.php 460 * 2. single-post-hello-world.php 461 * 3. single-post.php 462 * 4. single.php 461 463 * 462 464 * The template hierarchy is filterable via the {@see 'single_template_hierarchy'} hook. … … 467 469 * @since 4.7.0 The decoded form of `single-{post_type}-{post_name}.php` was added to the top of the 468 470 * template hierarchy when the post name contains multibyte characters. 471 * @since 4.7.0 {Post Type Template}.php was added to the top of the template hierarchy. 469 472 * 470 473 * @see get_query_template() … … 478 481 479 482 if ( ! empty( $object->post_type ) ) { 483 $template = get_page_template_slug( $object ); 484 if ( $template && 0 === validate_file( $template ) ) { 485 $templates[] = $template; 486 } 480 487 481 488 $name_decoded = urldecode( $object->post_name ); -
trunk/tests/phpunit/tests/admin/includesTheme.php
r25409 r38951 49 49 switch_theme( $theme['Template'], $theme['Stylesheet'] ); 50 50 51 $t emplates = get_page_templates();52 $this->assertCount( 3, $templates );53 $this->assertEquals( "template-top-level.php", $templates['Top Level'] );54 $this->assertEquals( "subdir/template-sub-dir.php", $templates['Sub Dir'] );55 $this->assertEquals( "template-header.php", $templates['This Template Header Is On One Line']);51 $this->assertEqualSetsWithIndex( array( 52 'Top Level' => 'template-top-level.php', 53 'Sub Dir' => 'subdir/template-sub-dir.php', 54 'This Template Header Is On One Line' => 'template-header.php', 55 ), get_page_templates() ); 56 56 57 57 $theme = wp_get_theme( 'page-templates' ); … … 60 60 switch_theme( $theme['Template'], $theme['Stylesheet'] ); 61 61 62 $templates = get_page_templates(); 63 $this->assertCount( 3, $templates ); 64 $this->assertEquals( "template-top-level.php", $templates['Top Level'] ); 65 $this->assertEquals( "subdir/template-sub-dir.php", $templates['Sub Dir'] ); 66 $this->assertEquals( "template-header.php", $templates['This Template Header Is On One Line'] ); 62 $this->assertEqualSetsWithIndex( array( 63 'Top Level' => 'template-top-level.php', 64 'Sub Dir' => 'subdir/template-sub-dir.php', 65 'This Template Header Is On One Line' => 'template-header.php', 66 ), get_page_templates() ); 67 } 68 69 /** 70 * @ticket 18375 71 */ 72 function test_page_templates_different_post_types() { 73 $theme = wp_get_theme( 'page-templates' ); 74 $this->assertNotEmpty( $theme ); 75 76 switch_theme( $theme['Template'], $theme['Stylesheet'] ); 77 78 $this->assertEqualSetsWithIndex( array( 79 'Top Level' => 'template-top-level-post-types.php', 80 'Sub Dir' => 'subdir/template-sub-dir-post-types.php', 81 ), get_page_templates( null, 'foo' ) ); 82 $this->assertEqualSetsWithIndex( array( 83 'Top Level' => 'template-top-level-post-types.php', 84 'Sub Dir' => 'subdir/template-sub-dir-post-types.php', 85 ), get_page_templates( null, 'post' ) ); 86 $this->assertEquals( array(), get_page_templates( null, 'bar' ) ); 67 87 } 68 88 } -
trunk/tests/phpunit/tests/post/getBodyClass.php
r37249 r38951 93 93 } 94 94 95 public function test_page_template_body_classes_no_template() { 96 $post_id = self::factory()->post->create( array( 97 'post_type' => 'page', 98 ) ); 99 $this->go_to( get_permalink( $post_id ) ); 100 101 $class = get_body_class(); 102 103 $this->assertNotContains( 'page-template', $class ); 104 $this->assertContains( 'page-template-default', $class ); 105 } 106 107 public function test_page_template_body_classes() { 108 $post_id = self::factory()->post->create( array( 109 'post_type' => 'page', 110 ) ); 111 112 add_post_meta( $post_id, '_wp_page_template', 'templates/cpt.php' ); 113 114 $this->go_to( get_permalink( $post_id ) ); 115 116 $class = get_body_class(); 117 118 $this->assertContains( 'page-template', $class ); 119 $this->assertContains( 'page-template-templates', $class ); 120 $this->assertContains( 'page-template-cpt', $class ); 121 $this->assertContains( 'page-template-templatescpt-php', $class ); 122 } 123 124 /** 125 * @ticket 18375 126 */ 127 public function test_page_template_body_classes_attachment() { 128 $post_id = self::factory()->post->create( array( 129 'post_type' => 'attachment', 130 ) ); 131 132 add_post_meta( $post_id, '_wp_page_template', 'templates/cpt.php' ); 133 134 $this->go_to( get_permalink( $post_id ) ); 135 136 $class = get_body_class(); 137 138 $this->assertContains( 'attachment-template', $class ); 139 $this->assertContains( 'attachment-template-templates', $class ); 140 $this->assertContains( 'attachment-template-cpt', $class ); 141 $this->assertContains( 'attachment-template-templatescpt-php', $class ); 142 } 143 144 /** 145 * @ticket 18375 146 */ 147 public function test_page_template_body_classes_post() { 148 $post_id = self::factory()->post->create(); 149 150 add_post_meta( $post_id, '_wp_page_template', 'templates/cpt.php' ); 151 152 $this->go_to( get_permalink( $post_id ) ); 153 154 $class = get_body_class(); 155 156 $this->assertContains( 'post-template', $class ); 157 $this->assertContains( 'post-template-templates', $class ); 158 $this->assertContains( 'post-template-cpt', $class ); 159 $this->assertContains( 'post-template-templatescpt-php', $class ); 160 } 95 161 } -
trunk/tests/phpunit/tests/post/objects.php
r35242 r38951 146 146 $template = get_post_meta( $post->ID, '_wp_page_template', true ); 147 147 $this->assertEquals( 'foo.php', $template ); 148 // The post is not a page so the template is still empty149 $this->assertEquals( '', $post->page_template );150 151 // Now the post is a page and should retrieve the template152 wp_update_post( array( 'ID' => $post->ID, 'post_type' => 'page' ) );153 $post = get_post( $post_id );154 148 $this->assertEquals( $template, $post->page_template ); 155 149 } -
trunk/tests/phpunit/tests/post/template.php
r38523 r38951 272 272 /** 273 273 * @ticket 31389 274 * @ticket 18375 274 275 */ 275 276 public function test_get_page_template_slug_non_page() { 276 $post_id = self::factory()->post->create( array( 277 'post_type' => 'post', 278 ) ); 279 280 $this->assertFalse( get_page_template_slug( $post_id ) ); 277 $post_id = self::factory()->post->create(); 278 279 $this->assertEquals( '', get_page_template_slug( $post_id ) ); 280 281 update_post_meta( $post_id, '_wp_page_template', 'default' ); 282 283 $this->assertEquals( '', get_page_template_slug( $post_id ) ); 284 285 update_post_meta( $post_id, '_wp_page_template', 'example.php' ); 286 $this->assertEquals( 'example.php', get_page_template_slug( $post_id ) ); 287 } 288 289 /** 290 * @ticket 18375 291 */ 292 public function test_get_page_template_slug_non_page_from_loop() { 293 $post_id = self::factory()->post->create(); 294 295 update_post_meta( $post_id, '_wp_page_template', 'example.php' ); 281 296 282 297 $this->go_to( get_permalink( $post_id ) ); 283 $this->assertFalse( get_page_template_slug() ); 298 299 $this->assertEquals( 'example.php', get_page_template_slug() ); 284 300 } 285 301 -
trunk/tests/phpunit/tests/query/conditionals.php
r38938 r38951 1045 1045 1046 1046 /** 1047 * @ticket 18375 1048 */ 1049 function test_is_page_template_other_post_type() { 1050 $post_id = self::factory()->post->create( array( 'post_type' => 'post' ) ); 1051 update_post_meta( $post_id, '_wp_page_template', 'example.php' ); 1052 $this->go_to( get_post_permalink( $post_id ) ); 1053 $this->assertFalse( is_page_template( array( 'test.php' ) ) ); 1054 $this->assertTrue( is_page_template( array( 'test.php', 'example.php' ) ) ); 1055 } 1056 1057 /** 1047 1058 * @ticket 35902 1048 1059 */ -
trunk/tests/phpunit/tests/template.php
r38583 r38951 37 37 ) ); 38 38 set_post_format( self::$post, 'quote' ); 39 add_post_meta( self::$post->ID, '_wp_page_template', 'templates/post.php' ); 39 40 } 40 41 … … 204 205 } 205 206 207 /** 208 * @ticket 18375 209 */ 206 210 public function test_single_template_hierarchy_for_post() { 207 211 $this->assertTemplateHierarchy( get_permalink( self::$post ), array( 212 'templates/post.php', 208 213 'single-post-post-name-😀.php', 209 214 'single-post-post-name-%f0%9f%98%80.php', … … 221 226 222 227 $this->assertTemplateHierarchy( get_permalink( $cpt ), array( 228 'single-cpt-cpt-name-😀.php', 229 'single-cpt-cpt-name-%f0%9f%98%80.php', 230 'single-cpt.php', 231 'single.php', 232 'singular.php', 233 ) ); 234 } 235 236 /** 237 * @ticket 18375 238 */ 239 public function test_single_template_hierarchy_for_custom_post_type_with_template() { 240 $cpt = self::factory()->post->create_and_get( array( 241 'post_type' => 'cpt', 242 'post_name' => 'cpt-name-😀', 243 ) ); 244 add_post_meta( $cpt->ID, '_wp_page_template', 'templates/cpt.php' ); 245 246 $this->assertTemplateHierarchy( get_permalink( $cpt ), array( 247 'templates/cpt.php', 223 248 'single-cpt-cpt-name-😀.php', 224 249 'single-cpt-cpt-name-%f0%9f%98%80.php', … … 248 273 } 249 274 275 /** 276 * @ticket 18375 277 */ 278 public function test_attachment_template_hierarchy_with_template() { 279 $attachment = self::factory()->attachment->create_and_get( array( 280 'post_name' => 'attachment-name-😀', 281 'file' => 'image.jpg', 282 'post_mime_type' => 'image/jpeg', 283 ) ); 284 285 add_post_meta( $attachment, '_wp_page_template', 'templates/cpt.php' ); 286 287 $this->assertTemplateHierarchy( get_permalink( $attachment ), array( 288 'image-jpeg.php', 289 'jpeg.php', 290 'image.php', 291 'attachment.php', 292 'single-attachment-attachment-name-😀.php', 293 'single-attachment-attachment-name-%f0%9f%98%80.php', 294 'single-attachment.php', 295 'single.php', 296 'singular.php', 297 ) ); 298 } 299 250 300 public function test_embed_template_hierarchy_for_post() { 251 301 $this->assertTemplateHierarchy( get_post_embed_url( self::$post ), array( … … 253 303 'embed-post.php', 254 304 'embed.php', 305 'templates/post.php', 255 306 'single-post-post-name-😀.php', 256 307 'single-post-post-name-%f0%9f%98%80.php',
Note: See TracChangeset
for help on using the changeset viewer.