<!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->post_parent ) )
</span><span class="cx">                 break;
</span><span class="cx">
</span><del>-        if ( ! WP_POST_REVISIONS && !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->post_type, 'revisions') ) && !wp_is_post_autosave( $revision ) ) {
+                $redirect = 'edit.php?post_type=' . $post->post_type;
</ins><span class="cx">                 break;
</span><ins>+        }
</ins><span class="cx">
</span><span class="cx">         check_admin_referer( "restore-post_$post->ID|$revision->ID" );
</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->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 ) && !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->ID !== $left_revision->ID && $post->ID !== $right_revision->ID )
</span><del>-                )
</del><ins>+                ) {
+                        $redirect = 'edit.php?post_type=' . $post->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 = '<a href="' . get_edit_post_link() . '">' . get_the_title() . '</a>';
</span><span class="cx">         $h2 = sprintf( __( 'Compare Revisions of &#8220;%1$s&#8221;' ), $post_title );
</span><ins>+        $title = __( 'Revisions' );
</ins><span class="cx">
</span><span class="cx">         $left = $left_revision->ID;
</span><span class="cx">         $right = $right_revision->ID;
</span><span class="lines">@@ -106,11 +111,12 @@
</span><span class="cx">         if ( !current_user_can( 'read_post', $revision->ID ) || !current_user_can( 'read_post', $post->ID ) )
</span><span class="cx">                 break;
</span><span class="cx">
</span><del>-        if ( ! WP_POST_REVISIONS && !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->post_type, 'revisions') ) && !wp_is_post_autosave( $revision ) ) {
+                $redirect = 'edit.php?post_type=' . $post->post_type;
</ins><span class="cx">                 break;
</span><ins>+        }
</ins><span class="cx">
</span><del>-        $post_type_object = get_post_type_object($post->post_type);
-
</del><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><span class="cx">         $h2 = sprintf( __( 'Revision for &#8220;%1$s&#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->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;
-}
</del><ins>+// Empty post_type means either malformed object found, or no valid parent was found.
+if ( !$redirect && empty($post->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"> <?php
</span><span class="cx">
</span><span class="cx"> $args = array( 'format' => 'form-table', 'parent' => true, 'right' => $right, 'left' => $left );
</span><del>-if ( ! WP_POST_REVISIONS )
</del><ins>+if ( ! WP_POST_REVISIONS || !post_type_supports($post->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"> </div>
</span><span class="cx">
</span><span class="cx"> <?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 ? '' : " class='alternate'";
</span><span class="cx">
</span><span class="cx">                         if ( $post->ID != $revision->ID && $can_edit_post )
</span><del>-                                $actions = '<a href="' . wp_nonce_url( add_query_arg( array( 'revision' => $revision->ID, 'diff' => false, 'action' => 'restore' ) ), "restore-post_$post->ID|$revision->ID" ) . '">' . __( 'Restore' ) . '</a>';
</del><ins>+                                $actions = '<a href="' . wp_nonce_url( add_query_arg( array( 'revision' => $revision->ID, 'action' => 'restore' ) ), "restore-post_$post->ID|$revision->ID" ) . '">' . __( 'Restore' ) . '</a>';
</ins><span class="cx">                         else
</span><span class="cx">                                 $actions = '';
</span><span class="cx">
</span><span class="cx">                         $rows .= "<tr$class>\n";
</span><del>-                        $rows .= "\t<th style='white-space: nowrap' scope='row'><input type='radio' name='left' value='$revision->ID'$left_checked />\n";
</del><ins>+                        $rows .= "\t<th style='white-space: nowrap' scope='row'><input type='radio' name='left' value='$revision->ID'$left_checked /></th>\n";
</ins><span class="cx">                         $rows .= "\t<th style='white-space: nowrap' scope='row'><input type='radio' name='right' value='$revision->ID'$right_checked /></th>\n";
</span><span class="cx">                         $rows .= "\t<td>$date</td>\n";
</span><span class="cx">                         $rows .= "\t<td>$name</td>\n";
</span></span></pre>
</div>
</div>
</body>
</html>