<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[12751] trunk: 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().</title>
</head>
<body>
<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/12751">12751</a></dd>
<dt>Author</dt> <dd>dd32</dd>
<dt>Date</dt> <dd>2010-01-18 11:44:51 +0000 (Mon, 18 Jan 2010)</dd>
</dl>
<h3>Log Message</h3>
<pre>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 <a href="http://trac.wordpress.org/ticket/9674">#9674</a>. Fixes <a href="http://trac.wordpress.org/ticket/11703">#11703</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadmineditformadvancedphp">trunk/wp-admin/edit-form-advanced.php</a></li>
<li><a href="#trunkwpadminrevisionphp">trunk/wp-admin/revision.php</a></li>
<li><a href="#trunkwpincludesposttemplatephp">trunk/wp-includes/post-template.php</a></li>
<li><a href="#trunkwpincludespostphp">trunk/wp-includes/post.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadmineditformadvancedphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/edit-form-advanced.php (12750 => 12751)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/edit-form-advanced.php        2010-01-17 22:51:15 UTC (rev 12750)
+++ trunk/wp-admin/edit-form-advanced.php        2010-01-18 11:44:51 UTC (rev 12751)
</span><span class="lines">@@ -135,7 +135,7 @@
</span><span class="cx"> if ( $authors && count( $authors ) > 1 )
</span><span class="cx">         add_meta_box('authordiv', __('Author'), 'post_author_meta_box', $post_type, 'normal', 'core');
</span><span class="cx">
</span><del>-if ( 0 < $post_ID && wp_get_post_revisions( $post_ID ) )
</del><ins>+if ( post_type_supports($post_type, 'revisions') && 0 < $post_ID && wp_get_post_revisions( $post_ID ) )
</ins><span class="cx">         add_meta_box('revisionsdiv', __('Revisions'), 'post_revisions_meta_box', $post_type, 'normal', 'core');
</span><span class="cx">
</span><span class="cx"> do_action('do_meta_boxes', $post_type, 'normal', $post);
</span></span></pre></div>
<a id="trunkwpadminrevisionphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/revision.php (12750 => 12751)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/revision.php        2010-01-17 22:51:15 UTC (rev 12750)
+++ trunk/wp-admin/revision.php        2010-01-18 11:44:51 UTC (rev 12751)
</span><span class="lines">@@ -12,21 +12,15 @@
</span><span class="cx"> wp_enqueue_script('list-revisions');
</span><span class="cx">
</span><span class="cx"> wp_reset_vars(array('revision', 'left', 'right', 'diff', 'action'));
</span><ins>+
</ins><span class="cx"> $revision_id = absint($revision);
</span><span class="cx"> $diff = absint($diff);
</span><span class="cx"> $left = absint($left);
</span><span class="cx"> $right = absint($right);
</span><span class="cx">
</span><del>-$parent_file = $redirect = 'edit.php';
</del><ins>+$redirect = 'edit.php';
</ins><span class="cx">
</span><span class="cx"> switch ( $action ) :
</span><del>-case 'delete' : // stubs
-case 'edit' :
-        if ( constant('WP_POST_REVISIONS') ) // stub
-                $redirect = remove_query_arg( 'action' );
-        else // Revisions disabled
-                $redirect = 'edit.php';
-        break;
</del><span class="cx"> case 'restore' :
</span><span class="cx">         if ( !$revision = wp_get_post_revision( $revision_id ) )
</span><span class="cx">                 break;
</span><span class="lines">@@ -115,9 +109,12 @@
</span><span class="cx">         if ( !constant('WP_POST_REVISIONS') && !wp_is_post_autosave( $revision ) ) // Revisions disabled and we're not looking at an autosave
</span><span class="cx">                 break;
</span><span class="cx">
</span><ins>+        $post_type_object = get_post_type_object($post->post_type);
+
</ins><span class="cx">         $post_title = '<a href="' . get_edit_post_link() . '">' . get_the_title() . '</a>';
</span><span class="cx">         $revision_title = wp_post_revision_title( $revision, false );
</span><del>-        $h2 = sprintf( __( 'Post Revision for &#8220;%1$s&#8221; created on %2$s' ), $post_title, $revision_title );
</del><ins>+        $h2 = sprintf( __( 'Revision for &#8220;%1$s&#8221; created on %2$s' ), $post_title, $revision_title );
+        $title = __( 'Revisions' );
</ins><span class="cx">
</span><span class="cx">         // Sets up the diff radio buttons
</span><span class="cx">         $left = $revision->ID;
</span><span class="lines">@@ -127,21 +124,23 @@
</span><span class="cx">         break;
</span><span class="cx"> endswitch;
</span><span class="cx">
</span><del>-if ( !$redirect && !in_array( $post->post_type, array( 'post', 'page' ) ) )
-        $redirect = 'edit.php';
</del><ins>+if ( !$redirect ) {
+        if ( empty($post->post_type) ) // Empty post_type means either malformed object found, or no valid parent was found.
+                $redirect = 'edit.php';        
+        elseif ( !post_type_supports($post->post_type, 'revisions') )
+                $redirect = 'edit.php?post_type=' . $post->post_type;
+}
</ins><span class="cx">
</span><del>-if ( $redirect ) {
</del><ins>+if ( !empty($redirect) ) {
</ins><span class="cx">         wp_redirect( $redirect );
</span><span class="cx">         exit;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-if ( 'page' == $post->post_type ) {
-        $submenu_file = 'edit-pages.php';
-        $title = __( 'Page Revisions' );
-} else {
-        $submenu_file = 'edit.php';
-        $title = __( 'Post Revisions' );
-}
</del><ins>+// This is so that the correct "Edit" menu item is selected.
+if ( !empty($post->post_type) && 'post' != $post->post_type )
+        $parent_file = $submenu_file = 'edit.php?post_type=' . $post->post_type;
+else
+        $parent_file = $submenu_file = 'edit.php';
</ins><span class="cx">
</span><span class="cx"> require_once( 'admin-header.php' );
</span><span class="cx">
</span></span></pre></div>
<a id="trunkwpincludesposttemplatephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/post-template.php (12750 => 12751)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/post-template.php        2010-01-17 22:51:15 UTC (rev 12750)
+++ trunk/wp-includes/post-template.php        2010-01-18 11:44:51 UTC (rev 12751)
</span><span class="lines">@@ -1260,17 +1260,17 @@
</span><span class="cx">         extract( wp_parse_args( $args, $defaults ), EXTR_SKIP );
</span><span class="cx">
</span><span class="cx">         switch ( $type ) {
</span><del>-        case 'autosave' :
-                if ( !$autosave = wp_get_post_autosave( $post->ID ) )
-                        return;
-                $revisions = array( $autosave );
-                break;
-        case 'revision' : // just revisions - remove autosave later
-        case 'all' :
-        default :
-                if ( !$revisions = wp_get_post_revisions( $post->ID ) )
-                        return;
-                break;
</del><ins>+                case 'autosave' :
+                        if ( !$autosave = wp_get_post_autosave( $post->ID ) )
+                                return;
+                        $revisions = array( $autosave );
+                        break;
+                case 'revision' : // just revisions - remove autosave later
+                case 'all' :
+                default :
+                        if ( !$revisions = wp_get_post_revisions( $post->ID ) )
+                                return;
+                        break;
</ins><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         /* translators: post revision: 1: when, 2: author name */
</span><span class="lines">@@ -1326,6 +1326,7 @@
</span><span class="cx">         <div class="alignleft">
</span><span class="cx">                 <input type="submit" class="button-secondary" value="<?php esc_attr_e( 'Compare Revisions' ); ?>" />
</span><span class="cx">                 <input type="hidden" name="action" value="diff" />
</span><ins>+                <input type="hidden" name="post_type" value="<?php echo esc_attr($GLOBALS['post_type']); ?>" />
</ins><span class="cx">         </div>
</span><span class="cx"> </div>
</span><span class="cx">
</span></span></pre></div>
<a id="trunkwpincludespostphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/post.php (12750 => 12751)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/post.php        2010-01-17 22:51:15 UTC (rev 12750)
+++ trunk/wp-includes/post.php        2010-01-18 11:44:51 UTC (rev 12751)
</span><span class="lines">@@ -15,18 +15,69 @@
</span><span class="cx"> * Creates the initial post types when 'init' action is fired.
</span><span class="cx"> */
</span><span class="cx"> function create_initial_post_types() {
</span><del>-        register_post_type( 'post', array('label' => __('Posts'), 'exclude_from_search' => false, '_builtin' => true, '_edit_link' => 'post.php?post=%d', 'capability_type' => 'post', 'hierarchical' => false) );
-        register_post_type( 'page', array('label' => __('Pages'),'exclude_from_search' => false, '_builtin' => true, '_edit_link' => 'post.php?post=%d', 'capability_type' => 'page', 'hierarchical' => true) );
-        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) );
-        register_post_type( 'revision', array('label' => __('Revisions'),'exclude_from_search' => true, '_builtin' => true, '_edit_link' => 'revision.php?revision=%d', 'capability_type' => 'post', 'hierarchical' => false) );
-        add_post_type_support('post', array('post-thumbnails', 'excerpts', 'trackbacks', 'custom-fields', 'comments') );
-        add_post_type_support('page', array('post-thumbnails', 'page-attributes', 'custom-fields', 'comments') );
</del><ins>+        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')
+                                                                        ) );
</ins><span class="cx">
</span><del>-        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>')) );
-        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>')) );
-        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>')) );
-        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>')) );
-        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>')) );
</del><ins>+        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')
+                                                                        ) );
+
+        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
+                                                                                ) );
+
+        register_post_type( 'revision', array(        'label' => __('Revisions'),
+                                                                                        'exclude_from_search' => true,
+                                                                                        '_builtin' => true,
+                                                                                        '_edit_link' => 'revision.php?revision=%d',
+                                                                                        'capability_type' => 'post',
+                                                                                        'hierarchical' => false
+                                                                                ) );
+
+        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>')
+                                                                                ) );
+
+        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>')
+                                                                                ) );
+
+        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>')
+                                                                                ) );
+
+        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>')
+                                                                                ) );
+
+        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>')
+                                                                                ) );
</ins><span class="cx"> }
</span><span class="cx"> add_action( 'init', 'create_initial_post_types', 0 ); // highest priority
</span><span class="cx">
</span><span class="lines">@@ -639,6 +690,7 @@
</span><span class="cx"> * inherit_type - The post type from which to inherit the edit link and capability type. Defaults to none.
</span><span class="cx"> * capability_type - The post type to use for checking read, edit, and delete capabilities. Defaults to "post".
</span><span class="cx"> * hierarchical - Whether the post type is hierarchical. Defaults to false.
</span><ins>+ * supports - An alias for calling add_post_type_support() directly. See add_post_type_support() for Documentation. Defaults to none.
</ins><span class="cx"> *
</span><span class="cx"> * @package WordPress
</span><span class="cx"> * @subpackage Post
</span><span class="lines">@@ -655,7 +707,7 @@
</span><span class="cx">                 $wp_post_types = array();
</span><span class="cx">
</span><span class="cx">         // Args prefixed with an underscore are reserved for internal use.
</span><del>-        $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);
</del><ins>+        $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());
</ins><span class="cx">         $args = wp_parse_args($args, $defaults);
</span><span class="cx">         $args = (object) $args;
</span><span class="cx">
</span><span class="lines">@@ -676,6 +728,11 @@
</span><span class="cx">         if ( !$args->_builtin && $args->public )
</span><span class="cx">                 $args->_show = true;
</span><span class="cx">
</span><ins>+        if ( ! empty($args->supports) ) {
+                add_post_type_support($post_type, $args->supports);
+                unset($args->supports);
+        }
+
</ins><span class="cx">         $wp_post_types[$post_type] = $args;
</span><span class="cx">
</span><span class="cx">         return $args;
</span><span class="lines">@@ -3940,7 +3997,7 @@
</span><span class="cx">         if ( !$post = get_post( $post_id, ARRAY_A ) )
</span><span class="cx">                 return;
</span><span class="cx">
</span><del>-        if ( !in_array( $post['post_type'], array( 'post', 'page' ) ) )
</del><ins>+        if ( !post_type_supports($post['post_type'], 'revisions') )
</ins><span class="cx">                 return;
</span><span class="cx">
</span><span class="cx">         $return = _wp_put_post_revision( $post );
</span></span></pre>
</div>
</div>
</body>
</html>