mirror of
https://github.com/WordPress/WordPress.git
synced 2024-11-15 23:25:50 +01:00
Fix viewing autosave revision for custom post types. Props duck_. fixes #13110
git-svn-id: http://svn.automattic.com/wordpress/trunk@14749 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
f0bf7b3bd3
commit
caf573b721
@ -11,10 +11,9 @@ require_once('./admin.php');
|
|||||||
|
|
||||||
wp_enqueue_script('list-revisions');
|
wp_enqueue_script('list-revisions');
|
||||||
|
|
||||||
wp_reset_vars(array('revision', 'left', 'right', 'diff', 'action'));
|
wp_reset_vars(array('revision', 'left', 'right', 'action'));
|
||||||
|
|
||||||
$revision_id = absint($revision);
|
$revision_id = absint($revision);
|
||||||
$diff = absint($diff);
|
|
||||||
$left = absint($left);
|
$left = absint($left);
|
||||||
$right = absint($right);
|
$right = absint($right);
|
||||||
|
|
||||||
@ -29,8 +28,11 @@ case 'restore' :
|
|||||||
if ( !$post = get_post( $revision->post_parent ) )
|
if ( !$post = get_post( $revision->post_parent ) )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if ( ! WP_POST_REVISIONS && !wp_is_post_autosave( $revision ) ) // Revisions disabled and we're not looking at an autosave
|
// 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;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
check_admin_referer( "restore-post_$post->ID|$revision->ID" );
|
check_admin_referer( "restore-post_$post->ID|$revision->ID" );
|
||||||
|
|
||||||
@ -68,16 +70,18 @@ case 'diff' :
|
|||||||
else
|
else
|
||||||
break; // Don't diff two unrelated revisions
|
break; // Don't diff two unrelated revisions
|
||||||
|
|
||||||
if ( ! WP_POST_REVISIONS ) { // Revisions disabled
|
if ( ! WP_POST_REVISIONS || !post_type_supports($post->post_type, 'revisions') ) { // Revisions disabled
|
||||||
if (
|
if (
|
||||||
// we're not looking at an autosave
|
// we're not looking at an autosave
|
||||||
( !wp_is_post_autosave( $left_revision ) && !wp_is_post_autosave( $right_revision ) )
|
( !wp_is_post_autosave( $left_revision ) && !wp_is_post_autosave( $right_revision ) )
|
||||||
||
|
||
|
||||||
// we're not comparing an autosave to the current post
|
// we're not comparing an autosave to the current post
|
||||||
( $post->ID !== $left_revision->ID && $post->ID !== $right_revision->ID )
|
( $post->ID !== $left_revision->ID && $post->ID !== $right_revision->ID )
|
||||||
)
|
) {
|
||||||
|
$redirect = 'edit.php?post_type=' . $post->post_type;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
// They're the same
|
// They're the same
|
||||||
@ -90,6 +94,7 @@ case 'diff' :
|
|||||||
|
|
||||||
$post_title = '<a href="' . get_edit_post_link() . '">' . get_the_title() . '</a>';
|
$post_title = '<a href="' . get_edit_post_link() . '">' . get_the_title() . '</a>';
|
||||||
$h2 = sprintf( __( 'Compare Revisions of “%1$s”' ), $post_title );
|
$h2 = sprintf( __( 'Compare Revisions of “%1$s”' ), $post_title );
|
||||||
|
$title = __( 'Revisions' );
|
||||||
|
|
||||||
$left = $left_revision->ID;
|
$left = $left_revision->ID;
|
||||||
$right = $right_revision->ID;
|
$right = $right_revision->ID;
|
||||||
@ -106,10 +111,11 @@ default :
|
|||||||
if ( !current_user_can( 'read_post', $revision->ID ) || !current_user_can( 'read_post', $post->ID ) )
|
if ( !current_user_can( 'read_post', $revision->ID ) || !current_user_can( 'read_post', $post->ID ) )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if ( ! WP_POST_REVISIONS && !wp_is_post_autosave( $revision ) ) // Revisions disabled and we're not looking at an autosave
|
// 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;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
$post_type_object = get_post_type_object($post->post_type);
|
|
||||||
|
|
||||||
$post_title = '<a href="' . get_edit_post_link() . '">' . get_the_title() . '</a>';
|
$post_title = '<a href="' . get_edit_post_link() . '">' . get_the_title() . '</a>';
|
||||||
$revision_title = wp_post_revision_title( $revision, false );
|
$revision_title = wp_post_revision_title( $revision, false );
|
||||||
@ -124,12 +130,9 @@ default :
|
|||||||
break;
|
break;
|
||||||
endswitch;
|
endswitch;
|
||||||
|
|
||||||
if ( !$redirect ) {
|
// Empty post_type means either malformed object found, or no valid parent was found.
|
||||||
if ( empty($post->post_type) ) // Empty post_type means either malformed object found, or no valid parent was found.
|
if ( !$redirect && empty($post->post_type) )
|
||||||
$redirect = 'edit.php';
|
$redirect = 'edit.php';
|
||||||
elseif ( !post_type_supports($post->post_type, 'revisions') )
|
|
||||||
$redirect = 'edit.php?post_type=' . $post->post_type;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !empty($redirect) ) {
|
if ( !empty($redirect) ) {
|
||||||
wp_redirect( $redirect );
|
wp_redirect( $redirect );
|
||||||
@ -207,7 +210,7 @@ endif;
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
$args = array( 'format' => 'form-table', 'parent' => true, 'right' => $right, 'left' => $left );
|
$args = array( 'format' => 'form-table', 'parent' => true, 'right' => $right, 'left' => $left );
|
||||||
if ( ! WP_POST_REVISIONS )
|
if ( ! WP_POST_REVISIONS || !post_type_supports($post->post_type, 'revisions') )
|
||||||
$args['type'] = 'autosave';
|
$args['type'] = 'autosave';
|
||||||
|
|
||||||
wp_list_post_revisions( $post, $args );
|
wp_list_post_revisions( $post, $args );
|
||||||
@ -217,5 +220,4 @@ wp_list_post_revisions( $post, $args );
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
require_once( './admin-footer.php' );
|
require_once( './admin-footer.php' );
|
||||||
|
@ -1169,12 +1169,12 @@ function wp_list_post_revisions( $post_id = 0, $args = null ) {
|
|||||||
$class = $class ? '' : " class='alternate'";
|
$class = $class ? '' : " class='alternate'";
|
||||||
|
|
||||||
if ( $post->ID != $revision->ID && $can_edit_post )
|
if ( $post->ID != $revision->ID && $can_edit_post )
|
||||||
$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>';
|
$actions = '<a href="' . wp_nonce_url( add_query_arg( array( 'revision' => $revision->ID, 'action' => 'restore' ) ), "restore-post_$post->ID|$revision->ID" ) . '">' . __( 'Restore' ) . '</a>';
|
||||||
else
|
else
|
||||||
$actions = '';
|
$actions = '';
|
||||||
|
|
||||||
$rows .= "<tr$class>\n";
|
$rows .= "<tr$class>\n";
|
||||||
$rows .= "\t<th style='white-space: nowrap' scope='row'><input type='radio' name='left' value='$revision->ID'$left_checked />\n";
|
$rows .= "\t<th style='white-space: nowrap' scope='row'><input type='radio' name='left' value='$revision->ID'$left_checked /></th>\n";
|
||||||
$rows .= "\t<th style='white-space: nowrap' scope='row'><input type='radio' name='right' value='$revision->ID'$right_checked /></th>\n";
|
$rows .= "\t<th style='white-space: nowrap' scope='row'><input type='radio' name='right' value='$revision->ID'$right_checked /></th>\n";
|
||||||
$rows .= "\t<td>$date</td>\n";
|
$rows .= "\t<td>$date</td>\n";
|
||||||
$rows .= "\t<td>$name</td>\n";
|
$rows .= "\t<td>$name</td>\n";
|
||||||
|
Loading…
Reference in New Issue
Block a user