[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

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( dirname( __FILE__ ) . '/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          // Restore if revisions are enabled or this is 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 allow revision restore when 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          wp_restore_post_revision( $revision->ID );
  64          $redirect = add_query_arg(
  65              array(
  66                  'message'  => 5,
  67                  'revision' => $revision->ID,
  68              ),
  69              get_edit_post_link( $post->ID, 'url' )
  70          );
  71          break;
  72      case 'view':
  73      case 'edit':
  74      default:
  75          $revision = wp_get_post_revision( $revision_id );
  76          if ( ! $revision ) {
  77              break;
  78          }
  79  
  80          $post = get_post( $revision->post_parent );
  81          if ( ! $post ) {
  82              break;
  83          }
  84  
  85          if ( ! current_user_can( 'read_post', $revision->ID ) || ! current_user_can( 'edit_post', $revision->post_parent ) ) {
  86              break;
  87          }
  88  
  89          // Revisions disabled and we're not looking at an autosave
  90          if ( ! wp_revisions_enabled( $post ) && ! wp_is_post_autosave( $revision ) ) {
  91              $redirect = 'edit.php?post_type=' . $post->post_type;
  92              break;
  93          }
  94  
  95          $post_edit_link = get_edit_post_link();
  96          $post_title     = '<a href="' . $post_edit_link . '">' . _draft_or_post_title() . '</a>';
  97          /* translators: %s: Post title. */
  98          $h1             = sprintf( __( 'Compare Revisions of &#8220;%s&#8221;' ), $post_title );
  99          $return_to_post = '<a href="' . $post_edit_link . '">' . __( '&larr; Return to editor' ) . '</a>';
 100          $title          = __( 'Revisions' );
 101  
 102          $redirect = false;
 103          break;
 104  }
 105  
 106  // Empty post_type means either malformed object found, or no valid parent was found.
 107  if ( ! $redirect && empty( $post->post_type ) ) {
 108      $redirect = 'edit.php';
 109  }
 110  
 111  if ( ! empty( $redirect ) ) {
 112      wp_redirect( $redirect );
 113      exit;
 114  }
 115  
 116  // This is so that the correct "Edit" menu item is selected.
 117  if ( ! empty( $post->post_type ) && 'post' != $post->post_type ) {
 118      $parent_file = 'edit.php?post_type=' . $post->post_type;
 119  } else {
 120      $parent_file = 'edit.php';
 121  }
 122  $submenu_file = $parent_file;
 123  
 124  wp_enqueue_script( 'revisions' );
 125  wp_localize_script( 'revisions', '_wpRevisionsSettings', wp_prepare_revisions_for_js( $post, $revision_id, $from ) );
 126  
 127  /* Revisions Help Tab */
 128  
 129  $revisions_overview  = '<p>' . __( 'This screen is used for managing your content revisions.' ) . '</p>';
 130  $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>';
 131  $revisions_overview .= '<p>' . __( 'From this screen you can review, compare, and restore revisions:' ) . '</p>';
 132  $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>';
 133  $revisions_overview .= '<li>' . __( 'Compare two different revisions by <strong>selecting the &#8220;Compare any two revisions&#8221; box</strong> to the side.' ) . '</li>';
 134  $revisions_overview .= '<li>' . __( 'To restore a revision, <strong>click Restore This Revision</strong>.' ) . '</li></ul>';
 135  
 136  get_current_screen()->add_help_tab(
 137      array(
 138          'id'      => 'revisions-overview',
 139          'title'   => __( 'Overview' ),
 140          'content' => $revisions_overview,
 141      )
 142  );
 143  
 144  $revisions_sidebar  = '<p><strong>' . __( 'For more information:' ) . '</strong></p>';
 145  $revisions_sidebar .= '<p>' . __( '<a href="https://wordpress.org/support/article/revisions/">Revisions Management</a>' ) . '</p>';
 146  $revisions_sidebar .= '<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>';
 147  
 148  get_current_screen()->set_help_sidebar( $revisions_sidebar );
 149  
 150  require_once ( ABSPATH . 'wp-admin/admin-header.php' );
 151  
 152  ?>
 153  
 154  <div class="wrap">
 155      <h1 class="long-header"><?php echo $h1; ?></h1>
 156      <?php echo $return_to_post; ?>
 157  </div>
 158  <?php
 159  wp_print_revision_templates();
 160  
 161  require_once ( ABSPATH . 'wp-admin/admin-footer.php' );


Generated: Sat Nov 23 20:47:33 2019 Cross-referenced by PHPXref 0.7