/**
  * Ajax callback to handle deleting the revision, then redirecting
  * back to the post edit page with a confirmation message.
  */
 public function revision_delete_action()
 {
     /**
      * Bail if required values unset.
      */
     if (!isset($_GET['revision'])) {
         return;
     }
     $revision_id = sanitize_key($_GET['revision']);
     /**
      * Verify revision ID valud.
      */
     if (!($revision = wp_get_post_revision($revision_id))) {
         break;
     }
     /**
      * Verify parent post valid.
      */
     if (!($post = get_post($revision->post_parent))) {
         break;
     }
     /**
      * Verify current user can edit parent post.
      */
     if (!current_user_can('edit_post', $post)) {
         break;
     }
     /**
      * Verify revisions not disabled and we're not looking at an autosave.
      */
     if (!constant('WP_POST_REVISIONS') && !wp_is_post_autosave($revision)) {
         break;
     }
     /**
      * Check the nonce.
      */
     check_admin_referer("delete-revision_{$post->ID}|{$revision->ID}");
     /**
      * Every checks out, delete the revision.
      */
     wp_delete_post_revision($revision->ID);
     wp_redirect(add_query_arg(array('message' => 99, 'revision' => $revision->ID), get_edit_post_link($post->ID, 'url')));
     exit;
 }
/**
 * Deletes a revision.
 *
 * Deletes the row from the posts table corresponding to the specified revision.
 *
 * @since 2.6.0
 *
 * @param int|WP_Post $revision_id Revision ID or revision object.
 * @return array|false|WP_Post|WP_Error|null Null or WP_Error if error, deleted post if success.
 */
function wp_delete_post_revision($revision_id)
{
    if (!($revision = wp_get_post_revision($revision_id))) {
        return $revision;
    }
    $delete = wp_delete_post($revision->ID);
    if ($delete) {
        /**
         * Fires once a post revision has been deleted.
         *
         * @since 2.6.0
         *
         * @param int          $revision_id Post revision ID.
         * @param object|array $revision    Post revision object or array.
         */
        do_action('wp_delete_post_revision', $revision->ID, $revision);
    }
    return $delete;
}
     if (!wp_revisions_enabled($post)) {
         $redirect = 'edit.php?post_type=' . $post->post_type;
         break;
     }
     // Don't allow revision restore when post is locked
     if (wp_check_post_lock($post->ID)) {
         break;
     }
     check_admin_referer("restore-post_{$revision->ID}");
     wp_restore_post_revision($revision->ID);
     $redirect = add_query_arg(array('message' => 5, 'revision' => $revision->ID), get_edit_post_link($post->ID, 'url'));
     break;
 case 'view':
 case 'edit':
 default:
     if (!($revision = wp_get_post_revision($revision_id))) {
         break;
     }
     if (!($post = get_post($revision->post_parent))) {
         break;
     }
     if (!current_user_can('read_post', $revision->ID) || !current_user_can('read_post', $post->ID)) {
         break;
     }
     // Revisions disabled and we're not looking at an autosave
     if (!wp_revisions_enabled($post) && !wp_is_post_autosave($revision)) {
         $redirect = 'edit.php?post_type=' . $post->post_type;
         break;
     }
     $post_title = '<a href="' . get_edit_post_link() . '">' . _draft_or_post_title() . '</a>';
     $h2 = sprintf(__('Compare Revisions of &#8220;%1$s&#8221;'), $post_title);
 /**
  * Get an adjacent post revision ID
  *
  * @param int $revision_id
  * @param bool $previous
  *
  * @return int $revision_id
  */
 public function get_adjacent_post_revision($revision_id, $previous = true)
 {
     if (empty($revision_id) || !wp_is_post_revision($revision_id)) {
         return false;
     }
     $revision = wp_get_post_revision($revision_id);
     $operator = $previous ? '<' : '>';
     $order = $previous ? 'DESC' : 'ASC';
     global $wpdb;
     $revision_id = $wpdb->get_var($wpdb->prepare("SELECT p.ID\n\t\t\t\tFROM {$wpdb->posts} AS p\n\t\t\t\tWHERE p.post_date {$operator} %s\n\t\t\t\t\tAND p.post_type = 'revision'\n\t\t\t\t\tAND p.post_parent = %d\n\t\t\t\tORDER BY p.post_date {$order}\n\t\t\t\tLIMIT 1", $revision->post_date, $revision->post_parent));
     $revision_id = absint($revision_id);
     if (!wp_is_post_revision($revision_id)) {
         return false;
     }
     return $revision_id;
 }
Exemple #5
0
/**
 * Deletes a revision.
 *
 * Deletes the row from the posts table corresponding to the specified revision.
 *
 * @package WordPress
 * @subpackage Post_Revisions
 * @since 2.6.0
 *
 * @uses wp_get_post_revision()
 * @uses wp_delete_post()
 *
 * @param int|object $revision_id Revision ID or revision object.
 * @param array $fields Optional. What fields to restore from.  Defaults to all.
 * @return mixed Null if error, false if no fields to restore, (int) post ID if success.
 */
function wp_delete_post_revision( $revision_id ) {
	if ( !$revision = wp_get_post_revision( $revision_id ) )
		return $revision;

	$delete = wp_delete_post( $revision->ID );
	if ( is_wp_error( $delete ) )
		return $delete;

	if ( $delete )
		do_action( 'wp_delete_post_revision', $revision->ID, $revision );

	return $delete;
}
 /**
  * Restore a post revision
  *
  * @since 3.5.0
  *
  * @uses wp_restore_post_revision()
  *
  * @param array $args Method parameters. Contains:
  *  - int     $blog_id
  *  - string  $username
  *  - string  $password
  *  - int     $post_id
  * @return bool false if there was an error restoring, true if success.
  */
 function wp_restoreRevision($args)
 {
     if (!$this->minimum_args($args, 3)) {
         return $this->error;
     }
     $this->escape($args);
     $blog_id = (int) $args[0];
     $username = $args[1];
     $password = $args[2];
     $revision_id = (int) $args[3];
     if (!($user = $this->login($username, $password))) {
         return $this->error;
     }
     do_action('xmlrpc_call', 'wp.restoreRevision');
     if (!($revision = wp_get_post_revision($revision_id))) {
         return new IXR_Error(404, __('Invalid post ID'));
     }
     if (wp_is_post_autosave($revision)) {
         return new IXR_Error(404, __('Invalid post ID'));
     }
     if (!($post = get_post($revision->post_parent))) {
         return new IXR_Error(404, __('Invalid post ID'));
     }
     if (!current_user_can('edit_post', $revision->post_parent)) {
         return new IXR_Error(401, __('Sorry, you cannot edit this post.'));
     }
     // Check if revisions are disabled.
     if (!WP_POST_REVISIONS || !post_type_supports($post->post_type, 'revisions')) {
         return new IXR_Error(401, __('Sorry, revisions are disabled.'));
     }
     $post = wp_restore_post_revision($revision_id);
     return (bool) $post;
 }
Exemple #7
0
 /**
  * If a loop started, check if it's the main query, in which case, add filters to append divs.
  *
  * @since 1.0.0
  * @access public
  *
  * @param WP_Query $wp_query
  */
 function replace_current_with_revision($wp_query)
 {
     if ($wp_query->is_main_query() && isset($_POST['revview_revision_id']) && !empty($_POST['revview_revision_id']) && is_numeric($_POST['revview_revision_id'])) {
         $this->requested_revision = wp_get_post_revision($_POST['revview_revision_id']);
         if ($this->requested_revision instanceof WP_Post) {
             $parent = get_post($this->requested_revision->post_parent);
             if ($parent instanceof WP_Post) {
                 $parent_post_status = get_post_status_object($parent->post_status);
                 /**
                  * Filters the status of the parent entry whose revision was requested.
                  *
                  * @param bool $parent_post_status_public Whether the post status of the parent entry is public or not.
                  * @param int $post The ID of the entry parent of the requested revision.
                  */
                 if (apply_filters('revview_allow_revision_load', $parent_post_status->public && empty($parent->post_password), $parent->ID)) {
                     add_filter('the_title', array($this, 'revview_title'), 0);
                     add_filter('the_content', array($this, 'revview_content'), 0);
                     add_filter('the_excerpt', array($this, 'revview_excerpt'), 0);
                 }
             }
         }
     }
 }
 /**
  * Reads the Webhook payload and syncs posts as necessary
  *
  * @param stdClass $payload
  *
  * @return array
  */
 public function pull($payload)
 {
     if (strtolower($payload->repository->full_name) !== strtolower($this->api->repository())) {
         $msg = strtolower($payload->repository->full_name) . __(' is an invalid repository.', 'wordpress-github-sync');
         WordPress_GitHub_Sync::write_log($msg);
         return array('result' => 'error', 'message' => $msg);
     }
     // the last term in the ref is the branch name
     $refs = explode('/', $payload->ref);
     $branch = array_pop($refs);
     if ('master' !== $branch) {
         $msg = __('Not on the master branch.', 'wordpress-github-sync');
         WordPress_GitHub_Sync::write_log($msg);
         return array('result' => 'error', 'message' => $msg);
     }
     // We add wpghs to commits we push out, so we shouldn't pull them in again
     if ('wpghs' === substr($payload->head_commit->message, -5)) {
         $msg = __('Already synced this commit.', 'wordpress-github-sync');
         WordPress_GitHub_Sync::write_log($msg);
         return array('result' => 'error', 'message' => $msg);
     }
     $commit = $this->api->get_commit($payload->head_commit->id);
     if (is_wp_error($commit)) {
         $msg = sprintf(__('Failed getting commit with error: %s', 'wordpress-github-sync'), $commit->get_error_message());
         WordPress_GitHub_Sync::write_log($msg);
         return array('result' => 'error', 'message' => $msg);
     }
     $import = new WordPress_GitHub_Sync_Import();
     $import->run($commit->tree->sha);
     $user = get_user_by('email', $payload->head_commit->author->email);
     if (!$user) {
         // use the default user
         $user = get_user_by('id', get_option('wpghs_default_user'));
     }
     // if we can't find a user and a default hasn't been set,
     // we're just going to set the revision author to 0
     update_option('_wpghs_export_user_id', $user ? $user->ID : 0);
     global $wpdb;
     if ($updated_posts = $import->updated_posts()) {
         foreach ($updated_posts as $post_id) {
             $revision = wp_get_post_revision($post_id);
             if (!$revision) {
                 $revision = wp_save_post_revision($post_id);
                 if (!$revision || is_wp_error($revision)) {
                     // there was a problem saving a new revision
                     continue;
                 }
                 // wp_save_post_revision returns the ID, whereas get_post_revision returns the whole object
                 // in order to be consistent, let's make sure we have the whole object before continuing
                 $revision = get_post($revision);
             }
             $wpdb->update($wpdb->posts, array('post_author' => (int) get_option('_wpghs_export_user_id')), array('ID' => $revision->ID), array('%d'), array('%d'));
         }
     }
     // Deleting posts from a payload is the only place
     // we need to search posts by path; another way?
     $removed = array();
     foreach ($payload->commits as $commit) {
         $removed = array_merge($removed, $commit->removed);
     }
     foreach (array_unique($removed) as $path) {
         $post = new WordPress_GitHub_Sync_Post($path);
         wp_delete_post($post->id);
     }
     if ($new_posts = $import->new_posts()) {
         // disable the lock to allow exporting
         global $wpghs;
         $wpghs->push_lock = false;
         WordPress_GitHub_Sync::write_log(sprintf(__('Updating new posts with IDs: %s', 'wordpress-github-sync'), implode(', ', $new_posts)));
         foreach ($new_posts as $post_id) {
             $wpdb->update($wpdb->posts, array('post_author' => (int) get_option('_wpghs_export_user_id')), array('ID' => $post_id), array('%d'), array('%d'));
         }
         $msg = apply_filters('wpghs_commit_msg_new_posts', 'Updating new posts from WordPress at ' . site_url() . ' (' . get_bloginfo('name') . ')') . ' - wpghs';
         $export = new WordPress_GitHub_Sync_Export($new_posts, $msg);
         $export->run();
     }
     $msg = __('Payload processed', 'wordpress-github-sync');
     WordPress_GitHub_Sync::write_log($msg);
     return array('result' => 'success', 'message' => $msg);
 }
 /**
  * Determines what the user is trying to do on this page view.
  *
  * This determination is made mostly on the basis of the information passed in the URL
  * parameters. This function is also responsible for some of the object setup (getting the
  * revision post(s), etc).
  *
  * This is cribbed nearly wholesale from wp-admin/revision.php. In the future I would like
  * to clean it up to be less WordPressy and more pluginish.
  *
  * @package BuddyPress Docs
  * @since 1.1
  */
 function setup_action()
 {
     global $bp;
     if (!bp_docs_is_existing_doc()) {
         return;
     }
     wp_enqueue_script('list-revisions');
     $redirect = false;
     switch ($this->action) {
         case 'restore':
             if (!($this->revision = wp_get_post_revision($this->revision_id))) {
                 break;
             }
             if (!current_user_can('bp_docs_edit')) {
                 break;
             }
             if (!($post = get_post($this->revision->post_parent))) {
                 break;
             }
             // Revisions disabled and we're not looking at an autosave
             if (!wp_revisions_enabled($post) && !wp_is_post_autosave($this->revision)) {
                 $redirect = 'edit.php?post_type=' . $post->post_type;
                 break;
             }
             $referer = 'restore-post_' . $post->ID . '|' . $this->revision->ID;
             check_admin_referer($referer);
             wp_restore_post_revision($this->revision->ID);
             bp_core_add_message(sprintf(__('You have successfully restored the Doc to the revision from %s.', 'bp-docs'), $this->revision->post_date));
             $redirect = get_permalink($post->ID) . '/' . BP_DOCS_HISTORY_SLUG . '/';
             break;
         case 'diff':
             if (!($this->left_revision = get_post($this->left))) {
                 break;
             }
             if (!($this->right_revision = get_post($this->right))) {
                 break;
             }
             // Don't allow reverse diffs?
             if (strtotime($this->right_revision->post_modified_gmt) < strtotime($this->left_revision->post_modified_gmt)) {
                 $redirect = add_query_arg(array('left' => $this->right, 'right' => $this->left));
                 break;
             }
             if ($this->left_revision->ID == $this->right_revision->post_parent) {
                 // right is a revision of left
                 $post =& $this->left_revision;
             } elseif ($this->left_revision->post_parent == $this->right_revision->ID) {
                 // left is a revision of right
                 $post =& $this->right_revision;
             } elseif ($this->left_revision->post_parent == $this->right_revision->post_parent) {
                 // both are revisions of common parent
                 $post = get_post($this->left_revision->post_parent);
             } else {
                 break;
             }
             // Don't diff two unrelated revisions
             if (!wp_revisions_enabled($post)) {
                 // Revisions disabled
                 if (!wp_is_post_autosave($this->left_revision) && !wp_is_post_autosave($this->right_revision) || $post->ID !== $this->left_revision->ID && $post->ID !== $this->right_revision->ID) {
                     $redirect = 'edit.php?post_type=' . $post->post_type;
                     break;
                 }
             }
             if ($this->left_revision->ID == $this->right_revision->ID || !wp_get_post_revision($this->left_revision->ID) && !wp_get_post_revision($this->right_revision->ID)) {
                 break;
             }
             $post_title = '<a href="' . get_edit_post_link() . '">' . get_the_title() . '</a>';
             $h2 = sprintf(__('Compare Revisions of &#8220;%1$s&#8221;', 'bp-docs'), $post_title);
             $title = __('Revisions', 'bp-docs');
             $this->left = $this->left_revision->ID;
             $this->right = $this->right_revision->ID;
             $redirect = false;
             break;
         case 'view':
         default:
             if (!($this->revision = wp_get_post_revision($this->revision_id))) {
                 if ($this->revision = get_post($this->revision_id)) {
                     $this->is_latest = true;
                 } else {
                     break;
                 }
             }
             if (!($post = get_post($this->revision->post_parent))) {
                 break;
             }
             // Revisions disabled and we're not looking at an autosave
             if (!wp_revisions_enabled($post) && !wp_is_post_autosave($this->revision)) {
                 $redirect = 'edit.php?post_type=' . $post->post_type;
                 break;
             }
             $post_title = '<a href="' . get_edit_post_link() . '">' . get_the_title() . '</a>';
             $revision_title = wp_post_revision_title($this->revision, false);
             $h2 = sprintf(__('Revision for &#8220;%1$s&#8221; created on %2$s', 'bp-docs'), $post_title, $revision_title);
             $title = __('Revisions', 'bp-docs');
             // Sets up the diff radio buttons
             $this->left = $this->revision->ID;
             $this->right = $post->ID;
             $redirect = false;
             break;
     }
     if ($redirect) {
         bp_core_redirect($redirect);
     }
     $this->setup_is_identical();
 }
function wp_momento_content_filter($content)
{
    if (is_singular() && get_query_var('revision')) {
        // Get the revision id
        $revision_id = get_query_var('revision');
        // Verify that it is a revision
        if (wp_is_post_revision($revision_id)) {
            // Remove the filer to avoid triggering an infinite loop
            remove_filter('the_content', 'wp_momento_content_filter');
            // Query this revision from the database
            $revision_id = get_query_var('revision');
            $revision = wp_get_post_revision($revision_id);
            // Render the content using this older data
            $rev_content = apply_filters('the_content', $revision->post_content);
            // Put the filter override back on so we can use it again
            add_filter('the_content', 'wp_momento_content_filter');
            // Return the revision content
            return $rev_content;
        }
        // If this a normal post and not a revision
        // then nothing special should happen
        if (is_single($revision_id)) {
            return $content;
        }
        // If it's none of the above just return the normal content.
        // Through perhaps we should have this raise a 404 or something.
        return $content;
    } else {
        return $content;
    }
}
add_filter('the_content', function ($content) {
    global $post;
    if (is_admin()) {
        return $content;
    }
    foreach (wpb_block_context() as $post_type) {
        if (get_post_type() == $post_type) {
            $page_blocks = wpb_get_blocks($post->ID);
            if ($page_blocks) {
                ob_start();
                foreach ($page_blocks as $page_block) {
                    if (!isset($page_block['buid']) || !isset($page_block['page_id']) || !isset($page_block['post_id'])) {
                        continue;
                    }
                    if (is_preview() === false && isset($page_block['post_revision_id'])) {
                        $rev = wp_get_post_revision($page_block['post_revision_id']);
                        if ($rev) {
                            $page_block['post_id'] = $rev->ID;
                        }
                    }
                    if ($page_block['into_id'] == 0) {
                        wpb_render_block_template($page_block['buid'], $page_block['post_id'], $page_block['page_id']);
                    }
                }
                $content = ob_get_contents();
                ob_end_clean();
            }
        }
    }
    return $content;
}, 20);
Exemple #12
0
    static function compare_revisions_iframe()
    {
        //add_action('admin_init', 'register_admin_colors', 1);
        set_current_screen('revision-edit');
        $left = isset($_GET['left']) ? absint($_GET['left']) : false;
        $right = isset($_GET['right']) ? absint($_GET['right']) : false;
        if (!($left_revision = get_post($left))) {
            return;
        }
        if (!($right_revision = get_post($right))) {
            return;
        }
        if (!current_user_can('read_post', $left_revision->ID) || !current_user_can('read_post', $right_revision->ID)) {
            return;
        }
        // Don't allow reverse diffs?
        if (strtotime($right_revision->post_modified_gmt) < strtotime($left_revision->post_modified_gmt)) {
            //$redirect = add_query_arg( array( 'left' => $right, 'right' => $left ) );
            // Switch-a-roo
            $temp_revision = $left_revision;
            $left_revision = $right_revision;
            $right_revision = $temp_revision;
            unset($temp_revision);
        }
        global $post;
        if ($left_revision->ID == $right_revision->post_parent) {
            // right is a revision of left
            $post = $left_revision;
        } elseif ($left_revision->post_parent == $right_revision->ID) {
            // left is a revision of right
            $post = $right_revision;
        } elseif ($left_revision->post_parent == $right_revision->post_parent) {
            // both are revisions of common parent
            $post = get_post($left_revision->post_parent);
        } else {
            wp_die(__('Sorry, But you cant compare unrelated Revisions.', 'revision-control'));
        }
        // Don't diff two unrelated revisions
        if ($left_revision->ID == $right_revision->ID || !wp_get_post_revision($left_revision->ID) && !wp_get_post_revision($right_revision->ID)) {
            wp_die(__('Sorry, But you cant compare a Revision to itself.', 'revision-control'));
        }
        $title = sprintf(__('Compare Revisions of &#8220;%1$s&#8221;', 'revision-control'), get_the_title());
        $left = $left_revision->ID;
        $right = $right_revision->ID;
        $GLOBALS['hook_suffix'] = 'revision-control';
        wp_enqueue_style('revision-control');
        iframe_header();
        ?>
		<div class="wrap">
		
		<h2 class="long-header center"><?php 
        echo $title;
        ?>
</h2>
		
		<table class="form-table ie-fixed">
			<col class="th" />
		<tr id="revision">
			<th scope="col" class="th-full">
				<?php 
        printf(__('Older: %s', 'revision-control'), wp_post_revision_title($left_revision, false));
        ?>
				<span class="alignright"><?php 
        printf(__('Newer: %s', 'revision-control'), wp_post_revision_title($right_revision, false));
        ?>
</span>
			</th>
		</tr>
		<?php 
        $fields = _wp_post_revision_fields();
        foreach (get_object_taxonomies($post->post_type) as $taxonomy) {
            $t = get_taxonomy($taxonomy);
            $fields[$taxonomy] = $t->label;
            $left_terms = $right_terms = array();
            foreach (wp_get_object_terms($left_revision->ID, $taxonomy) as $term) {
                $left_terms[] = $term->name;
            }
            foreach (wp_get_object_terms($right_revision->ID, $taxonomy) as $term) {
                $right_terms[] = $term->name;
            }
            $left_revision->{$taxonomy} = (empty($left_terms) ? '' : "* ") . join("\n* ", $left_terms);
            $right_revision->{$taxonomy} = (empty($right_terms) ? '' : "* ") . join("\n* ", $right_terms);
        }
        $fields['postmeta'] = __('Post Meta', 'revision-control');
        $left_revision->postmeta = $right_revision->postmeta = array();
        foreach ((array) has_meta($right_revision->ID) as $meta) {
            if ('_' == $meta['meta_key'][0]) {
                continue;
            }
            $right_revision->postmeta[] = $meta['meta_key'] . ': ' . $meta['meta_value'];
            $left_val = get_post_meta('post', $left_revision->ID, $meta['meta_key'], true);
            if (!empty($left_val)) {
                $left_revision->postmeta[] = $meta['meta_key'] . ': ' . $left_val;
            }
        }
        $right_revision->postmeta = implode("\n", $right_revision->postmeta);
        $left_revision->postmeta = implode("\n", $left_revision->postmeta);
        $identical = true;
        foreach ($fields as $field => $field_title) {
            if (!($content = wp_text_diff($left_revision->{$field}, $right_revision->{$field}))) {
                continue;
            }
            // There is no difference between left and right
            $identical = false;
            ?>
			<tr>
				<th scope="row"><strong><?php 
            echo esc_html($field_title);
            ?>
</strong></th>
			</tr>
			<tr id="revision-field-<?php 
            echo $field;
            ?>
">
				<td><div class="pre"><?php 
            echo $content;
            ?>
</div></td>
			</tr>
			<?php 
        }
        if ($identical) {
            ?>
<tr><td><div class="updated"><p><?php 
            _e('These Revisions are identical.', 'revision-control');
            ?>
</p></div></td></tr><?php 
        }
        ?>
		</table>
		<p><?php 
        _e('<em>Please Note:</em> at present, Although Taxonomies <em>(Tags / Categories / Custom Taxonomies)</em> are stored with the revisions, Restoring a Revision will <strong>not</strong> restore the taxonomies at present.', 'revision-control');
        ?>
</p>
		<br class="clear" />
		<?php 
        iframe_footer();
    }
    function compare_revisions_iframe()
    {
        if (function_exists('register_admin_colors')) {
            add_action('admin_init', 'register_admin_colors', 1);
        } else {
            // Hard coded translation strings here as the translations are not required, just the name and stlesheet.
            wp_admin_css_color('classic', 'Blue', admin_url("css/colors-classic.css"), array('#073447', '#21759B', '#EAF3FA', '#BBD8E7'));
            wp_admin_css_color('fresh', 'Gray', admin_url("css/colors-fresh.css"), array('#464646', '#6D6D6D', '#F1F1F1', '#DFDFDF'));
        }
        $left = isset($_GET['left']) ? absint($_GET['left']) : false;
        $right = isset($_GET['right']) ? absint($_GET['right']) : false;
        if (!($left_revision = get_post($left))) {
            break;
        }
        if (!($right_revision = get_post($right))) {
            break;
        }
        if (!current_user_can('read_post', $left_revision->ID) || !current_user_can('read_post', $right_revision->ID)) {
            break;
        }
        // Don't allow reverse diffs?
        if (strtotime($right_revision->post_modified_gmt) < strtotime($left_revision->post_modified_gmt)) {
            //$redirect = add_query_arg( array( 'left' => $right, 'right' => $left ) );
            // Switch-a-roo
            $temp_revision = $left_revision;
            $left_revision = $right_revision;
            $right_revision = $temp_revision;
            unset($temp_revision);
        }
        global $post;
        if ($left_revision->ID == $right_revision->post_parent) {
            // right is a revision of left
            $post = $left_revision;
        } elseif ($left_revision->post_parent == $right_revision->ID) {
            // left is a revision of right
            $post = $right_revision;
        } elseif ($left_revision->post_parent == $right_revision->post_parent) {
            // both are revisions of common parent
            $post = get_post($left_revision->post_parent);
        } else {
            wp_die(__('Sorry, But you cant compare unrelated Revisions.', 'revision-control'));
        }
        // Don't diff two unrelated revisions
        if ($left_revision->ID == $right_revision->ID || !wp_get_post_revision($left_revision->ID) && !wp_get_post_revision($right_revision->ID)) {
            wp_die(__('Sorry, But you cant compare a Revision to itself.', 'revision-control'));
        }
        $title = sprintf(__('Compare Revisions of &#8220;%1$s&#8221;', 'revision-control'), get_the_title());
        $left = $left_revision->ID;
        $right = $right_revision->ID;
        iframe_header();
        ?>
		<div class="wrap">
		
		<h2 class="long-header center"><?php 
        echo $title;
        ?>
</h2>
		
		<table class="form-table ie-fixed">
			<col class="th" />
		<tr id="revision">
			<th scope="col" class="th-full">
				<?php 
        printf(__('Older: %s', 'revision-control'), wp_post_revision_title($left_revision, false));
        ?>
				<span class="alignright"><?php 
        printf(__('Newer: %s', 'revision-control'), wp_post_revision_title($right_revision, false));
        ?>
</span>
			</th>
		</tr>
		<?php 
        $fields = _wp_post_revision_fields();
        foreach (get_object_taxonomies($post->post_type) as $taxonomy) {
            $t = get_taxonomy($taxonomy);
            $fields[$taxonomy] = $t->label;
            $left_terms = $right_terms = array();
            foreach (wp_get_object_terms($left_revision->ID, $taxonomy) as $term) {
                $left_terms[] = $term->name;
            }
            foreach (wp_get_object_terms($right_revision->ID, $taxonomy) as $term) {
                $right_terms[] = $term->name;
            }
            $left_revision->{$taxonomy} = (empty($left_terms) ? '' : "* ") . join("\n* ", $left_terms);
            $right_revision->{$taxonomy} = (empty($right_terms) ? '' : "* ") . join("\n* ", $right_terms);
        }
        $identical = true;
        foreach ($fields as $field => $field_title) {
            if (!($content = wp_text_diff($left_revision->{$field}, $right_revision->{$field}))) {
                continue;
            }
            // There is no difference between left and right
            $identical = false;
            ?>
			<tr>
				<th scope="row"><strong><?php 
            echo esc_html($field_title);
            ?>
</strong></th>
			</tr>
			<tr id="revision-field-<?php 
            echo $field;
            ?>
">
				<td><div class="pre"><?php 
            echo $content;
            ?>
</div></td>
			</tr>
			<?php 
        }
        if ($identical) {
            ?>
<tr><td><div class="updated"><p><?php 
            _e('These Revisions are identical.', 'revision-control');
            ?>
</p></div></td></tr><?php 
        }
        ?>
		</table>
		<p><?php 
        _e('<em>Please Note:</em> at present, Although Taxonomies <em>(Tags / Categories / Custom Taxonomies)</em> are stored with the revisions, Restoring a Revision will <strong>not</strong> restore the taxonomies at present.', 'revision-control');
        ?>
</p>
		<br class="clear" />
		<?php 
        iframe_footer();
    }
echo $h1;
?>
</h1>
		</header>
		<div class="entry-content">
		<?php 
$revisions = wp_get_post_revisions($post->ID);
$revision_id = @$_REQUEST['revision'];
$old_revision = @$_REQUEST['old'];
$new_revision = @$_REQUEST['new'];
$view_revision = @$_REQUEST['view_revision'];
if ($revision_id) {
    // Compare revision with current post
    require_once PACOWIKI_PLUGIN_PATH . 'library/Diff.php';
    require_once PACOWIKI_PLUGIN_PATH . 'library/Diff/Renderer/Html/Inline.php';
    $revision = wp_get_post_revision($revision_id);
    $new_content = explode("\n", $post->post_content);
    $old_content = explode("\n", $revision->post_content);
    // Options for generating the diff
    $options = array('ignoreWhitespace' => false, 'ignoreCase' => false);
    // Initialize the diff class
    $diff = new Diff($new_content, $old_content, $options);
    $renderer = new Diff_Renderer_Html_Inline();
    $diff_output = $diff->Render($renderer);
    if (empty($diff_output)) {
        echo '<p>' . __('No changes were found in post content of this revision!', 'pacowiki') . '</p>';
    } else {
        echo $diff_output;
    }
} elseif ($old_revision) {
    // Compare two different revisions
 /**
  * Restore a post revision
  *
  * @since 3.5.0
  *
  * @uses wp_restore_post_revision()
  *
  * @param array $args Method parameters. Contains:
  *  - int     $blog_id (unused)
  *  - string  $username
  *  - string  $password
  *  - int     $post_id
  * @return bool|IXR_Error false if there was an error restoring, true if success.
  */
 public function wp_restoreRevision($args)
 {
     if (!$this->minimum_args($args, 3)) {
         return $this->error;
     }
     $this->escape($args);
     $username = $args[1];
     $password = $args[2];
     $revision_id = (int) $args[3];
     if (!($user = $this->login($username, $password))) {
         return $this->error;
     }
     /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
     do_action('xmlrpc_call', 'wp.restoreRevision');
     if (!($revision = wp_get_post_revision($revision_id))) {
         return new IXR_Error(404, __('Invalid post ID'));
     }
     if (wp_is_post_autosave($revision)) {
         return new IXR_Error(404, __('Invalid post ID'));
     }
     if (!($post = get_post($revision->post_parent))) {
         return new IXR_Error(404, __('Invalid post ID'));
     }
     if (!current_user_can('edit_post', $revision->post_parent)) {
         return new IXR_Error(401, __('Sorry, you cannot edit this post.'));
     }
     // Check if revisions are disabled.
     if (!wp_revisions_enabled($post)) {
         return new IXR_Error(401, __('Sorry, revisions are disabled.'));
     }
     $post = wp_restore_post_revision($revision_id);
     return (bool) $post;
 }
 function theme($content)
 {
     global $post;
     $revision_id = isset($_REQUEST['revision']) ? absint($_REQUEST['revision']) : 0;
     $left = isset($_REQUEST['left']) ? absint($_REQUEST['left']) : 0;
     $right = isset($_REQUEST['right']) ? absint($_REQUEST['right']) : 0;
     $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'view';
     $new_content = '';
     if ($action != 'edit') {
         $top = "";
         $btop = "";
         $btop .= '<div class="incsub_wiki incsub_wiki_single">';
         $btop .= '<div class="incsub_wiki_tabs incsub_wiki_tabs_top">' . $this->tabs() . '<div class="incsub_wiki_clear"></div></div>';
         switch ($action) {
             case 'discussion':
                 break;
             case 'edit':
                 set_include_path(get_include_path() . PATH_SEPARATOR . ABSPATH . 'wp-admin');
                 $post_type_object = get_post_type_object($post->post_type);
                 $p = $post;
                 if (empty($post->ID)) {
                     wp_die(__('You attempted to edit an item that doesn&#8217;t exist. Perhaps it was deleted?'));
                 }
                 if (!current_user_can($post_type_object->cap->edit_post, $post_id)) {
                     wp_die(__('You are not allowed to edit this item.'));
                 }
                 if ('trash' == $post->post_status) {
                     wp_die(__('You can&#8217;t edit this item because it is in the Trash. Please restore it and try again.'));
                 }
                 if (null == $post_type_object) {
                     wp_die(__('Unknown post type.'));
                 }
                 $post_type = $post->post_type;
                 if ($last = $this->check_post_lock($post->ID)) {
                     add_action('admin_notices', '_admin_notice_post_locked');
                 } else {
                     $this->set_post_lock($post->ID);
                     wp_enqueue_script('autosave');
                 }
                 $title = $post_type_object->labels->edit_item;
                 $post = $this->post_to_edit($post_id);
                 $new_content = '';
                 break;
             case 'restore':
                 if (!($revision = wp_get_post_revision($revision_id))) {
                     break;
                 }
                 if (!current_user_can('edit_post', $revision->post_parent)) {
                     break;
                 }
                 if (!($post = get_post($revision->post_parent))) {
                     break;
                 }
                 // Revisions disabled and we're not looking at an autosave
                 if ((!WP_POST_REVISIONS || !post_type_supports($post->post_type, 'revisions')) && !wp_is_post_autosave($revision)) {
                     $redirect = get_permalink() . '?action=edit';
                     break;
                 }
                 check_admin_referer("restore-post_{$post->ID}|{$revision->ID}");
                 wp_restore_post_revision($revision->ID);
                 $redirect = add_query_arg(array('message' => 5, 'revision' => $revision->ID), get_permalink() . '?action=edit');
                 break;
             case 'diff':
                 if (!($left_revision = get_post($left))) {
                     break;
                 }
                 if (!($right_revision = get_post($right))) {
                     break;
                 }
                 // If we're comparing a revision to itself, redirect to the 'view' page for that revision or the edit page for that post
                 if ($left_revision->ID == $right_revision->ID) {
                     $redirect = get_edit_post_link($left_revision->ID);
                     include ABSPATH . 'wp-admin/js/revisions-js.php';
                     break;
                 }
                 // Don't allow reverse diffs?
                 if (strtotime($right_revision->post_modified_gmt) < strtotime($left_revision->post_modified_gmt)) {
                     $redirect = add_query_arg(array('left' => $right, 'right' => $left));
                     break;
                 }
                 if ($left_revision->ID == $right_revision->post_parent) {
                     // right is a revision of left
                     $post =& $left_revision;
                 } elseif ($left_revision->post_parent == $right_revision->ID) {
                     // left is a revision of right
                     $post =& $right_revision;
                 } elseif ($left_revision->post_parent == $right_revision->post_parent) {
                     // both are revisions of common parent
                     $post = get_post($left_revision->post_parent);
                 } else {
                     break;
                 }
                 // Don't diff two unrelated revisions
                 if (!WP_POST_REVISIONS || !post_type_supports($post->post_type, 'revisions')) {
                     // Revisions disabled
                     if (!wp_is_post_autosave($left_revision) && !wp_is_post_autosave($right_revision) || $post->ID !== $left_revision->ID && $post->ID !== $right_revision->ID) {
                         $redirect = get_permalink() . '?action=edit';
                         break;
                     }
                 }
                 if ($left_revision->ID == $right_revision->ID || !wp_get_post_revision($left_revision->ID) && !wp_get_post_revision($right_revision->ID)) {
                     break;
                 }
                 $post_title = '<a href="' . get_permalink() . '?action=edit' . '">' . get_the_title() . '</a>';
                 $h2 = sprintf(__('Compare Revisions of &#8220;%1$s&#8221;'), $post_title);
                 $title = __('Revisions');
                 $left = $left_revision->ID;
                 $right = $right_revision->ID;
             case 'history':
                 $args = array('format' => 'form-table', 'parent' => false, 'right' => $right, 'left' => $left);
                 if (!WP_POST_REVISIONS || !post_type_supports($post->post_type, 'revisions')) {
                     $args['type'] = 'autosave';
                 }
                 if (!isset($h2)) {
                     $post_title = '<a href="' . get_permalink() . '?action=edit' . '">' . get_the_title() . '</a>';
                     $revisions = wp_get_post_revisions($post->ID);
                     $revision = array_shift($revisions);
                     $revision_title = wp_post_revision_title($revision, false);
                     $h2 = sprintf(__('Revision for &#8220;%1$s&#8221; created on %2$s'), $post_title, $revision_title);
                 }
                 $new_content .= '<h3 class="long-header">' . $h2 . '</h3>';
                 $new_content .= '<table class="form-table ie-fixed">';
                 $new_content .= '<col class="th" />';
                 if ('diff' == $action) {
                     $new_content .= '<tr id="revision">';
                     $new_content .= '<th scope="row"></th>';
                     $new_content .= '<th scope="col" class="th-full">';
                     $new_content .= '<span class="alignleft">' . sprintf(__('Older: %s', $this->translation_domain), wp_post_revision_title($left_revision, false)) . '</span>';
                     $new_content .= '<span class="alignright">' . sprintf(__('Newer: %s', $this->translation_domain), wp_post_revision_title($right_revision, false)) . '</span>';
                     $new_content .= '</th>';
                     $new_content .= '</tr>';
                 }
                 // use get_post_to_edit filters?
                 $identical = true;
                 foreach (_wp_post_revision_fields() as $field => $field_title) {
                     if ('diff' == $action) {
                         $left_content = apply_filters("_wp_post_revision_field_{$field}", $left_revision->{$field}, $field);
                         $right_content = apply_filters("_wp_post_revision_field_{$field}", $right_revision->{$field}, $field);
                         if (!($rcontent = wp_text_diff($left_content, $right_content))) {
                             continue;
                         }
                         // There is no difference between left and right
                         $identical = false;
                     } else {
                         add_filter("_wp_post_revision_field_{$field}", 'htmlspecialchars');
                         $rcontent = apply_filters("_wp_post_revision_field_{$field}", $revision->{$field}, $field);
                     }
                     $new_content .= '<tr id="revision-field-<?php echo $field; ?>">';
                     $new_content .= '<th scope="row">' . esc_html($field_title) . '</th>';
                     $new_content .= '<td><div class="pre">' . $rcontent . '</div></td>';
                     $new_content .= '</tr>';
                 }
                 if ('diff' == $action && $identical) {
                     $new_content .= '<tr><td colspan="2"><div class="updated"><p>' . __('These revisions are identical.', $this->translation_domain) . '</p></div></td></tr>';
                 }
                 $new_content .= '</table>';
                 $new_content .= '<br class="clear" />';
                 $new_content .= '<div class="incsub_wiki_revisions">' . $this->list_post_revisions($post, $args) . '</div>';
                 $redirect = false;
                 break;
             default:
                 $crumbs = array();
                 foreach ($post->ancestors as $parent_pid) {
                     $parent_post = get_post($parent_pid);
                     $crumbs[] = '<a href="' . get_permalink($parent_pid) . '" class="incsub_wiki_crumbs">' . $parent_post->post_title . '</a>';
                 }
                 $crumbs[] = '<span class="incsub_wiki_crumbs">' . $post->post_title . '</span>';
                 sort($crumbs);
                 $top .= join(get_option("incsub_meta_seperator", " > "), $crumbs);
                 $children = get_children('post_parent=' . $post->ID . '&post_type=incsub_wiki');
                 $crumbs = array();
                 foreach ($children as $child) {
                     $crumbs[] = '<a href="' . get_permalink($child->ID) . '" class="incsub_wiki_crumbs">' . $child->post_title . '</a>';
                 }
                 $bottom = "<h3>" . __('Sub Wikis', $this->translation_domain) . "</h3> <ul><li>";
                 $bottom .= join("</li><li>", $crumbs);
                 if (count($crumbs) == 0) {
                     $bottom = "";
                 } else {
                     $bottom .= "</li></ul>";
                 }
                 $revisions = wp_get_post_revisions($post->ID);
                 if (current_user_can('edit_wiki')) {
                     $bottom .= '<div class="incsub_wiki-meta">';
                     if (is_array($revisions) && count($revisions) > 0) {
                         $revision = array_shift($revisions);
                     }
                     $bottom .= '</div>';
                 }
                 $notification_meta = get_post_custom($post->ID, array('incsub_wiki_email_notification' => 'enabled'));
                 if ($notification_meta['incsub_wiki_email_notification'][0] == 'enabled' && !$this->is_subscribed()) {
                     if (is_user_logged_in()) {
                         $bottom .= '<div class="incsub_wiki-subscribe"><a href="' . wp_nonce_url(add_query_arg(array('post_id' => $post->ID, 'subscribe' => 1)), "wiki-subscribe-wiki_{$post->ID}") . '">' . __('Notify me of changes', $this->translation_domain) . '</a></div>';
                     } else {
                         if (!empty($_COOKIE['incsub_wiki_email'])) {
                             $user_email = $_COOKIE['incsub_wiki_email'];
                         } else {
                             $user_email = "";
                         }
                         $bottom .= '<div class="incsub_wiki-subscribe">' . '<form action="" method="post">' . '<label>' . __('E-mail', $this->translation_domain) . ': <input type="text" name="email" id="email" value="' . $user_email . '" /></label> &nbsp;' . '<input type="hidden" name="post_id" id="post_id" value="' . $post->ID . '" />' . '<input type="submit" name="subscribe" id="subscribe" value="' . __('Notify me of changes', $this->translation_domain) . '" />' . '<input type="hidden" name="_wpnonce" id="_wpnonce" value="' . wp_create_nonce("wiki-subscribe-wiki_{$post->ID}") . '" />' . '</form>' . '</div>';
                     }
                 }
                 $new_content = $btop . '<div class="incsub_wiki_top">' . $top . '</div>' . $new_content;
                 $new_content .= '<div class="incsub_wiki_content">' . $content . '</div>';
                 $new_content .= '<div class="incsub_wiki_bottom">' . $bottom . '</div>';
                 $redirect = false;
         }
         $new_content .= '</div>';
     }
     if (!comments_open()) {
         $new_content .= '<style type="text/css">' . '#comments { display: none; }' . '</style>';
     } else {
         $new_content .= '<style type="text/css">' . '.hentry { margin-bottom: 5px; }' . '</style>';
     }
     // Empty post_type means either malformed object found, or no valid parent was found.
     if (isset($redirect) && !$redirect && empty($post->post_type)) {
         $redirect = 'edit.php';
     }
     if (!empty($redirect)) {
         echo '<script type="text/javascript">' . 'window.location = "' . $redirect . '";' . '</script>';
         exit;
     }
     return $new_content;
 }
/**
 * Deletes a revision.
 *
 * Deletes the row from the posts table corresponding to the specified revision.
 *
 * @package WordPress
 * @subpackage Post_Revisions
 * @since 2.6.0
 *
 * @uses wp_get_post_revision()
 * @uses wp_delete_post()
 *
 * @param int|object $revision_id Revision ID or revision object.
 * @return mixed Null or WP_Error if error, deleted post if success.
 */
function wp_delete_post_revision($revision_id)
{
    if (!($revision = wp_get_post_revision($revision_id))) {
        return $revision;
    }
    $delete = wp_delete_post($revision->ID);
    if (is_wp_error($delete)) {
        return $delete;
    }
    if ($delete) {
        do_action('wp_delete_post_revision', $revision->ID, $revision);
    }
    return $delete;
}
 /**
  * Make sure that restoring snapshot revisions doesn't involve kses corrupting the post_content.
  *
  * Ideally there would be an action like pre_wp_restore_post_revision instead
  * of having to hack into the load-revision.php action. But even more ideally
  * we should be able to disable such content_save_pre filters from even applying
  * for certain post types, such as those which store JSON in post_content.
  *
  * @codeCoverageIgnore
  */
 function suspend_kses_for_snapshot_revision_restore()
 {
     if (!isset($_GET['revision'])) {
         // WPCS: input var ok.
         return;
     }
     if (!isset($_GET['action']) || 'restore' !== $_GET['action']) {
         // WPCS: input var ok, sanitization ok.
         return;
     }
     $revision_post_id = intval($_GET['revision']);
     // WPCS: input var ok.
     if ($revision_post_id <= 0) {
         return;
     }
     $revision_post = wp_get_post_revision($revision_post_id);
     if (empty($revision_post)) {
         return;
     }
     $post = get_post($revision_post->post_parent);
     if (empty($post) || static::SLUG !== $post->post_type) {
         return;
     }
     $this->suspend_kses();
     $that = $this;
     add_action('wp_restore_post_revision', function () use($that) {
         $that->restore_kses();
     });
 }