Make WordPress Core

Changeset 12751


Ignore:
Timestamp:
01/18/2010 11:44:51 AM (17 years ago)
Author:
dd32
Message:

Introduce Revisioning for custom Post Types, Introduce 'supports' argument to register_post_type() to wrap add_post_type_support(), Whitespace additions to create_initial_post_types(). See #9674. Fixes #11703

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/edit-form-advanced.php

    r12728 r12751  
    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
  • trunk/wp-admin/revision.php

    r12500 r12751  
    1313
    1414wp_reset_vars(array('revision', 'left', 'right', 'diff', 'action'));
     15
    1516$revision_id = absint($revision);
    1617$diff        = absint($diff);
     
    1819$right       = absint($right);
    1920
    20 $parent_file = $redirect = 'edit.php';
     21$redirect = 'edit.php';
    2122
    2223switch ( $action ) :
    23 case 'delete' : // stubs
    24 case 'edit' :
    25         if ( constant('WP_POST_REVISIONS') ) // stub
    26                 $redirect = remove_query_arg( 'action' );
    27         else // Revisions disabled
    28                 $redirect = 'edit.php';
    29         break;
    3024case 'restore' :
    3125        if ( !$revision = wp_get_post_revision( $revision_id ) )
     
    116110                break;
    117111
     112        $post_type_object = get_post_type_object($post->post_type);
     113
    118114        $post_title = '<a href="' . get_edit_post_link() . '">' . get_the_title() . '</a>';
    119115        $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 );
     116        $h2 = sprintf( __( 'Revision for &#8220;%1$s&#8221; created on %2$s' ), $post_title, $revision_title );
     117        $title = __( 'Revisions' );
    121118
    122119        // Sets up the diff radio buttons
     
    128125endswitch;
    129126
    130 if ( !$redirect && !in_array( $post->post_type, array( 'post', 'page' ) ) )
    131         $redirect = 'edit.php';
    132 
    133 if ( $redirect ) {
     127if ( !$redirect ) {
     128        if ( empty($post->post_type) ) // Empty post_type means either malformed object found, or no valid parent was found.
     129                $redirect = 'edit.php';
     130        elseif ( !post_type_supports($post->post_type, 'revisions') )
     131                $redirect = 'edit.php?post_type=' . $post->post_type;
     132}
     133
     134if ( !empty($redirect) ) {
    134135        wp_redirect( $redirect );
    135136        exit;
    136137}
    137138
    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 }
     139// This is so that the correct "Edit" menu item is selected.
     140if ( !empty($post->post_type) && 'post' != $post->post_type )
     141        $parent_file = $submenu_file = 'edit.php?post_type=' . $post->post_type;
     142else
     143        $parent_file = $submenu_file = 'edit.php';
    145144
    146145require_once( 'admin-header.php' );
  • trunk/wp-includes/post-template.php

    r12680 r12751  
    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
     
    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>
  • trunk/wp-includes/post.php

    r12733 r12751  
    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') );
    24 
    25         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>')) );
    26         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>')) );
    27         register_post_status( 'draft', array('label' => _x('Draft', 'post'), 'exclude_from_search' => false, '_builtin' => true, 'label_count' => _n_noop('Draft <span class="count">(%s)</span>', 'Drafts <span class="count">(%s)</span>')) );
    28         register_post_status( 'private', array('label' => _x('Private', 'post'), 'exclude_from_search' => false, '_builtin' => true, 'label_count' => _n_noop('Private <span class="count">(%s)</span>', 'Private <span class="count">(%s)</span>')) );
    29         register_post_status( 'trash', array('label' => _x('Trash', 'post'), 'exclude_from_search' => false, '_builtin' => true, 'label_count' => _n_noop('Trash <span class="count">(%s)</span>', 'Trash <span class="count">(%s)</span>')) );
     18        register_post_type( 'post', array(      'label' => __('Posts'),
     19                                                                                'exclude_from_search' => false,
     20                                                                                '_builtin' => true,
     21                                                                                '_edit_link' => 'post.php?post=%d',
     22                                                                                'capability_type' => 'post',
     23                                                                                'hierarchical' => false,
     24                                                                                'supports' => array('post-thumbnails', 'excerpts', 'trackbacks', 'custom-fields', 'comments', 'revisions')
     25                                                                        ) );
     26
     27        register_post_type( 'page', array(      'label' => __('Pages'),
     28                                                                                'exclude_from_search' => false,
     29                                                                                '_builtin' => true,
     30                                                                                '_edit_link' => 'post.php?post=%d',
     31                                                                                'capability_type' => 'page',
     32                                                                                'hierarchical' => true,
     33                                                                                'supports' => array('post-thumbnails', 'page-attributes', 'custom-fields', 'comments', 'revisions')
     34                                                                        ) );
     35
     36        register_post_type( 'attachment', array('label' => __('Media'),
     37                                                                                        'exclude_from_search' => false,
     38                                                                                        '_builtin' => true,
     39                                                                                        '_edit_link' => 'media.php?attachment_id=%d',
     40                                                                                        'capability_type' => 'post',
     41                                                                                        'hierarchical' => false
     42                                                                                ) );
     43
     44        register_post_type( 'revision', array(  'label' => __('Revisions'),
     45                                                                                        'exclude_from_search' => true,
     46                                                                                        '_builtin' => true,
     47                                                                                        '_edit_link' => 'revision.php?revision=%d',
     48                                                                                        'capability_type' => 'post',
     49                                                                                        'hierarchical' => false
     50                                                                                ) );
     51
     52        register_post_status( 'publish', array( 'label' => _x('Published', 'post'),
     53                                                                                        'exclude_from_search' => false,
     54                                                                                        '_builtin' => true,
     55                                                                                        'label_count' => _n_noop('Published <span class="count">(%s)</span>', 'Published <span class="count">(%s)</span>')
     56                                                                                ) );
     57
     58        register_post_status( 'future', array(  'label' => _x('Scheduled', 'post'),
     59                                                                                        'exclude_from_search' => false,
     60                                                                                        '_builtin' => true,
     61                                                                                        'label_count' => _n_noop('Scheduled <span class="count">(%s)</span>', 'Scheduled <span class="count">(%s)</span>')
     62                                                                                ) );
     63
     64        register_post_status( 'draft', array(   'label' => _x('Draft', 'post'),
     65                                                                                        'exclude_from_search' => false,
     66                                                                                        '_builtin' => true,
     67                                                                                        'label_count' => _n_noop('Draft <span class="count">(%s)</span>', 'Drafts <span class="count">(%s)</span>')
     68                                                                                ) );
     69
     70        register_post_status( 'private', array( 'label' => _x('Private', 'post'),
     71                                                                                        'exclude_from_search' => false,
     72                                                                                        '_builtin' => true,
     73                                                                                        'label_count' => _n_noop('Private <span class="count">(%s)</span>', 'Private <span class="count">(%s)</span>')
     74                                                                                ) );
     75
     76        register_post_status( 'trash', array(   'label' => _x('Trash', 'post'),
     77                                                                                        'exclude_from_search' => false,
     78                                                                                        '_builtin' => true,
     79                                                                                        'label_count' => _n_noop('Trash <span class="count">(%s)</span>', 'Trash <span class="count">(%s)</span>')
     80                                                                                ) );
    3081}
    3182add_action( 'init', 'create_initial_post_types', 0 ); // highest priority
     
    640691 * capability_type - The post type to use for checking read, edit, and delete capabilities. Defaults to "post".
    641692 * hierarchical - Whether the post type is hierarchical. Defaults to false.
     693 * supports - An alias for calling add_post_type_support() directly. See add_post_type_support() for Documentation. Defaults to none.
    642694 *
    643695 * @package WordPress
     
    656708
    657709        // 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);
     710        $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());
    659711        $args = wp_parse_args($args, $defaults);
    660712        $args = (object) $args;
     
    676728        if ( !$args->_builtin && $args->public )
    677729                $args->_show = true;
     730
     731        if ( ! empty($args->supports) ) {
     732                add_post_type_support($post_type, $args->supports);
     733                unset($args->supports);
     734        }
    678735
    679736        $wp_post_types[$post_type] = $args;
     
    39413998                return;
    39423999
    3943         if ( !in_array( $post['post_type'], array( 'post', 'page' ) ) )
     4000        if ( !post_type_supports($post['post_type'], 'revisions') )
    39444001                return;
    39454002
Note: See TracChangeset for help on using the changeset viewer.