2008-04-19 01:38:21 +02:00
< ? php
2008-08-16 09:27:34 +02:00
/**
2013-09-13 00:59:08 +02:00
* Revisions administration panel
2013-10-25 04:29:52 +02:00
*
2013-09-13 00:59:08 +02:00
* Requires wp - admin / includes / revision . php .
2008-08-16 09:27:34 +02:00
*
* @ package WordPress
* @ subpackage Administration
2013-09-13 00:59:08 +02:00
* @ since 2.6 . 0
2013-10-25 04:29:52 +02:00
*
2013-09-13 00:59:08 +02:00
* @ param int revision Optional . The revision ID .
* @ param string action The action to take .
2013-10-25 04:29:52 +02:00
* Accepts 'restore' , 'view' or 'edit' .
2013-09-13 00:59:08 +02:00
* @ param int from The revision to compare from .
* @ param int to Optional , required if revision missing . The revision to compare to .
2008-08-16 09:27:34 +02:00
*/
2008-04-19 01:38:21 +02:00
2008-08-16 09:27:34 +02:00
/** WordPress Administration Bootstrap */
2013-09-25 02:18:11 +02:00
require_once ( dirname ( __FILE__ ) . '/admin.php' );
2013-06-26 23:06:50 +02:00
require ABSPATH . 'wp-admin/includes/revision.php' ;
2013-07-12 00:56:48 +02:00
wp_reset_vars ( array ( 'revision' , 'action' , 'from' , 'to' ) );
2010-01-18 12:44:51 +01:00
2013-03-07 16:32:26 +01:00
$revision_id = absint ( $revision );
2013-07-12 16:01:39 +02:00
$from = is_numeric ( $from ) ? absint ( $from ) : null ;
2013-07-12 00:56:48 +02:00
if ( ! $revision_id )
$revision_id = absint ( $to );
2010-01-18 12:44:51 +01:00
$redirect = 'edit.php' ;
2008-04-19 01:38:21 +02:00
2014-05-19 07:04:16 +02:00
switch ( $action ) {
2008-05-08 19:25:07 +02:00
case 'restore' :
2013-03-07 16:32:26 +01:00
if ( ! $revision = wp_get_post_revision ( $revision_id ) )
2008-05-08 19:25:07 +02:00
break ;
2013-03-21 16:54:11 +01:00
2013-03-07 16:32:26 +01:00
if ( ! current_user_can ( 'edit_post' , $revision -> post_parent ) )
2008-05-08 19:25:07 +02:00
break ;
2013-03-21 16:54:11 +01:00
2013-03-07 16:32:26 +01:00
if ( ! $post = get_post ( $revision -> post_parent ) )
2008-05-08 19:25:07 +02:00
break ;
2008-04-19 01:38:21 +02:00
2013-07-24 08:08:14 +02:00
// Revisions disabled (previously checked autosaves && ! wp_is_post_autosave( $revision ))
2013-06-07 04:06:22 +02:00
if ( ! wp_revisions_enabled ( $post ) ) {
2010-05-19 20:36:52 +02:00
$redirect = 'edit.php?post_type=' . $post -> post_type ;
2008-05-30 00:21:36 +02:00
break ;
2010-05-19 20:36:52 +02:00
}
2008-05-08 19:25:07 +02:00
2013-07-28 23:51:44 +02:00
// Don't allow revision restore when post is locked
if ( wp_check_post_lock ( $post -> ID ) )
break ;
2013-03-21 16:54:11 +01:00
check_admin_referer ( " restore-post_ { $revision -> ID } " );
2013-03-07 16:32:26 +01:00
2008-05-30 00:21:36 +02:00
wp_restore_post_revision ( $revision -> ID );
2008-05-08 19:25:07 +02:00
$redirect = add_query_arg ( array ( 'message' => 5 , 'revision' => $revision -> ID ), get_edit_post_link ( $post -> ID , 'url' ) );
break ;
case 'view' :
2013-02-28 16:14:34 +01:00
case 'edit' :
2008-05-08 19:25:07 +02:00
default :
2013-03-07 16:32:26 +01:00
if ( ! $revision = wp_get_post_revision ( $revision_id ) )
2008-05-08 19:25:07 +02:00
break ;
2013-03-07 16:32:26 +01:00
if ( ! $post = get_post ( $revision -> post_parent ) )
2008-05-08 19:25:07 +02:00
break ;
2016-06-21 16:32:27 +02:00
if ( ! current_user_can ( 'read_post' , $revision -> ID ) || ! current_user_can ( 'edit_post' , $revision -> post_parent ) )
2008-05-08 19:25:07 +02:00
break ;
2010-05-19 20:36:52 +02:00
// Revisions disabled and we're not looking at an autosave
2013-03-27 19:11:56 +01:00
if ( ! wp_revisions_enabled ( $post ) && ! wp_is_post_autosave ( $revision ) ) {
2010-05-19 20:36:52 +02:00
$redirect = 'edit.php?post_type=' . $post -> post_type ;
2008-05-30 00:21:36 +02:00
break ;
2010-05-19 20:36:52 +02:00
}
2010-01-18 12:44:51 +01:00
2014-03-03 20:50:15 +01:00
$post_edit_link = get_edit_post_link ();
$post_title = '<a href="' . $post_edit_link . '">' . _draft_or_post_title () . '</a>' ;
2015-06-27 17:41:25 +02:00
$h1 = sprintf ( __ ( 'Compare Revisions of “%1$s”' ), $post_title );
2015-09-09 05:23:23 +02:00
$return_to_post = '<a href="' . $post_edit_link . '">' . __ ( '← Return to editor' ) . '</a>' ;
2014-03-03 20:50:15 +01:00
$title = __ ( 'Revisions' );
2008-05-08 19:25:07 +02:00
$redirect = false ;
break ;
2014-05-19 07:04:16 +02:00
}
2008-04-19 01:38:21 +02:00
2010-05-19 20:36:52 +02:00
// Empty post_type means either malformed object found, or no valid parent was found.
2013-03-07 16:32:26 +01:00
if ( ! $redirect && empty ( $post -> post_type ) )
2010-05-19 20:36:52 +02:00
$redirect = 'edit.php' ;
2008-05-09 17:59:17 +02:00
2013-03-07 16:32:26 +01:00
if ( ! empty ( $redirect ) ) {
2008-05-08 19:25:07 +02:00
wp_redirect ( $redirect );
2008-04-19 01:38:21 +02:00
exit ;
}
2010-01-18 12:44:51 +01:00
// This is so that the correct "Edit" menu item is selected.
2013-03-07 16:32:26 +01:00
if ( ! empty ( $post -> post_type ) && 'post' != $post -> post_type )
2010-01-18 12:44:51 +01:00
$parent_file = $submenu_file = 'edit.php?post_type=' . $post -> post_type ;
else
$parent_file = $submenu_file = 'edit.php' ;
2008-04-19 01:38:21 +02:00
2013-04-04 17:49:28 +02:00
wp_enqueue_script ( 'revisions' );
2013-07-12 00:56:48 +02:00
wp_localize_script ( 'revisions' , '_wpRevisionsSettings' , wp_prepare_revisions_for_js ( $post , $revision_id , $from ) );
2013-03-21 16:54:11 +01:00
2013-05-04 01:00:14 +02:00
/* Revisions Help Tab */
$revisions_overview = '<p>' . __ ( 'This screen is used for managing your content revisions.' ) . '</p>' ;
$revisions_overview .= '<p>' . __ ( 'Revisions are saved copies of your post or page, which are periodically created as you update your content. The red text on the left shows the content that was removed. The green text on the right shows the content that was added.' ) . '</p>' ;
$revisions_overview .= '<p>' . __ ( 'From this screen you can review, compare, and restore revisions:' ) . '</p>' ;
2013-05-09 12:07:26 +02:00
$revisions_overview .= '<ul><li>' . __ ( 'To navigate between revisions, <strong>drag the slider handle left or right</strong> or <strong>use the Previous or Next buttons</strong>.' ) . '</li>' ;
2013-07-31 17:27:02 +02:00
$revisions_overview .= '<li>' . __ ( 'Compare two different revisions by <strong>selecting the “Compare any two revisions” box</strong> to the side.' ) . '</li>' ;
2013-05-04 01:00:14 +02:00
$revisions_overview .= '<li>' . __ ( 'To restore a revision, <strong>click Restore This Revision</strong>.' ) . '</li></ul>' ;
get_current_screen () -> add_help_tab ( array (
'id' => 'revisions-overview' ,
'title' => __ ( 'Overview' ),
'content' => $revisions_overview
) );
$revisions_sidebar = '<p><strong>' . __ ( 'For more information:' ) . '</strong></p>' ;
2015-04-12 23:29:32 +02:00
$revisions_sidebar .= '<p>' . __ ( '<a href="https://codex.wordpress.org/Revision_Management" target="_blank">Revisions Management</a>' ) . '</p>' ;
2014-03-08 05:14:15 +01:00
$revisions_sidebar .= '<p>' . __ ( '<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>' ) . '</p>' ;
2013-05-04 01:00:14 +02:00
get_current_screen () -> set_help_sidebar ( $revisions_sidebar );
2013-09-25 02:18:11 +02:00
require_once ( ABSPATH . 'wp-admin/admin-header.php' );
2013-04-04 17:49:28 +02:00
2013-03-07 16:32:26 +01:00
?>
2008-04-19 01:38:21 +02:00
2013-02-28 16:14:34 +01:00
< div class = " wrap " >
2015-06-27 17:41:25 +02:00
< h1 class = " long-header " >< ? php echo $h1 ; ?> </h1>
2014-03-03 20:50:15 +01:00
< ? php echo $return_to_post ; ?>
2013-06-26 23:06:50 +02:00
</ div >
2008-05-30 01:16:11 +02:00
< ? php
2014-11-01 01:15:24 +01:00
wp_print_revision_templates ();
2013-09-25 02:18:11 +02:00
require_once ( ABSPATH . 'wp-admin/admin-footer.php' );