[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-admin/ -> revision.php (source)

   1  <?php
   2  /**
   3   * Revisions administration panel
   4   *
   5   * Requires wp-admin/includes/revision.php.
   6   *
   7   * @package WordPress
   8   * @subpackage Administration
   9   * @since 2.6.0
  10   */
  11  
  12  /** WordPress Administration Bootstrap */
  13  require_once  __DIR__ . '/admin.php';
  14  
  15  require  ABSPATH . 'wp-admin/includes/revision.php';
  16  
  17  /**
  18   * @global int    $revision_id Optional. The revision ID.
  19   * @global string $action      The action to take. Accepts 'restore', 'view', or 'edit'.
  20   * @global int    $from        The revision to compare from.
  21   * @global int    $to          Optional, required if revision missing. The revision to compare to.
  22   */
  23  
  24  $revision_id = ! empty( $_REQUEST['revision'] ) ? absint( $_REQUEST['revision'] ) : 0;
  25  $action      = ! empty( $_REQUEST['action'] ) ? sanitize_text_field( $_REQUEST['action'] ) : '';
  26  $from        = ! empty( $_REQUEST['from'] ) && is_numeric( $_REQUEST['from'] ) ? absint( $_REQUEST['from'] ) : null;
  27  $to          = ! empty( $_REQUEST['to'] ) && is_numeric( $_REQUEST['to'] ) ? absint( $_REQUEST['to'] ) : null;
  28  
  29  if ( ! $revision_id ) {
  30      $revision_id = $to;
  31  }
  32  
  33  $redirect = 'edit.php';
  34  
  35  switch ( $action ) {
  36      case 'restore':
  37          $revision = wp_get_post_revision( $revision_id );
  38          if ( ! $revision ) {
  39              break;
  40          }
  41  
  42          if ( ! current_user_can( 'edit_post', $revision->post_parent ) ) {
  43              break;
  44          }
  45  
  46          $post = get_post( $revision->post_parent );
  47          if ( ! $post ) {
  48              break;
  49          }
  50  
  51          // Don't restore if revisions are disabled and this is not an autosave.
  52          if ( ! wp_revisions_enabled( $post ) && ! wp_is_post_autosave( $revision ) ) {
  53              $redirect = 'edit.php?post_type=' . $post->post_type;
  54              break;
  55          }
  56  
  57          // Don't restore if the post is locked.
  58          if ( wp_check_post_lock( $post->ID ) ) {
  59              break;
  60          }
  61  
  62          check_admin_referer( "restore-post_{$revision->ID}" );
  63  
  64          /*
  65           * Ensure the global $post remains the same after revision is restored.
  66           * Because wp_insert_post() and wp_transition_post_status() are called
  67           * during the process, plugins can unexpectedly modify $post.
  68           */
  69          $backup_global_post = clone $post;
  70  
  71          wp_restore_post_revision( $revision->ID );
  72  
  73          // Restore the global $post as it was before.
  74          $post = $backup_global_post;
  75  
  76          $redirect = add_query_arg(
  77              array(
  78                  'message'  => 5,
  79                  'revision' => $revision->ID,
  80              ),
  81              get_edit_post_link( $post->ID, 'url' )
  82          );
  83          break;
  84      case 'view':
  85      case 'edit':
  86      default:
  87          $revision = wp_get_post_revision( $revision_id );
  88          if ( ! $revision ) {
  89              break;
  90          }
  91  
  92          $post = get_post( $revision->post_parent );
  93          if ( ! $post ) {
  94              break;
  95          }
  96  
  97          if ( ! current_user_can( 'read_post', $revision->ID ) || ! current_user_can( 'edit_post', $revision->post_parent ) ) {
  98              break;
  99          }
 100  
 101          // Bail if revisions are disabled and this is not an autosave.
 102          if ( ! wp_revisions_enabled( $post ) && ! wp_is_post_autosave( $revision ) ) {
 103              $redirect = 'edit.php?post_type=' . $post->post_type;
 104              break;
 105          }
 106  
 107          $post_edit_link = get_edit_post_link();
 108          $post_title     = '<a href="' . esc_url( $post_edit_link ) . '">' . _draft_or_post_title() . '</a>';
 109          /* translators: %s: Post title. */
 110          $h1             = sprintf( __( 'Compare Revisions of &#8220;%s&#8221;' ), $post_title );
 111          $return_to_post = '<a href="' . esc_url( $post_edit_link ) . '">' . __( '&larr; Go to editor' ) . '</a>';
 112          // Used in the HTML title tag.
 113          $title = __( 'Revisions' );
 114  
 115          $redirect = false;
 116          break;
 117  }
 118  
 119  // Empty post_type means either malformed object found, or no valid parent was found.
 120  if ( ! $redirect && empty( $post->post_type ) ) {
 121      $redirect = 'edit.php';
 122  }
 123  
 124  if ( ! empty( $redirect ) ) {
 125      wp_redirect( $redirect );
 126      exit;
 127  }
 128  
 129  // This is so that the correct "Edit" menu item is selected.
 130  if ( ! empty( $post->post_type ) && 'post' !== $post->post_type ) {
 131      $parent_file = 'edit.php?post_type=' . $post->post_type;
 132  } else {
 133      $parent_file = 'edit.php';
 134  }
 135  $submenu_file = $parent_file;
 136  
 137  wp_enqueue_script( 'revisions' );
 138  wp_localize_script( 'revisions', '_wpRevisionsSettings', wp_prepare_revisions_for_js( $post, $revision_id, $from ) );
 139  
 140  /* Revisions Help Tab */
 141  
 142  $revisions_overview  = '<p>' . __( 'This screen is used for managing your content revisions.' ) . '</p>';
 143  $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>';
 144  $revisions_overview .= '<p>' . __( 'From this screen you can review, compare, and restore revisions:' ) . '</p>';
 145  $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>';
 146  $revisions_overview .= '<li>' . __( 'Compare two different revisions by <strong>selecting the &#8220;Compare any two revisions&#8221; box</strong> to the side.' ) . '</li>';
 147  $revisions_overview .= '<li>' . __( 'To restore a revision, <strong>click Restore This Revision</strong>.' ) . '</li></ul>';
 148  
 149  get_current_screen()->add_help_tab(
 150      array(
 151          'id'      => 'revisions-overview',
 152          'title'   => __( 'Overview' ),
 153          'content' => $revisions_overview,
 154      )
 155  );
 156  
 157  $revisions_sidebar  = '<p><strong>' . __( 'For more information:' ) . '</strong></p>';
 158  $revisions_sidebar .= '<p>' . __( '<a href="https://wordpress.org/documentation/article/revisions/">Revisions Management</a>' ) . '</p>';
 159  $revisions_sidebar .= '<p>' . __( '<a href="https://wordpress.org/support/forums/">Support forums</a>' ) . '</p>';
 160  
 161  get_current_screen()->set_help_sidebar( $revisions_sidebar );
 162  
 163  require_once  ABSPATH . 'wp-admin/admin-header.php';
 164  
 165  ?>
 166  
 167  <div class="wrap">
 168      <h1 class="long-header"><?php echo $h1; ?></h1>
 169      <?php echo $return_to_post; ?>
 170  </div>
 171  <?php
 172  wp_print_revision_templates();
 173  
 174  require_once  ABSPATH . 'wp-admin/admin-footer.php';


Generated : Fri Oct 10 08:20:03 2025 Cross-referenced by PHPXref