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


Generated : Thu May 9 08:20:02 2024 Cross-referenced by PHPXref