Ticket #18375: 18375.2.patch
File 18375.2.patch, 11.5 KB (added by , 9 years ago) |
---|
-
src/wp-admin/edit-form-advanced.php
259 259 add_meta_box( $tax_meta_box_id, $label, $taxonomy->meta_box_cb, null, 'side', 'core', array( 'taxonomy' => $tax_name ) ); 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 add_meta_box('pageparentdiv', 'page' == $post_type ? __('Page Attributes') : __('Attributes'), 'page_attributes_meta_box', null, 'side', 'core'); 264 263 265 264 if ( $thumbnail_support && current_user_can( 'upload_files' ) ) 266 265 add_meta_box('postimagediv', esc_html( $post_type_object->labels->featured_image ), 'post_thumbnail_meta_box', null, 'side', 'low'); -
src/wp-admin/includes/meta-boxes.php
785 785 * @param object $post 786 786 */ 787 787 function page_attributes_meta_box($post) { 788 if ( post_type_supports($post->post_type, 'page-attributes') ) { 788 789 $post_type_object = get_post_type_object($post->post_type); 789 790 if ( $post_type_object->hierarchical ) { 790 791 $dropdown_args = array( … … 817 818 <?php 818 819 } // end empty pages check 819 820 } // end hierarchical check. 820 if ( 'page' == $post->post_type && 0 != count( get_page_templates( $post ) ) && get_option( 'page_for_posts' ) != $post->ID ) { 821 } 822 if ( 0 != count( get_page_templates( $post ) ) ) { 821 823 $template = !empty($post->page_template) ? $post->page_template : false; 822 824 ?> 823 825 <p><strong><?php _e('Template') ?></strong><?php … … 832 834 */ 833 835 do_action( 'page_attributes_meta_box_template', $template, $post ); 834 836 ?></p> 835 <label class="screen-reader-text" for="page_template"><?php _e(' PageTemplate') ?></label><select name="page_template" id="page_template">837 <label class="screen-reader-text" for="page_template"><?php _e('Template') ?></label><select name="page_template" id="page_template"> 836 838 <?php 837 839 /** 838 840 * Filters the title of the default page template displayed in the drop-down. … … 846 848 $default_title = apply_filters( 'default_page_template_title', __( 'Default Template' ), 'meta-box' ); 847 849 ?> 848 850 <option value="default"><?php echo esc_html( $default_title ); ?></option> 849 <?php p age_template_dropdown($template); ?>851 <?php post_type_template_dropdown($template, $post->post_type); ?> 850 852 </select> 851 853 <?php 852 } ?> 854 } 855 if ( post_type_supports($post->post_type, 'page-attributes') ) {?> 853 856 <p><strong><?php _e('Order') ?></strong></p> 854 857 <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> 855 <?php if ( 'page' == $post->post_type && get_current_screen()->get_help_tabs() ) { ?>858 <?php if ( 'page' == $post->post_type && get_current_screen()->get_help_tabs() ) { ?> 856 859 <p><?php _e( 'Need help? Use the Help tab above the screen title.' ); ?></p> 857 860 <?php 861 } 858 862 } 859 863 } 860 864 -
src/wp-admin/includes/template.php
296 296 if ( $post_type_object->hierarchical ) 297 297 echo '<div class="post_parent">' . $post->post_parent . '</div>'; 298 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>'; 299 echo '<div class="page_template">' . esc_html( get_post_meta( $post->ID, '_wp_page_template', true ) ) . '</div>'; 301 300 302 301 if ( post_type_supports( $post->post_type, 'page-attributes' ) ) 303 302 echo '<div class="menu_order">' . $post->menu_order . '</div>'; … … 758 757 } 759 758 760 759 /** 761 * Print out option HTML elements for the page templates drop-down.760 * Display dropdown options for template files from the active theme 762 761 * 763 * @since 1.5.0762 * @since 4.8.0 764 763 * 765 764 * @param string $default Optional. The template file name. Default empty. 765 * @param string $post_type Post type 766 766 */ 767 function p age_template_dropdown( $default = '' ) {768 $templates = get_p age_templates( get_post());767 function post_type_template_dropdown( $default = '', $post_type = 'page' ) { 768 $templates = get_post_type_templates( null, $post_type ); 769 769 ksort( $templates ); 770 770 foreach ( array_keys( $templates ) as $template ) { 771 771 $selected = selected( $default, $templates[ $template ], false ); … … 774 774 } 775 775 776 776 /** 777 * Print out option HTML elements for the page templates drop-down. 778 * 779 * @since 1.5.0 780 * 781 * @param string $default Optional. The template file name. Default empty. 782 */ 783 function page_template_dropdown( $default = '' ) { 784 post_type_template_dropdown( $default, 'page' ); 785 } 786 787 /** 777 788 * Print out option HTML elements for the page parents drop-down. 778 789 * 779 790 * @since 1.5.0 -
src/wp-admin/includes/theme.php
99 99 } 100 100 101 101 /** 102 * Get the Templates available in this theme 103 * 104 * @since 4.8.0 105 * 106 * @param WP_Post|null $post Optional. The post being edited, provided for context. 107 * @param string $post_type Optional. The post type templates to find 108 * @return array Key is the template name, value is the filename of the template 109 */ 110 function get_post_type_templates( $post = null, $post_type = null ) { 111 return array_flip( wp_get_theme()->get_post_templates( $post, $post_type ) ); 112 } 113 114 /** 102 115 * Get the Page Templates available in this theme 103 116 * 104 117 * @since 1.5.0 … … 107 120 * @return array Key is the template name, value is the filename of the template 108 121 */ 109 122 function get_page_templates( $post = null ) { 110 return array_flip( wp_get_theme()->get_p age_templates( $post) );123 return array_flip( wp_get_theme()->get_post_templates( $post, 'page' ) ); 111 124 } 112 125 113 126 /** -
src/wp-includes/class-wp-theme.php
1014 1014 * @return array Array of page templates, keyed by filename, with the value of the translated header name. 1015 1015 */ 1016 1016 public function get_page_templates( $post = null ) { 1017 return (array) apply_filters( 'theme_page_templates', $this->get_post_templates($post, 'page'), $this, $post ); 1018 } 1019 1020 /** 1021 * Returns the theme's post type templates. 1022 * 1023 * @since 4.8.0 1024 * @access public 1025 * 1026 * @param WP_Post|null $post Optional. The post being edited, provided for context. 1027 * @param string $post_type Optional. The post type templates to find 1028 * @return array Array of page templates, keyed by filename, with the value of the translated header name. 1029 */ 1030 public function get_post_templates( $post = null, $post_type = 'page' ) { 1017 1031 // If you screw up your current theme and we invalidate your parent, most things still work. Let it slide. 1018 1032 if ( $this->errors() && $this->errors()->get_error_codes() !== array( 'theme_parent_invalid' ) ) 1019 1033 return array(); 1020 1034 1021 $p age_templates = $this->cache_get( 'page_templates' );1035 $post_templates = $this->cache_get( 'post_templates' ); 1022 1036 1023 if ( ! is_array( $p age_templates ) ) {1024 $p age_templates = array();1037 if ( ! is_array( $post_templates ) ) { 1038 $post_templates = array(); 1025 1039 1026 1040 $files = (array) $this->get_files( 'php', 1 ); 1027 1041 … … 1028 1042 foreach ( $files as $file => $full_path ) { 1029 1043 if ( ! preg_match( '|Template Name:(.*)$|mi', file_get_contents( $full_path ), $header ) ) 1030 1044 continue; 1031 $page_templates[ $file ] = _cleanup_header_comment( $header[1] ); 1045 $post_templates[ $file ] = _cleanup_header_comment( $header[1] ); 1046 if ( preg_match( '|Template Type:(.*)$|mi', file_get_contents( $full_path ), $type ) ) { 1047 $types = explode( ',', _cleanup_header_comment( $type[1] ) ); 1048 } else { 1049 $types = array( 'page' ); 1050 } 1051 foreach ( $types as $type ) { 1052 $type = trim( $type ); 1053 if ( !isset( $post_templates[$type] ) ) { 1054 $post_templates[$type] = array(); 1055 $post_templates[$type][$file] = _cleanup_header_comment( $header[1] ); 1056 } 1057 } 1032 1058 } 1033 1059 1034 $this->cache_add( 'p age_templates', $page_templates );1060 $this->cache_add( 'post_templates', $post_templates ); 1035 1061 } 1036 1062 1037 1063 if ( $this->load_textdomain() ) { 1038 foreach ( $p age_templates as &$page_template ) {1039 $p age_template = $this->translate_header( 'Template Name', $page_template);1064 foreach ( $post_templates as &$post_template ) { 1065 $post_templates = $this->translate_header( 'Template Name', $post_template[$post_type] ); 1040 1066 } 1041 1067 } 1042 1068 1043 1069 if ( $this->parent() ) 1044 $p age_templates += $this->parent()->get_page_templates( $post);1070 $post_templates += $this->parent()->get_post_templates( $post, $post_type ); 1045 1071 1046 1072 /** 1047 1073 * Filters list of page templates for a theme. … … 1054 1080 * @param WP_Theme $this The theme object. 1055 1081 * @param WP_Post|null $post The post being edited, provided for context, or null. 1056 1082 */ 1057 return (array) apply_filters( 'theme_p age_templates', $page_templates, $this, $post );1083 return (array) apply_filters( 'theme_post_templates', $post_templates[$post_type], $this, $post ); 1058 1084 } 1059 1085 1060 1086 /** -
src/wp-includes/post-template.php
1580 1580 * @return bool True on success, false on failure. 1581 1581 */ 1582 1582 function is_page_template( $template = '' ) { 1583 if ( ! is_page() )1584 return false;1585 1586 1583 $page_template = get_page_template_slug( get_queried_object_id() ); 1587 1584 1588 1585 if ( empty( $template ) ) -
src/wp-includes/post.php
3307 3307 3308 3308 $post = get_post( $post_ID ); 3309 3309 3310 if ( ! empty( $postarr['page_template'] ) && 'page' == $data['post_type']) {3310 if ( ! empty( $postarr['page_template'] ) ) { 3311 3311 $post->page_template = $postarr['page_template']; 3312 $page_templates = wp_get_theme()->get_p age_templates( $post);3312 $page_templates = wp_get_theme()->get_post_templates( $post->post_type ); 3313 3313 if ( 'default' != $postarr['page_template'] && ! isset( $page_templates[ $postarr['page_template'] ] ) ) { 3314 3314 if ( $wp_error ) { 3315 3315 return new WP_Error('invalid_page_template', __('The page template is invalid.')); -
src/wp-includes/template.php
391 391 */ 392 392 function get_single_template() { 393 393 $object = get_queried_object(); 394 $template = get_post_meta( $object->ID, '_wp_page_template', true ); 395 396 if ( 'default' === $template ) 397 $template = ''; 394 398 395 399 $templates = array(); 396 400 401 if ( !empty($template) && !validate_file($template) ) { 402 $templates[] = $template; 403 } 404 397 405 if ( ! empty( $object->post_type ) ) { 398 406 $templates[] = "single-{$object->post_type}-{$object->post_name}.php"; 399 407 $templates[] = "single-{$object->post_type}.php";