WordPress.org

Make WordPress Core

Ticket #11703: 11703.3.diff

File 11703.3.diff, 9.2 KB (added by dd32, 4 years ago)
  • wp-admin/edit-form-advanced.php

     
    135135if ( $authors && count( $authors ) > 1 ) 
    136136        add_meta_box('authordiv', __('Author'), 'post_author_meta_box', $post_type, 'normal', 'core'); 
    137137 
    138 if ( 0 < $post_ID && wp_get_post_revisions( $post_ID ) ) 
     138if ( post_type_supports($post_type, 'revisions') && 0 < $post_ID && wp_get_post_revisions( $post_ID ) ) 
    139139        add_meta_box('revisionsdiv', __('Revisions'), 'post_revisions_meta_box', $post_type, 'normal', 'core'); 
    140140 
    141141do_action('do_meta_boxes', $post_type, 'normal', $post); 
  • wp-admin/revision.php

     
    1111 
    1212wp_enqueue_script('list-revisions'); 
    1313 
    14 wp_reset_vars(array('revision', 'left', 'right', 'diff', 'action')); 
     14wp_reset_vars(array('revision', 'left', 'right', 'diff', 'action', 'post_type')); 
     15 
     16if ( empty($post_type) ) 
     17        $post_type = 'post'; 
     18 
     19if ( 'post' != $post_type ) 
     20        $parent_file = $submenu_file = $redirect = "edit.php?post_type=$post_type"; 
     21else 
     22        $parent_file = $submenu_file = $redirect = 'edit.php'; 
     23 
    1524$revision_id = absint($revision); 
    1625$diff        = absint($diff); 
    1726$left        = absint($left); 
    1827$right       = absint($right); 
    1928 
    20 $parent_file = $redirect = 'edit.php'; 
    21  
    2229switch ( $action ) : 
    2330case 'delete' : // stubs 
    2431case 'edit' : 
     
    115122        if ( !constant('WP_POST_REVISIONS') && !wp_is_post_autosave( $revision ) ) // Revisions disabled and we're not looking at an autosave 
    116123                break; 
    117124 
     125        $post_type_object = get_post_type_object($post->post_type); 
     126 
    118127        $post_title = '<a href="' . get_edit_post_link() . '">' . get_the_title() . '</a>'; 
    119128        $revision_title = wp_post_revision_title( $revision, false ); 
    120         $h2 = sprintf( __( 'Post Revision for &#8220;%1$s&#8221; created on %2$s' ), $post_title, $revision_title ); 
     129        $h2 = sprintf( __( '%s Revision for &#8220;%1$s&#8221; created on %2$s' ), $post_type_object->label, $post_title, $revision_title ); // @TODO singular? for post_type 
     130        $title = sprintf(__( '%s Revisions' ), $post_type_object->label );  // @TODO singular? for post_type 
    121131 
    122132        // Sets up the diff radio buttons 
    123133        $left  = $revision->ID; 
     
    127137        break; 
    128138endswitch; 
    129139 
    130 if ( !$redirect && !in_array( $post->post_type, array( 'post', 'page' ) ) ) 
    131         $redirect = 'edit.php'; 
     140if ( !$redirect && !post_type_supports($post_type, 'revisions') ) 
     141        $redirect = "edit.php?post_type=$post_type"; 
    132142 
    133143if ( $redirect ) { 
    134144        wp_redirect( $redirect ); 
    135145        exit; 
    136146} 
    137147 
    138 if ( 'page' == $post->post_type ) { 
    139         $submenu_file = 'edit-pages.php'; 
    140         $title = __( 'Page Revisions' ); 
    141 } else { 
    142         $submenu_file = 'edit.php'; 
    143         $title = __( 'Post Revisions' ); 
    144 } 
    145  
    146148require_once( 'admin-header.php' ); 
    147149 
    148150?> 
  • wp-includes/link-template.php

     
    689689        if ( !current_user_can( $post_type_object->edit_cap, $post->ID ) ) 
    690690                return; 
    691691 
    692         return apply_filters( 'get_edit_post_link', admin_url( sprintf($post_type_object->_edit_link . $action, $post->ID) ), $post->ID, $context ); 
     692        if ( 'revision' == $post->post_type && $revision_parent = get_post($post->post_parent) ) { 
     693                $url = admin_url( sprintf($post_type_object->_edit_link . $action, $revision_parent->post_type, $post->ID) ); 
     694        } else { 
     695                $url = admin_url( sprintf($post_type_object->_edit_link . $action, $post->ID) ); 
     696        } 
     697 
     698        return apply_filters( 'get_edit_post_link', $url, $post->ID, $context ); 
    693699} 
    694700 
    695701/** 
  • wp-includes/post-template.php

     
    12601260        extract( wp_parse_args( $args, $defaults ), EXTR_SKIP ); 
    12611261 
    12621262        switch ( $type ) { 
    1263         case 'autosave' : 
    1264                 if ( !$autosave = wp_get_post_autosave( $post->ID ) ) 
    1265                         return; 
    1266                 $revisions = array( $autosave ); 
    1267                 break; 
    1268         case 'revision' : // just revisions - remove autosave later 
    1269         case 'all' : 
    1270         default : 
    1271                 if ( !$revisions = wp_get_post_revisions( $post->ID ) ) 
    1272                         return; 
    1273                 break; 
     1263                case 'autosave' : 
     1264                        if ( !$autosave = wp_get_post_autosave( $post->ID ) ) 
     1265                                return; 
     1266                        $revisions = array( $autosave ); 
     1267                        break; 
     1268                case 'revision' : // just revisions - remove autosave later 
     1269                case 'all' : 
     1270                default : 
     1271                        if ( !$revisions = wp_get_post_revisions( $post->ID ) ) 
     1272                                return; 
     1273                        break; 
    12741274        } 
    12751275 
    12761276        /* translators: post revision: 1: when, 2: author name */ 
     
    13261326        <div class="alignleft"> 
    13271327                <input type="submit" class="button-secondary" value="<?php esc_attr_e( 'Compare Revisions' ); ?>" /> 
    13281328                <input type="hidden" name="action" value="diff" /> 
     1329                <input type="hidden" name="post_type" value="<?php echo esc_attr($GLOBALS['post_type']); ?>" /> 
    13291330        </div> 
    13301331</div> 
    13311332 
  • wp-includes/post.php

     
    1515 * Creates the initial post types when 'init' action is fired. 
    1616 */ 
    1717function create_initial_post_types() { 
    18         register_post_type( 'post', array('label' => __('Posts'), 'exclude_from_search' => false, '_builtin' => true, '_edit_link' => 'post.php?post=%d', 'capability_type' => 'post', 'hierarchical' => false) ); 
    19         register_post_type( 'page', array('label' => __('Pages'),'exclude_from_search' => false, '_builtin' => true, '_edit_link' => 'post.php?post=%d', 'capability_type' => 'page', 'hierarchical' => true) ); 
    20         register_post_type( 'attachment', array('label' => __('Media'), 'exclude_from_search' => false, '_builtin' => true, '_edit_link' => 'media.php?attachment_id=%d', 'capability_type' => 'post', 'hierarchical' => false) ); 
    21         register_post_type( 'revision', array('label' => __('Revisions'),'exclude_from_search' => true, '_builtin' => true, '_edit_link' => 'revision.php?revision=%d', 'capability_type' => 'post', 'hierarchical' => false) ); 
    22         add_post_type_support('post', array('post-thumbnails', 'excerpts', 'trackbacks', 'custom-fields', 'comments') ); 
    23         add_post_type_support('page', array('post-thumbnails', 'page-attributes', 'custom-fields', 'comments') ); 
     18        register_post_type( 'post', array('label' => __('Posts'), 'exclude_from_search' => false, '_builtin' => true, '_edit_link' => 'post.php?post=%d', 'capability_type' => 'post', 'hierarchical' => false, 'supports' => array('post-thumbnails', 'excerpts', 'trackbacks', 'custom-fields', 'comments', 'revisions') ) ); 
     19        register_post_type( 'page', array('label' => __('Pages'), 'exclude_from_search' => false, '_builtin' => true, '_edit_link' => 'post.php?post=%d', 'capability_type' => 'page', 'hierarchical' => true, 'supports' => array('post-thumbnails', 'page-attributes', 'custom-fields', 'comments', 'revisions')) ); 
     20        register_post_type( 'attachment', array('label' => __('Media'), 'exclude_from_search' => false, '_builtin' => true, '_edit_link' => 'media.php?attachment_id=%d', 'capability_type' => 'post', 'hierarchical' => false ) ); 
     21        register_post_type( 'revision', array('label' => __('Revisions'),'exclude_from_search' => true, '_builtin' => true, '_edit_link' => 'revision.php?post_type=%s&revision=%d', 'capability_type' => 'post', 'hierarchical' => false) ); 
    2422 
    2523        register_post_status( 'publish', array('label' => _x('Published', 'post'), 'exclude_from_search' => false, '_builtin' => true, 'label_count' => _n_noop('Published <span class="count">(%s)</span>', 'Published <span class="count">(%s)</span>')) ); 
    2624        register_post_status( 'future', array('label' => _x('Scheduled', 'post'), 'exclude_from_search' => false, '_builtin' => true, 'label_count' => _n_noop('Scheduled <span class="count">(%s)</span>', 'Scheduled <span class="count">(%s)</span>')) ); 
     
    655653                $wp_post_types = array(); 
    656654 
    657655        // Args prefixed with an underscore are reserved for internal use. 
    658         $defaults = array('label' => false, 'exclude_from_search' => true, '_builtin' => false, '_edit_link' => 'post.php?post=%d', 'capability_type' => 'post', 'hierarchical' => false, 'public' => false, '_show' => false); 
     656        $defaults = array('label' => false, 'exclude_from_search' => true, '_builtin' => false, '_edit_link' => 'post.php?post=%d', 'capability_type' => 'post', 'hierarchical' => false, 'public' => false, '_show' => false, 'supports' => array()); 
    659657        $args = wp_parse_args($args, $defaults); 
    660658        $args = (object) $args; 
    661659 
     
    676674        if ( !$args->_builtin && $args->public ) 
    677675                $args->_show = true; 
    678676 
     677        if ( ! empty($args->supports) ) { 
     678                add_post_type_support($post_type, $args->supports); 
     679                unset($args->supports); 
     680        } 
     681 
    679682        $wp_post_types[$post_type] = $args; 
    680683 
    681684        return $args; 
     
    39403943        if ( !$post = get_post( $post_id, ARRAY_A ) ) 
    39413944                return; 
    39423945 
    3943         if ( !in_array( $post['post_type'], array( 'post', 'page' ) ) ) 
     3946        if ( !post_type_supports($post['post_type'], 'revisions') ) 
    39443947                return; 
    39453948 
    39463949        $return = _wp_put_post_revision( $post );