2008-04-18 19:38:21 -04:00
< ? php
2008-08-16 03:27:34 -04:00
/**
2013-09-12 18:59:08 -04:00
* Revisions administration panel
2013-10-24 22:29:52 -04:00
*
2013-09-12 18:59:08 -04:00
* Requires wp - admin / includes / revision . php .
2008-08-16 03:27:34 -04:00
*
* @ package WordPress
* @ subpackage Administration
2013-09-12 18:59:08 -04:00
* @ since 2.6 . 0
2013-10-24 22:29:52 -04:00
*
2013-09-12 18:59:08 -04:00
* @ param int revision Optional . The revision ID .
* @ param string action The action to take .
2013-10-24 22:29:52 -04:00
* Accepts 'restore' , 'view' or 'edit' .
2013-09-12 18:59:08 -04: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 03:27:34 -04:00
*/
2008-04-18 19:38:21 -04:00
2008-08-16 03:27:34 -04:00
/** WordPress Administration Bootstrap */
2013-09-24 20:18:11 -04:00
require_once ( dirname ( __FILE__ ) . '/admin.php' );
2013-06-26 17:06:50 -04:00
require ABSPATH . 'wp-admin/includes/revision.php' ;
2013-07-11 18:56:48 -04:00
wp_reset_vars ( array ( 'revision' , 'action' , 'from' , 'to' ) );
2010-01-18 06:44:51 -05:00
2013-03-07 10:32:26 -05:00
$revision_id = absint ( $revision );
2013-07-12 10:01:39 -04:00
$from = is_numeric ( $from ) ? absint ( $from ) : null ;
2013-07-11 18:56:48 -04:00
if ( ! $revision_id )
$revision_id = absint ( $to );
2010-01-18 06:44:51 -05:00
$redirect = 'edit.php' ;
2008-04-18 19:38:21 -04:00
2014-05-19 01:04:16 -04:00
switch ( $action ) {
2008-05-08 13:25:07 -04:00
case 'restore' :
2013-03-07 10:32:26 -05:00
if ( ! $revision = wp_get_post_revision ( $revision_id ) )
2008-05-08 13:25:07 -04:00
break ;
2013-03-21 11:54:11 -04:00
2013-03-07 10:32:26 -05:00
if ( ! current_user_can ( 'edit_post' , $revision -> post_parent ) )
2008-05-08 13:25:07 -04:00
break ;
2013-03-21 11:54:11 -04:00
2013-03-07 10:32:26 -05:00
if ( ! $post = get_post ( $revision -> post_parent ) )
2008-05-08 13:25:07 -04:00
break ;
2008-04-18 19:38:21 -04:00
2016-07-07 21:16:31 -04:00
// Restore if revisions are enabled or this is an autosave.
if ( ! wp_revisions_enabled ( $post ) && ! wp_is_post_autosave ( $revision ) ) {
2010-05-19 14:36:52 -04:00
$redirect = 'edit.php?post_type=' . $post -> post_type ;
2008-05-29 18:21:36 -04:00
break ;
2010-05-19 14:36:52 -04:00
}
2008-05-08 13:25:07 -04:00
2013-07-28 17:51:44 -04:00
// Don't allow revision restore when post is locked
if ( wp_check_post_lock ( $post -> ID ) )
break ;
2013-03-21 11:54:11 -04:00
check_admin_referer ( " restore-post_ { $revision -> ID } " );
2013-03-07 10:32:26 -05:00
2008-05-29 18:21:36 -04:00
wp_restore_post_revision ( $revision -> ID );
2008-05-08 13:25:07 -04:00
$redirect = add_query_arg ( array ( 'message' => 5 , 'revision' => $revision -> ID ), get_edit_post_link ( $post -> ID , 'url' ) );
break ;
case 'view' :
2013-02-28 10:14:34 -05:00
case 'edit' :
2008-05-08 13:25:07 -04:00
default :
2013-03-07 10:32:26 -05:00
if ( ! $revision = wp_get_post_revision ( $revision_id ) )
2008-05-08 13:25:07 -04:00
break ;
2013-03-07 10:32:26 -05:00
if ( ! $post = get_post ( $revision -> post_parent ) )
2008-05-08 13:25:07 -04:00
break ;
2016-06-21 10:22:26 -04:00
if ( ! current_user_can ( 'read_post' , $revision -> ID ) || ! current_user_can ( 'edit_post' , $revision -> post_parent ) )
2008-05-08 13:25:07 -04:00
break ;
2010-05-19 14:36:52 -04:00
// Revisions disabled and we're not looking at an autosave
2013-03-27 14:11:56 -04:00
if ( ! wp_revisions_enabled ( $post ) && ! wp_is_post_autosave ( $revision ) ) {
2010-05-19 14:36:52 -04:00
$redirect = 'edit.php?post_type=' . $post -> post_type ;
2008-05-29 18:21:36 -04:00
break ;
2010-05-19 14:36:52 -04:00
}
2010-01-18 06:44:51 -05:00
2014-03-03 14:50:15 -05:00
$post_edit_link = get_edit_post_link ();
$post_title = '<a href="' . $post_edit_link . '">' . _draft_or_post_title () . '</a>' ;
2016-11-20 20:22:32 -05:00
/* translators: 1: Post title */
2015-06-27 11:41:25 -04:00
$h1 = sprintf ( __ ( 'Compare Revisions of “%1$s”' ), $post_title );
2015-09-08 23:23:23 -04:00
$return_to_post = '<a href="' . $post_edit_link . '">' . __ ( '← Return to editor' ) . '</a>' ;
2014-03-03 14:50:15 -05:00
$title = __ ( 'Revisions' );
2008-05-08 13:25:07 -04:00
$redirect = false ;
break ;
2014-05-19 01:04:16 -04:00
}
2008-04-18 19:38:21 -04:00
2010-05-19 14:36:52 -04:00
// Empty post_type means either malformed object found, or no valid parent was found.
2013-03-07 10:32:26 -05:00
if ( ! $redirect && empty ( $post -> post_type ) )
2010-05-19 14:36:52 -04:00
$redirect = 'edit.php' ;
2008-05-09 11:59:17 -04:00
2013-03-07 10:32:26 -05:00
if ( ! empty ( $redirect ) ) {
2008-05-08 13:25:07 -04:00
wp_redirect ( $redirect );
2008-04-18 19:38:21 -04:00
exit ;
}
2010-01-18 06:44:51 -05:00
// This is so that the correct "Edit" menu item is selected.
2013-03-07 10:32:26 -05:00
if ( ! empty ( $post -> post_type ) && 'post' != $post -> post_type )
2010-01-18 06:44:51 -05:00
$parent_file = $submenu_file = 'edit.php?post_type=' . $post -> post_type ;
else
$parent_file = $submenu_file = 'edit.php' ;
2008-04-18 19:38:21 -04:00
2013-04-04 11:49:28 -04:00
wp_enqueue_script ( 'revisions' );
2013-07-11 18:56:48 -04:00
wp_localize_script ( 'revisions' , '_wpRevisionsSettings' , wp_prepare_revisions_for_js ( $post , $revision_id , $from ) );
2013-03-21 11:54:11 -04:00
2013-05-03 19:00:14 -04: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 06:07:26 -04: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 11:27:02 -04:00
$revisions_overview .= '<li>' . __ ( 'Compare two different revisions by <strong>selecting the “Compare any two revisions” box</strong> to the side.' ) . '</li>' ;
2013-05-03 19:00:14 -04: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>' ;
2016-10-04 03:08:29 -04:00
$revisions_sidebar .= '<p>' . __ ( '<a href="https://codex.wordpress.org/Revision_Management">Revisions Management</a>' ) . '</p>' ;
$revisions_sidebar .= '<p>' . __ ( '<a href="https://wordpress.org/support/">Support Forums</a>' ) . '</p>' ;
2013-05-03 19:00:14 -04:00
get_current_screen () -> set_help_sidebar ( $revisions_sidebar );
2013-09-24 20:18:11 -04:00
require_once ( ABSPATH . 'wp-admin/admin-header.php' );
2013-04-04 11:49:28 -04:00
2013-03-07 10:32:26 -05:00
?>
2008-04-18 19:38:21 -04:00
2013-02-28 10:14:34 -05:00
< div class = " wrap " >
2015-06-27 11:41:25 -04:00
< h1 class = " long-header " >< ? php echo $h1 ; ?> </h1>
2014-03-03 14:50:15 -05:00
< ? php echo $return_to_post ; ?>
2013-06-26 17:06:50 -04:00
</ div >
2008-05-29 19:16:11 -04:00
< ? php
2014-10-31 20:15:24 -04:00
wp_print_revision_templates ();
2013-09-24 20:18:11 -04:00
require_once ( ABSPATH . 'wp-admin/admin-footer.php' );