[ Index ]

PHP Cross Reference of WordPress

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


Generated: Thu Sep 24 01:02:16 2020 Cross-referenced by PHPXref 0.7.1