<!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>[14749] trunk: Fix viewing autosave revision for custom post types.</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/14749">14749</a></dd>
<dt>Author</dt> <dd>ryan</dd>
<dt>Date</dt> <dd>2010-05-19 18:36:52 +0000 (Wed, 19 May 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>Fix viewing autosave revision for custom post types. Props duck_. fixes <a href="http://trac.wordpress.org/ticket/13110">#13110</a></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminrevisionphp">trunk/wp-admin/revision.php</a></li>
<li><a href="#trunkwpincludesposttemplatephp">trunk/wp-includes/post-template.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminrevisionphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/revision.php (14748 => 14749)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/revision.php        2010-05-19 18:18:26 UTC (rev 14748)
+++ trunk/wp-admin/revision.php        2010-05-19 18:36:52 UTC (rev 14749)
</span><span class="lines">@@ -11,10 +11,9 @@
</span><span class="cx"> 
</span><span class="cx"> wp_enqueue_script('list-revisions');
</span><span class="cx"> 
</span><del>-wp_reset_vars(array('revision', 'left', 'right', 'diff', 'action'));
</del><ins>+wp_reset_vars(array('revision', 'left', 'right', 'action'));
</ins><span class="cx"> 
</span><span class="cx"> $revision_id = absint($revision);
</span><del>-$diff        = absint($diff);
</del><span class="cx"> $left        = absint($left);
</span><span class="cx"> $right       = absint($right);
</span><span class="cx"> 
</span><span class="lines">@@ -29,8 +28,11 @@
</span><span class="cx">         if ( !$post = get_post( $revision-&gt;post_parent ) )
</span><span class="cx">                 break;
</span><span class="cx"> 
</span><del>-        if ( ! WP_POST_REVISIONS &amp;&amp; !wp_is_post_autosave( $revision ) ) // Revisions disabled and we're not looking at an autosave
</del><ins>+        // Revisions disabled and we're not looking at an autosave
+        if ( ( ! WP_POST_REVISIONS || !post_type_supports($post-&gt;post_type, 'revisions') ) &amp;&amp; !wp_is_post_autosave( $revision ) ) {
+                $redirect = 'edit.php?post_type=' . $post-&gt;post_type;
</ins><span class="cx">                 break;
</span><ins>+        }
</ins><span class="cx"> 
</span><span class="cx">         check_admin_referer( &quot;restore-post_$post-&gt;ID|$revision-&gt;ID&quot; );
</span><span class="cx"> 
</span><span class="lines">@@ -68,15 +70,17 @@
</span><span class="cx">         else
</span><span class="cx">                 break; // Don't diff two unrelated revisions
</span><span class="cx"> 
</span><del>-        if ( ! WP_POST_REVISIONS ) { // Revisions disabled
</del><ins>+        if ( ! WP_POST_REVISIONS || !post_type_supports($post-&gt;post_type, 'revisions') ) { // Revisions disabled
</ins><span class="cx">                 if (
</span><span class="cx">                         // we're not looking at an autosave
</span><span class="cx">                         ( !wp_is_post_autosave( $left_revision ) &amp;&amp; !wp_is_post_autosave( $right_revision ) )
</span><span class="cx">                 ||
</span><span class="cx">                         // we're not comparing an autosave to the current post
</span><span class="cx">                         ( $post-&gt;ID !== $left_revision-&gt;ID &amp;&amp; $post-&gt;ID !== $right_revision-&gt;ID )
</span><del>-                )
</del><ins>+                ) {
+                        $redirect = 'edit.php?post_type=' . $post-&gt;post_type;
</ins><span class="cx">                         break;
</span><ins>+                }
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         if (
</span><span class="lines">@@ -90,6 +94,7 @@
</span><span class="cx"> 
</span><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">         $h2 = sprintf( __( 'Compare Revisions of &amp;#8220;%1$s&amp;#8221;' ), $post_title );
</span><ins>+        $title = __( 'Revisions' );
</ins><span class="cx"> 
</span><span class="cx">         $left  = $left_revision-&gt;ID;
</span><span class="cx">         $right = $right_revision-&gt;ID;
</span><span class="lines">@@ -106,11 +111,12 @@
</span><span class="cx">         if ( !current_user_can( 'read_post', $revision-&gt;ID ) || !current_user_can( 'read_post', $post-&gt;ID ) )
</span><span class="cx">                 break;
</span><span class="cx"> 
</span><del>-        if ( ! WP_POST_REVISIONS &amp;&amp; !wp_is_post_autosave( $revision ) ) // Revisions disabled and we're not looking at an autosave
</del><ins>+        // Revisions disabled and we're not looking at an autosave
+        if ( ( ! WP_POST_REVISIONS || !post_type_supports($post-&gt;post_type, 'revisions') ) &amp;&amp; !wp_is_post_autosave( $revision ) ) {
+                $redirect = 'edit.php?post_type=' . $post-&gt;post_type;
</ins><span class="cx">                 break;
</span><ins>+        }
</ins><span class="cx"> 
</span><del>-        $post_type_object = get_post_type_object($post-&gt;post_type);
-
</del><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><span class="cx">         $h2 = sprintf( __( 'Revision for &amp;#8220;%1$s&amp;#8221; created on %2$s' ), $post_title, $revision_title );
</span><span class="lines">@@ -124,12 +130,9 @@
</span><span class="cx">         break;
</span><span class="cx"> endswitch;
</span><span class="cx"> 
</span><del>-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;
-}
</del><ins>+// Empty post_type means either malformed object found, or no valid parent was found.
+if ( !$redirect &amp;&amp; empty($post-&gt;post_type) )
+        $redirect = 'edit.php';
</ins><span class="cx"> 
</span><span class="cx"> if ( !empty($redirect) ) {
</span><span class="cx">         wp_redirect( $redirect );
</span><span class="lines">@@ -207,7 +210,7 @@
</span><span class="cx"> &lt;?php
</span><span class="cx"> 
</span><span class="cx"> $args = array( 'format' =&gt; 'form-table', 'parent' =&gt; true, 'right' =&gt; $right, 'left' =&gt; $left );
</span><del>-if ( ! WP_POST_REVISIONS )
</del><ins>+if ( ! WP_POST_REVISIONS || !post_type_supports($post-&gt;post_type, 'revisions') )
</ins><span class="cx">         $args['type'] = 'autosave';
</span><span class="cx"> 
</span><span class="cx"> wp_list_post_revisions( $post, $args );
</span><span class="lines">@@ -217,5 +220,4 @@
</span><span class="cx"> &lt;/div&gt;
</span><span class="cx"> 
</span><span class="cx"> &lt;?php
</span><del>-
</del><span class="cx"> require_once( './admin-footer.php' );
</span></span></pre></div>
<a id="trunkwpincludesposttemplatephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/post-template.php (14748 => 14749)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/post-template.php        2010-05-19 18:18:26 UTC (rev 14748)
+++ trunk/wp-includes/post-template.php        2010-05-19 18:36:52 UTC (rev 14749)
</span><span class="lines">@@ -1169,12 +1169,12 @@
</span><span class="cx">                         $class = $class ? '' : &quot; class='alternate'&quot;;
</span><span class="cx"> 
</span><span class="cx">                         if ( $post-&gt;ID != $revision-&gt;ID &amp;&amp; $can_edit_post )
</span><del>-                                $actions = '&lt;a href=&quot;' . wp_nonce_url( add_query_arg( array( 'revision' =&gt; $revision-&gt;ID, 'diff' =&gt; false, 'action' =&gt; 'restore' ) ), &quot;restore-post_$post-&gt;ID|$revision-&gt;ID&quot; ) . '&quot;&gt;' . __( 'Restore' ) . '&lt;/a&gt;';
</del><ins>+                                $actions = '&lt;a href=&quot;' . wp_nonce_url( add_query_arg( array( 'revision' =&gt; $revision-&gt;ID, 'action' =&gt; 'restore' ) ), &quot;restore-post_$post-&gt;ID|$revision-&gt;ID&quot; ) . '&quot;&gt;' . __( 'Restore' ) . '&lt;/a&gt;';
</ins><span class="cx">                         else
</span><span class="cx">                                 $actions = '';
</span><span class="cx"> 
</span><span class="cx">                         $rows .= &quot;&lt;tr$class&gt;\n&quot;;
</span><del>-                        $rows .= &quot;\t&lt;th style='white-space: nowrap' scope='row'&gt;&lt;input type='radio' name='left' value='$revision-&gt;ID'$left_checked /&gt;\n&quot;;
</del><ins>+                        $rows .= &quot;\t&lt;th style='white-space: nowrap' scope='row'&gt;&lt;input type='radio' name='left' value='$revision-&gt;ID'$left_checked /&gt;&lt;/th&gt;\n&quot;;
</ins><span class="cx">                         $rows .= &quot;\t&lt;th style='white-space: nowrap' scope='row'&gt;&lt;input type='radio' name='right' value='$revision-&gt;ID'$right_checked /&gt;&lt;/th&gt;\n&quot;;
</span><span class="cx">                         $rows .= &quot;\t&lt;td&gt;$date&lt;/td&gt;\n&quot;;
</span><span class="cx">                         $rows .= &quot;\t&lt;td&gt;$name&lt;/td&gt;\n&quot;;
</span></span></pre>
</div>
</div>

</body>
</html>