WordPress.org

Make WordPress Core

Ticket #18375: 18375.2.patch

File 18375.2.patch, 11.5 KB (added by Mte90, 21 months ago)

new refreshed working version

  • src/wp-admin/edit-form-advanced.php

     
    259259        add_meta_box( $tax_meta_box_id, $label, $taxonomy->meta_box_cb, null, 'side', 'core', array( 'taxonomy' => $tax_name ) );
    260260}
    261261
    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');
     262add_meta_box('pageparentdiv', 'page' == $post_type ? __('Page Attributes') : __('Attributes'), 'page_attributes_meta_box', null, 'side', 'core');
    264263
    265264if ( $thumbnail_support && current_user_can( 'upload_files' ) )
    266265        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

     
    785785 * @param object $post
    786786 */
    787787function page_attributes_meta_box($post) {
     788  if ( post_type_supports($post->post_type, 'page-attributes') ) {
    788789        $post_type_object = get_post_type_object($post->post_type);
    789790        if ( $post_type_object->hierarchical ) {
    790791                $dropdown_args = array(
     
    817818<?php
    818819                } // end empty pages check
    819820        } // 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 ) ) ) {
    821823                $template = !empty($post->page_template) ? $post->page_template : false;
    822824                ?>
    823825<p><strong><?php _e('Template') ?></strong><?php
     
    832834         */
    833835        do_action( 'page_attributes_meta_box_template', $template, $post );
    834836?></p>
    835 <label class="screen-reader-text" for="page_template"><?php _e('Page Template') ?></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">
    836838<?php
    837839/**
    838840 * Filters the title of the default page template displayed in the drop-down.
     
    846848$default_title = apply_filters( 'default_page_template_title',  __( 'Default Template' ), 'meta-box' );
    847849?>
    848850<option value="default"><?php echo esc_html( $default_title ); ?></option>
    849 <?php page_template_dropdown($template); ?>
     851<?php post_type_template_dropdown($template, $post->post_type); ?>
    850852</select>
    851853<?php
    852         } ?>
     854        }
     855        if ( post_type_supports($post->post_type, 'page-attributes') ) {?>
    853856<p><strong><?php _e('Order') ?></strong></p>
    854857<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() ) { ?>
    856859<p><?php _e( 'Need help? Use the Help tab above the screen title.' ); ?></p>
    857860<?php
     861          }
    858862        }
    859863}
    860864
  • src/wp-admin/includes/template.php

     
    296296        if ( $post_type_object->hierarchical )
    297297                echo '<div class="post_parent">' . $post->post_parent . '</div>';
    298298
    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>';
    301300
    302301        if ( post_type_supports( $post->post_type, 'page-attributes' ) )
    303302                echo '<div class="menu_order">' . $post->menu_order . '</div>';
     
    758757}
    759758
    760759/**
    761  * Print out option HTML elements for the page templates drop-down.
     760 * Display dropdown options for template files from the active theme
    762761 *
    763  * @since 1.5.0
     762 * @since 4.8.0
    764763 *
    765764 * @param string $default Optional. The template file name. Default empty.
     765 * @param string $post_type Post type
    766766 */
    767 function page_template_dropdown( $default = '' ) {
    768         $templates = get_page_templates( get_post() );
     767function post_type_template_dropdown( $default = '', $post_type = 'page' ) {
     768        $templates = get_post_type_templates( null, $post_type );
    769769        ksort( $templates );
    770770        foreach ( array_keys( $templates ) as $template ) {
    771771                $selected = selected( $default, $templates[ $template ], false );
     
    774774}
    775775
    776776/**
     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 */
     783function page_template_dropdown( $default = '' ) {
     784        post_type_template_dropdown( $default, 'page' );
     785}
     786
     787/**
    777788 * Print out option HTML elements for the page parents drop-down.
    778789 *
    779790 * @since 1.5.0
  • src/wp-admin/includes/theme.php

     
    9999}
    100100
    101101/**
     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 */
     110function 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/**
    102115 * Get the Page Templates available in this theme
    103116 *
    104117 * @since 1.5.0
     
    107120 * @return array Key is the template name, value is the filename of the template
    108121 */
    109122function get_page_templates( $post = null ) {
    110         return array_flip( wp_get_theme()->get_page_templates( $post ) );
     123        return array_flip( wp_get_theme()->get_post_templates( $post, 'page' ) );
    111124}
    112125
    113126/**
  • src/wp-includes/class-wp-theme.php

     
    10141014         * @return array Array of page templates, keyed by filename, with the value of the translated header name.
    10151015         */
    10161016        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' ) {
    10171031                // If you screw up your current theme and we invalidate your parent, most things still work. Let it slide.
    10181032                if ( $this->errors() && $this->errors()->get_error_codes() !== array( 'theme_parent_invalid' ) )
    10191033                        return array();
    10201034
    1021                 $page_templates = $this->cache_get( 'page_templates' );
     1035                $post_templates = $this->cache_get( 'post_templates' );
    10221036
    1023                 if ( ! is_array( $page_templates ) ) {
    1024                         $page_templates = array();
     1037                if ( ! is_array( $post_templates ) ) {
     1038                        $post_templates = array();
    10251039
    10261040                        $files = (array) $this->get_files( 'php', 1 );
    10271041
     
    10281042                        foreach ( $files as $file => $full_path ) {
    10291043                                if ( ! preg_match( '|Template Name:(.*)$|mi', file_get_contents( $full_path ), $header ) )
    10301044                                        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                            }
    10321058                        }
    10331059
    1034                         $this->cache_add( 'page_templates', $page_templates );
     1060                        $this->cache_add( 'post_templates', $post_templates );
    10351061                }
    10361062
    10371063                if ( $this->load_textdomain() ) {
    1038                         foreach ( $page_templates as &$page_template ) {
    1039                                 $page_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] );
    10401066                        }
    10411067                }
    10421068
    10431069                if ( $this->parent() )
    1044                         $page_templates += $this->parent()->get_page_templates( $post );
     1070                        $post_templates += $this->parent()->get_post_templates( $post, $post_type );
    10451071
    10461072                /**
    10471073                 * Filters list of page templates for a theme.
     
    10541080                 * @param WP_Theme     $this           The theme object.
    10551081                 * @param WP_Post|null $post           The post being edited, provided for context, or null.
    10561082                 */
    1057                 return (array) apply_filters( 'theme_page_templates', $page_templates, $this, $post );
     1083                return (array) apply_filters( 'theme_post_templates', $post_templates[$post_type], $this, $post );
    10581084        }
    10591085
    10601086        /**
  • src/wp-includes/post-template.php

     
    15801580 * @return bool True on success, false on failure.
    15811581 */
    15821582function is_page_template( $template = '' ) {
    1583         if ( ! is_page() )
    1584                 return false;
    1585 
    15861583        $page_template = get_page_template_slug( get_queried_object_id() );
    15871584
    15881585        if ( empty( $template ) )
  • src/wp-includes/post.php

     
    33073307
    33083308        $post = get_post( $post_ID );
    33093309
    3310         if ( ! empty( $postarr['page_template'] ) && 'page' == $data['post_type'] ) {
     3310        if ( ! empty( $postarr['page_template'] ) ) {
    33113311                $post->page_template = $postarr['page_template'];
    3312                 $page_templates = wp_get_theme()->get_page_templates( $post );
     3312                $page_templates = wp_get_theme()->get_post_templates( $post->post_type );
    33133313                if ( 'default' != $postarr['page_template'] && ! isset( $page_templates[ $postarr['page_template'] ] ) ) {
    33143314                        if ( $wp_error ) {
    33153315                                return new WP_Error('invalid_page_template', __('The page template is invalid.'));
  • src/wp-includes/template.php

     
    391391 */
    392392function get_single_template() {
    393393        $object = get_queried_object();
     394        $template = get_post_meta( $object->ID, '_wp_page_template', true );
     395       
     396        if ( 'default' === $template )
     397              $template = '';
    394398
    395399        $templates = array();
    396 
     400       
     401        if ( !empty($template) && !validate_file($template) ) {
     402              $templates[] = $template;
     403        }
     404       
    397405        if ( ! empty( $object->post_type ) ) {
    398406                $templates[] = "single-{$object->post_type}-{$object->post_name}.php";
    399407                $templates[] = "single-{$object->post_type}.php";