Make WordPress Core

Ticket #11049: preview_template.diff

File preview_template.diff, 2.1 KB (added by Nano8Blazex, 14 years ago)

patch -> for Google Code In

  • wp-includes/post.php

     
    25922592
    25932593        $post = get_post($post_ID);
    25942594
    2595         if ( !empty($page_template) && 'page' == $data['post_type'] ) {
     2595        if ( !empty($page_template) && (('page' == $data['post_type']) || ('revision' == $data['post_type'])) ) {
    25962596                $post->page_template = $page_template;
    25972597                $page_templates = get_page_templates();
    25982598                if ( 'default' != $page_template && !in_array($page_template, $page_templates) ) {
     
    26012601                        else
    26022602                                return 0;
    26032603                }
    2604                 update_post_meta($post_ID, '_wp_page_template',  $page_template);
     2604                if ( 'page' == $data['post_type'] ) {
     2605                        update_post_meta($post_ID, '_wp_page_template',  $page_template);
     2606                } elseif ('revision' == $data['post_type'] ) {
     2607                        //update the meta for autosave, page preview
     2608                        update_post_meta($post_ID, '_wp_preview_page_template',  $page_template);
     2609                }
    26052610        }
    26062611
    26072612        wp_transition_post_status($data['post_status'], $previous_status, $post);
     
    46294634        $return['post_name']     = $autosave ? "$post[ID]-autosave" : "$post[ID]-revision";
    46304635        $return['post_date']     = isset($post['post_modified']) ? $post['post_modified'] : '';
    46314636        $return['post_date_gmt'] = isset($post['post_modified_gmt']) ? $post['post_modified_gmt'] : '';
     4637       
     4638        if ( $autosave ) {
     4639                $return['page_template'] = isset($post['page_template']) ? $post['page_template'] : 'default';
     4640        }
    46324641
    46334642        return $return;
    46344643}
  • wp-includes/theme.php

     
    946946 */
    947947function get_page_template() {
    948948        $id = get_queried_object_id();
    949         $template = get_post_meta($id, '_wp_page_template', true);
     949        if ( is_preview() ) { //a page preview may have a different template than the published page
     950                $template = get_post_meta($id, '_wp_preview_page_template', true);
     951        } else {
     952                $template = get_post_meta($id, '_wp_page_template', true);
     953        }
    950954        $pagename = get_query_var('pagename');
    951955
    952956        if ( !$pagename && $id > 0 ) {