Skip to content

Commit efff0fe

Browse files
committed
Fix viewing autosave revision for custom post types. Props duck_. fixes #13110
git-svn-id: https://develop.svn.wordpress.org/trunk@14749 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 4528488 commit efff0fe

2 files changed

Lines changed: 20 additions & 18 deletions

File tree

wp-admin/revision.php

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@
1111

1212
wp_enqueue_script('list-revisions');
1313

14-
wp_reset_vars(array('revision', 'left', 'right', 'diff', 'action'));
14+
wp_reset_vars(array('revision', 'left', 'right', 'action'));
1515

1616
$revision_id = absint($revision);
17-
$diff = absint($diff);
1817
$left = absint($left);
1918
$right = absint($right);
2019

@@ -29,8 +28,11 @@
2928
if ( !$post = get_post( $revision->post_parent ) )
3029
break;
3130

32-
if ( ! WP_POST_REVISIONS && !wp_is_post_autosave( $revision ) ) // Revisions disabled and we're not looking at an autosave
31+
// Revisions disabled and we're not looking at an autosave
32+
if ( ( ! WP_POST_REVISIONS || !post_type_supports($post->post_type, 'revisions') ) && !wp_is_post_autosave( $revision ) ) {
33+
$redirect = 'edit.php?post_type=' . $post->post_type;
3334
break;
35+
}
3436

3537
check_admin_referer( "restore-post_$post->ID|$revision->ID" );
3638

@@ -68,15 +70,17 @@
6870
else
6971
break; // Don't diff two unrelated revisions
7072

71-
if ( ! WP_POST_REVISIONS ) { // Revisions disabled
73+
if ( ! WP_POST_REVISIONS || !post_type_supports($post->post_type, 'revisions') ) { // Revisions disabled
7274
if (
7375
// we're not looking at an autosave
7476
( !wp_is_post_autosave( $left_revision ) && !wp_is_post_autosave( $right_revision ) )
7577
||
7678
// we're not comparing an autosave to the current post
7779
( $post->ID !== $left_revision->ID && $post->ID !== $right_revision->ID )
78-
)
80+
) {
81+
$redirect = 'edit.php?post_type=' . $post->post_type;
7982
break;
83+
}
8084
}
8185

8286
if (
@@ -90,6 +94,7 @@
9094

9195
$post_title = '<a href="' . get_edit_post_link() . '">' . get_the_title() . '</a>';
9296
$h2 = sprintf( __( 'Compare Revisions of &#8220;%1$s&#8221;' ), $post_title );
97+
$title = __( 'Revisions' );
9398

9499
$left = $left_revision->ID;
95100
$right = $right_revision->ID;
@@ -106,10 +111,11 @@
106111
if ( !current_user_can( 'read_post', $revision->ID ) || !current_user_can( 'read_post', $post->ID ) )
107112
break;
108113

109-
if ( ! WP_POST_REVISIONS && !wp_is_post_autosave( $revision ) ) // Revisions disabled and we're not looking at an autosave
114+
// Revisions disabled and we're not looking at an autosave
115+
if ( ( ! WP_POST_REVISIONS || !post_type_supports($post->post_type, 'revisions') ) && !wp_is_post_autosave( $revision ) ) {
116+
$redirect = 'edit.php?post_type=' . $post->post_type;
110117
break;
111-
112-
$post_type_object = get_post_type_object($post->post_type);
118+
}
113119

114120
$post_title = '<a href="' . get_edit_post_link() . '">' . get_the_title() . '</a>';
115121
$revision_title = wp_post_revision_title( $revision, false );
@@ -124,12 +130,9 @@
124130
break;
125131
endswitch;
126132

127-
if ( !$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+
// Empty post_type means either malformed object found, or no valid parent was found.
134+
if ( !$redirect && empty($post->post_type) )
135+
$redirect = 'edit.php';
133136

134137
if ( !empty($redirect) ) {
135138
wp_redirect( $redirect );
@@ -207,7 +210,7 @@
207210
<?php
208211

209212
$args = array( 'format' => 'form-table', 'parent' => true, 'right' => $right, 'left' => $left );
210-
if ( ! WP_POST_REVISIONS )
213+
if ( ! WP_POST_REVISIONS || !post_type_supports($post->post_type, 'revisions') )
211214
$args['type'] = 'autosave';
212215

213216
wp_list_post_revisions( $post, $args );
@@ -217,5 +220,4 @@
217220
</div>
218221

219222
<?php
220-
221223
require_once( './admin-footer.php' );

wp-includes/post-template.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,12 +1169,12 @@ function wp_list_post_revisions( $post_id = 0, $args = null ) {
11691169
$class = $class ? '' : " class='alternate'";
11701170

11711171
if ( $post->ID != $revision->ID && $can_edit_post )
1172-
$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>';
1172+
$actions = '<a href="' . wp_nonce_url( add_query_arg( array( 'revision' => $revision->ID, 'action' => 'restore' ) ), "restore-post_$post->ID|$revision->ID" ) . '">' . __( 'Restore' ) . '</a>';
11731173
else
11741174
$actions = '';
11751175

11761176
$rows .= "<tr$class>\n";
1177-
$rows .= "\t<th style='white-space: nowrap' scope='row'><input type='radio' name='left' value='$revision->ID'$left_checked />\n";
1177+
$rows .= "\t<th style='white-space: nowrap' scope='row'><input type='radio' name='left' value='$revision->ID'$left_checked /></th>\n";
11781178
$rows .= "\t<th style='white-space: nowrap' scope='row'><input type='radio' name='right' value='$revision->ID'$right_checked /></th>\n";
11791179
$rows .= "\t<td>$date</td>\n";
11801180
$rows .= "\t<td>$name</td>\n";

0 commit comments

Comments
 (0)