<!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 &amp;&amp; count( $authors ) &gt; 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 &lt; $post_ID &amp;&amp; wp_get_post_revisions( $post_ID ) )
</del><ins>+if ( post_type_supports($post_type, 'revisions') &amp;&amp; 0 &lt; $post_ID &amp;&amp; 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') &amp;&amp; !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-&gt;post_type);
+
</ins><span class="cx">         $post_title = '&lt;a href=&quot;' . get_edit_post_link() . '&quot;&gt;' . get_the_title() . '&lt;/a&gt;';
</span><span class="cx">         $revision_title = wp_post_revision_title( $revision, false );
</span><del>-        $h2 = sprintf( __( 'Post Revision for &amp;#8220;%1$s&amp;#8221; created on %2$s' ), $post_title, $revision_title );
</del><ins>+        $h2 = sprintf( __( 'Revision for &amp;#8220;%1$s&amp;#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-&gt;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 &amp;&amp; !in_array( $post-&gt;post_type, array( 'post', 'page' ) ) )
-        $redirect = 'edit.php';
</del><ins>+if ( !$redirect ) {
+        if ( empty($post-&gt;post_type) ) // Empty post_type means either malformed object found, or no valid parent was found.
+                $redirect = 'edit.php';        
+        elseif ( !post_type_supports($post-&gt;post_type, 'revisions') )
+                $redirect = 'edit.php?post_type=' . $post-&gt;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-&gt;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 &quot;Edit&quot; menu item is selected.
+if ( !empty($post-&gt;post_type) &amp;&amp; 'post' != $post-&gt;post_type )
+        $parent_file = $submenu_file = 'edit.php?post_type=' . $post-&gt;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-&gt;ID ) )
-                        return;
-                $revisions = array( $autosave );
-                break;
-        case 'revision' : // just revisions - remove autosave later
-        case 'all' :
-        default :
-                if ( !$revisions = wp_get_post_revisions( $post-&gt;ID ) )
-                        return;
-                break;
</del><ins>+                case 'autosave' :
+                        if ( !$autosave = wp_get_post_autosave( $post-&gt;ID ) )
+                                return;
+                        $revisions = array( $autosave );
+                        break;
+                case 'revision' : // just revisions - remove autosave later
+                case 'all' :
+                default :
+                        if ( !$revisions = wp_get_post_revisions( $post-&gt;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">         &lt;div class=&quot;alignleft&quot;&gt;
</span><span class="cx">                 &lt;input type=&quot;submit&quot; class=&quot;button-secondary&quot; value=&quot;&lt;?php esc_attr_e( 'Compare Revisions' ); ?&gt;&quot; /&gt;
</span><span class="cx">                 &lt;input type=&quot;hidden&quot; name=&quot;action&quot; value=&quot;diff&quot; /&gt;
</span><ins>+                &lt;input type=&quot;hidden&quot; name=&quot;post_type&quot; value=&quot;&lt;?php echo esc_attr($GLOBALS['post_type']); ?&gt;&quot; /&gt;
</ins><span class="cx">         &lt;/div&gt;
</span><span class="cx"> &lt;/div&gt;
</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' =&gt; __('Posts'), 'exclude_from_search' =&gt; false, '_builtin' =&gt; true, '_edit_link' =&gt; 'post.php?post=%d', 'capability_type' =&gt; 'post', 'hierarchical' =&gt; false) );
-        register_post_type( 'page', array('label' =&gt; __('Pages'),'exclude_from_search' =&gt; false, '_builtin' =&gt; true, '_edit_link' =&gt; 'post.php?post=%d', 'capability_type' =&gt; 'page', 'hierarchical' =&gt; true) );
-        register_post_type( 'attachment', array('label' =&gt; __('Media'), 'exclude_from_search' =&gt; false, '_builtin' =&gt; true, '_edit_link' =&gt; 'media.php?attachment_id=%d', 'capability_type' =&gt; 'post', 'hierarchical' =&gt; false) );
-        register_post_type( 'revision', array('label' =&gt; __('Revisions'),'exclude_from_search' =&gt; true, '_builtin' =&gt; true, '_edit_link' =&gt; 'revision.php?revision=%d', 'capability_type' =&gt; 'post', 'hierarchical' =&gt; 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' =&gt; __('Posts'),
+                                                                                'exclude_from_search' =&gt; false,
+                                                                                '_builtin' =&gt; true,
+                                                                                '_edit_link' =&gt; 'post.php?post=%d',
+                                                                                'capability_type' =&gt; 'post',
+                                                                                'hierarchical' =&gt; false,
+                                                                                'supports' =&gt; array('post-thumbnails', 'excerpts', 'trackbacks', 'custom-fields', 'comments', 'revisions')
+                                                                        ) );
</ins><span class="cx"> 
</span><del>-        register_post_status( 'publish', array('label' =&gt; _x('Published', 'post'), 'exclude_from_search' =&gt; false, '_builtin' =&gt; true, 'label_count' =&gt; _n_noop('Published &lt;span class=&quot;count&quot;&gt;(%s)&lt;/span&gt;', 'Published &lt;span class=&quot;count&quot;&gt;(%s)&lt;/span&gt;')) );
-        register_post_status( 'future', array('label' =&gt; _x('Scheduled', 'post'), 'exclude_from_search' =&gt; false, '_builtin' =&gt; true, 'label_count' =&gt; _n_noop('Scheduled &lt;span class=&quot;count&quot;&gt;(%s)&lt;/span&gt;', 'Scheduled &lt;span class=&quot;count&quot;&gt;(%s)&lt;/span&gt;')) );
-        register_post_status( 'draft', array('label' =&gt; _x('Draft', 'post'), 'exclude_from_search' =&gt; false, '_builtin' =&gt; true, 'label_count' =&gt; _n_noop('Draft &lt;span class=&quot;count&quot;&gt;(%s)&lt;/span&gt;', 'Drafts &lt;span class=&quot;count&quot;&gt;(%s)&lt;/span&gt;')) );
-        register_post_status( 'private', array('label' =&gt; _x('Private', 'post'), 'exclude_from_search' =&gt; false, '_builtin' =&gt; true, 'label_count' =&gt; _n_noop('Private &lt;span class=&quot;count&quot;&gt;(%s)&lt;/span&gt;', 'Private &lt;span class=&quot;count&quot;&gt;(%s)&lt;/span&gt;')) );
-        register_post_status( 'trash', array('label' =&gt; _x('Trash', 'post'), 'exclude_from_search' =&gt; false, '_builtin' =&gt; true, 'label_count' =&gt; _n_noop('Trash &lt;span class=&quot;count&quot;&gt;(%s)&lt;/span&gt;', 'Trash &lt;span class=&quot;count&quot;&gt;(%s)&lt;/span&gt;')) );
</del><ins>+        register_post_type( 'page', array(        'label' =&gt; __('Pages'),
+                                                                                'exclude_from_search' =&gt; false,
+                                                                                '_builtin' =&gt; true,
+                                                                                '_edit_link' =&gt; 'post.php?post=%d',
+                                                                                'capability_type' =&gt; 'page',
+                                                                                'hierarchical' =&gt; true,
+                                                                                'supports' =&gt; array('post-thumbnails', 'page-attributes', 'custom-fields', 'comments', 'revisions')
+                                                                        ) );
+
+        register_post_type( 'attachment', array('label' =&gt; __('Media'),
+                                                                                        'exclude_from_search' =&gt; false,
+                                                                                        '_builtin' =&gt; true,
+                                                                                        '_edit_link' =&gt; 'media.php?attachment_id=%d',
+                                                                                        'capability_type' =&gt; 'post',
+                                                                                        'hierarchical' =&gt; false
+                                                                                ) );
+
+        register_post_type( 'revision', array(        'label' =&gt; __('Revisions'),
+                                                                                        'exclude_from_search' =&gt; true,
+                                                                                        '_builtin' =&gt; true,
+                                                                                        '_edit_link' =&gt; 'revision.php?revision=%d',
+                                                                                        'capability_type' =&gt; 'post',
+                                                                                        'hierarchical' =&gt; false
+                                                                                ) );
+
+        register_post_status( 'publish', array(        'label' =&gt; _x('Published', 'post'),
+                                                                                        'exclude_from_search' =&gt; false,
+                                                                                        '_builtin' =&gt; true,
+                                                                                        'label_count' =&gt; _n_noop('Published &lt;span class=&quot;count&quot;&gt;(%s)&lt;/span&gt;', 'Published &lt;span class=&quot;count&quot;&gt;(%s)&lt;/span&gt;')
+                                                                                ) );
+
+        register_post_status( 'future', array(        'label' =&gt; _x('Scheduled', 'post'),
+                                                                                        'exclude_from_search' =&gt; false,
+                                                                                        '_builtin' =&gt; true,
+                                                                                        'label_count' =&gt; _n_noop('Scheduled &lt;span class=&quot;count&quot;&gt;(%s)&lt;/span&gt;', 'Scheduled &lt;span class=&quot;count&quot;&gt;(%s)&lt;/span&gt;')
+                                                                                ) );
+
+        register_post_status( 'draft', array(        'label' =&gt; _x('Draft', 'post'),
+                                                                                        'exclude_from_search' =&gt; false,
+                                                                                        '_builtin' =&gt; true,
+                                                                                        'label_count' =&gt; _n_noop('Draft &lt;span class=&quot;count&quot;&gt;(%s)&lt;/span&gt;', 'Drafts &lt;span class=&quot;count&quot;&gt;(%s)&lt;/span&gt;')
+                                                                                ) );
+
+        register_post_status( 'private', array(        'label' =&gt; _x('Private', 'post'),
+                                                                                        'exclude_from_search' =&gt; false,
+                                                                                        '_builtin' =&gt; true,
+                                                                                        'label_count' =&gt; _n_noop('Private &lt;span class=&quot;count&quot;&gt;(%s)&lt;/span&gt;', 'Private &lt;span class=&quot;count&quot;&gt;(%s)&lt;/span&gt;')
+                                                                                ) );
+
+        register_post_status( 'trash', array(        'label' =&gt; _x('Trash', 'post'),
+                                                                                        'exclude_from_search' =&gt; false,
+                                                                                        '_builtin' =&gt; true,
+                                                                                        'label_count' =&gt; _n_noop('Trash &lt;span class=&quot;count&quot;&gt;(%s)&lt;/span&gt;', 'Trash &lt;span class=&quot;count&quot;&gt;(%s)&lt;/span&gt;')
+                                                                                ) );
</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 &quot;post&quot;.
</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' =&gt; false, 'exclude_from_search' =&gt; true, '_builtin' =&gt; false, '_edit_link' =&gt; 'post.php?post=%d', 'capability_type' =&gt; 'post', 'hierarchical' =&gt; false, 'public' =&gt; false, '_show' =&gt; false);
</del><ins>+        $defaults = array('label' =&gt; false, 'exclude_from_search' =&gt; true, '_builtin' =&gt; false, '_edit_link' =&gt; 'post.php?post=%d', 'capability_type' =&gt; 'post', 'hierarchical' =&gt; false, 'public' =&gt; false, '_show' =&gt; false, 'supports' =&gt; 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-&gt;_builtin &amp;&amp; $args-&gt;public )
</span><span class="cx">                 $args-&gt;_show = true;
</span><span class="cx"> 
</span><ins>+        if ( ! empty($args-&gt;supports) ) {
+                add_post_type_support($post_type, $args-&gt;supports);
+                unset($args-&gt;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>