[ 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; Go to editor' ) . '</a>';
 111          // Used in the HTML title tag.
 112          $title = __( 'Revisions' );
 113  
 114          $redirect = false;
 115          break;
 116  }
 117  
 118  // Empty post_type means either malformed object found, or no valid parent was found.
 119  if ( ! $redirect && empty( $post->post_type ) ) {
 120      $redirect = 'edit.php';
 121  }
 122  
 123  if ( ! empty( $redirect ) ) {
 124      wp_redirect( $redirect );
 125      exit;
 126  }
 127  
 128  // This is so that the correct "Edit" menu item is selected.
 129  if ( ! empty( $post->post_type ) && 'post' !== $post->post_type ) {
 130      $parent_file = 'edit.php?post_type=' . $post->post_type;
 131  } else {
 132      $parent_file = 'edit.php';
 133  }
 134  $submenu_file = $parent_file;
 135  
 136  wp_enqueue_script( 'revisions' );
 137  wp_localize_script( 'revisions', '_wpRevisionsSettings', wp_prepare_revisions_for_js( $post, $revision_id, $from ) );
 138  
 139  /* Revisions Help Tab */
 140  
 141  $revisions_overview  = '<p>' . __( 'This screen is used for managing your content revisions.' ) . '</p>';
 142  $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>';
 143  $revisions_overview .= '<p>' . __( 'From this screen you can review, compare, and restore revisions:' ) . '</p>';
 144  $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>';
 145  $revisions_overview .= '<li>' . __( 'Compare two different revisions by <strong>selecting the &#8220;Compare any two revisions&#8221; box</strong> to the side.' ) . '</li>';
 146  $revisions_overview .= '<li>' . __( 'To restore a revision, <strong>click Restore This Revision</strong>.' ) . '</li></ul>';
 147  
 148  get_current_screen()->add_help_tab(
 149      array(
 150          'id'      => 'revisions-overview',
 151          'title'   => __( 'Overview' ),
 152          'content' => $revisions_overview,
 153      )
 154  );
 155  
 156  $revisions_sidebar  = '<p><strong>' . __( 'For more information:' ) . '</strong></p>';
 157  $revisions_sidebar .= '<p>' . __( '<a href="https://wordpress.org/support/article/revisions/">Revisions Management</a>' ) . '</p>';
 158  $revisions_sidebar .= '<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>';
 159  
 160  get_current_screen()->set_help_sidebar( $revisions_sidebar );
 161  
 162  require_once ABSPATH . 'wp-admin/admin-header.php';
 163  
 164  ?>
 165  
 166  <div class="wrap">
 167      <h1 class="long-header"><?php echo $h1; ?></h1>
 168      <?php echo $return_to_post; ?>
 169  </div>
 170  <?php
 171  wp_print_revision_templates();
 172  
 173  require_once ABSPATH . 'wp-admin/admin-footer.php';


Generated: Sat Dec 21 01:00:02 2024 Cross-referenced by PHPXref 0.7.1