• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP wp_restore_post_revision函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中wp_restore_post_revision函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_restore_post_revision函数的具体用法?PHP wp_restore_post_revision怎么用?PHP wp_restore_post_revision使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了wp_restore_post_revision函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: test_revision_restore_updates_edit_last_post_meta

 /**
  * Note: Test needs reviewing when #16215 is fixed because I'm not sure the test current tests the "correct" behavior
  * @ticket 20982
  * @ticket 16215
  */
 function test_revision_restore_updates_edit_last_post_meta()
 {
     $admin_user_id = $this->factory->user->create(array('role' => 'administrator'));
     $editor_user_id = $this->factory->user->create(array('role' => 'editor'));
     $author_user_id = $this->factory->user->create(array('role' => 'author'));
     //create a post as Author
     wp_set_current_user($author_user_id);
     $post = get_default_post_to_edit('post', true);
     $post_id = $post->ID;
     wp_update_post(array('post_status' => 'draft', 'post_content' => 'I cant spel werds.', 'ID' => $post_id));
     //update post as Editor
     wp_set_current_user($editor_user_id);
     wp_update_post(array('post_content' => 'The Editor was in fixing your typos.', 'ID' => $post_id));
     //restore back as Admin
     wp_set_current_user($admin_user_id);
     $revisions = wp_get_post_revisions($post->ID);
     $this->assertCount(2, $revisions);
     $lastrevision = end($revisions);
     $this->assertEquals('I cant spel werds.', $lastrevision->post_content);
     // #16215
     $this->assertEquals($author_user_id, $lastrevision->post_author);
     wp_restore_post_revision($lastrevision->ID);
     //is post_meta correctly set to revision author
     $this->assertEquals($admin_user_id, get_post_meta($post_id, '_edit_last', true));
     //after restoring user
     wp_set_current_user(0);
 }
开发者ID:Benrajalu,项目名称:philRaj,代码行数:32,代码来源:revisions.php


示例2: wp_restoreRevision

 /**
  * 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;
 }
开发者ID:sb-xs,项目名称:que-pour-elle,代码行数:47,代码来源:class-wp-xmlrpc-server.php


示例3: check_admin_referer

         break;
     }
     if (!($post = get_post($revision->post_parent))) {
         break;
     }
     // Revisions disabled (previously checked autosaves && ! wp_is_post_autosave( $revision ))
     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
开发者ID:palimadra,项目名称:bubblegraphics-wpsite,代码行数:31,代码来源:revision.php


示例4: insert_post

 function insert_post($update = false, $freshness = 2)
 {
     global $wpdb;
     $dbpost = $this->normalize_post(true);
     if (!is_null($dbpost)) {
         $dbpost['post_pingback'] = false;
         // Tell WP 2.1 and 2.2 not to process for pingbacks
         // This is a ridiculous fucking kludge necessitated by WordPress 2.6 munging authorship meta-data
         add_action('_wp_put_post_revision', array($this, 'fix_revision_meta'));
         // Kludge to prevent kses filters from stripping the
         // content of posts when updating without a logged in
         // user who has `unfiltered_html` capability.
         $mungers = array('wp_filter_kses', 'wp_filter_post_kses');
         $removed = array();
         foreach ($mungers as $munger) {
             if (has_filter('content_save_pre', $munger)) {
                 remove_filter('content_save_pre', $munger);
                 $removed[] = $munger;
             }
         }
         if ($update and function_exists('get_post_field')) {
             // Don't munge status fields that the user may
             // have reset manually
             $doNotMunge = array('post_status', 'comment_status', 'ping_status');
             foreach ($doNotMunge as $field) {
                 $dbpost[$field] = get_post_field($field, $this->wp_id());
             }
         }
         // WP3's wp_insert_post scans current_user_can() for the
         // tax_input, with no apparent way to override. Ugh.
         add_action('transition_post_status', array($this, 'add_terms'), -10001, 3);
         // WP3 appears to override whatever you give it for
         // post_modified. Ugh.
         add_action('transition_post_status', array($this, 'fix_post_modified_ts'), -10000, 3);
         if ($update) {
             $this->post['ID'] = $this->wp_id();
             $dbpost['ID'] = $this->post['ID'];
         }
         // O.K., is this a new post? If so, we need to create
         // the basic post record before we do anything else.
         if ($this->this_revision_needs_original_post()) {
             // *sigh*, for handling inconsistent slash expectations < 3.6
             $sdbpost = $this->db_sanitize_post($dbpost);
             // Go ahead and insert the first post record to
             // anchor the revision history.
             $this->_wp_id = wp_insert_post($sdbpost, true);
             $dbpost['ID'] = $this->_wp_id;
         }
         // Now that we've made sure the original exists, insert
         // this version here as a revision.
         $revision_id = _wp_put_post_revision($dbpost, false);
         if (!$this->this_revision_needs_original_post()) {
             if ($this->this_revision_is_current()) {
                 wp_restore_post_revision($revision_id);
             } else {
                 // If we do not activate this revision, then the
                 // add_rss_meta will not be called, which is
                 // more or less as it should be, but that means
                 // we have to actively record this revision's
                 // update hash from here.
                 $postId = $this->post['ID'];
                 $key = 'syndication_item_hash';
                 $hash = $this->update_hash();
                 FeedWordPress::diagnostic('syndicated_posts:meta_data', "Adding post meta-datum to post [{$postId}]: [{$key}] = " . FeedWordPress::val($hash, true));
                 add_post_meta($postId, $key, $hash, false);
             }
         }
         remove_action('transition_post_status', array($this, 'add_terms'), -10001, 3);
         remove_action('transition_post_status', array($this, 'fix_post_modified_ts'), -10000, 3);
         // Turn off ridiculous fucking kludges #1 and #2
         remove_action('_wp_put_post_revision', array($this, 'fix_revision_meta'));
         foreach ($removed as $filter) {
             add_filter('content_save_pre', $filter);
         }
         $this->validate_post_id($dbpost, $update, array(__CLASS__, __FUNCTION__));
     }
 }
开发者ID:kosir,项目名称:thatcamp-org,代码行数:77,代码来源:syndicatedpost.class.php


示例5: wp_restoreRevision

 /**
  * 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;
 }
开发者ID:jospintedjou,项目名称:wordpress,代码行数:47,代码来源:class-wp-xmlrpc-server.php


示例6: tdomf_moderation_handler


//.........这里部分代码省略.........
                    $ham_list = array();
                    $edit_spam_list = array();
                    $edit_ham_list = array();
                    foreach ($posts as $post) {
                        $last_edit = tdomf_get_edits(array('post_id' => $post, 'limit' => 1));
                        if ($last_edit != false && !empty($last_edit)) {
                            if (tdomf_check_edit_spam($last_edit[0]->edit_id, false)) {
                                $ham_list[] = $post;
                                $edit_ham_list[] = $last_edit[0]->edit_id;
                            } else {
                                $spam_list[] = $post;
                                $edit_spam_list[] = $last_edit[0]->edit_id;
                            }
                        }
                    }
                    tdomf_log_message('Akismet thinks these edits are spam: ' . implode(", ", $edit_spam_list));
                    $message .= sprintf(__("Marked last contribution on these submissions as spam: %s.", "tdomf"), implode(", ", $spam_list));
                    tdomf_log_message('Akismet thinks these edits are not spam: ' . implode(", ", $edit_ham_list));
                    $message .= " ";
                    $message .= sprintf(__("Marked last contribution on these submissions as not spam: %s.", "tdomf"), implode(", ", $ham_list));
                    break;
                case 'edit_approve':
                    $edit_list = array();
                    $post_list = array();
                    foreach ($posts as $post) {
                        $last_edit = tdomf_get_edits(array('post_id' => $post, 'limit' => 1));
                        if (!empty($last_edit) && $last_edit[0]->state != 'approved') {
                            $edit_list[] = $last_edit[0]->edit_id;
                            $post_list[] = $post;
                            $user_id = $last_edit[0]->user_id;
                            if ($last_edit[0]->state == 'spam') {
                                tdomf_hamit_edit($last_edit[0]);
                            }
                            wp_restore_post_revision($edit->revision_id);
                            tdomf_set_state_edit('approved', $last_edit[0]->edit_id);
                            if ($user_id > 0) {
                                tdomf_trust_user($user_id);
                            }
                        }
                    }
                    tdomf_log_message('These edits have been approved: ' . implode(", ", $edit_list));
                    $message .= sprintf(__("Approved contributions on these submissions: %s.", "tdomf"), implode(", ", $post_list));
                    break;
                case 'edit_revert':
                    $edit_list = array();
                    $post_list = array();
                    foreach ($posts as $post) {
                        $last_edit = tdomf_get_edits(array('post_id' => $post, 'limit' => 1));
                        if (!empty($last_edit) && $last_edit[0]->state == 'approved' && $last_edit[0]->revision_id != 0 && $last_edit[0]->current_revision_id != 0) {
                            $edit_list[] = $last_edit[0]->edit_id;
                            $post_list[] = $post;
                            wp_restore_post_revision($last_edit[0]->current_revision_id);
                            tdomf_set_state_edit('unapproved', $last_edit[0]->edit_id);
                        }
                    }
                    tdomf_log_message('These edits have been reverted: ' . implode(", ", $edit_list));
                    $message .= sprintf(__("Latest contribution on these submissions have been reverted: %s.", "tdomf"), implode(", ", $post_list));
                    break;
                case 'edit_delete':
                    $edit_list = array();
                    $post_list = array();
                    foreach ($posts as $post) {
                        $last_edit = tdomf_get_edits(array('post_id' => $post, 'limit' => 1));
                        if (!empty($last_edit) && $last_edit[0]->state != 'approved') {
                            $edit_list[] = $last_edit[0]->edit_id;
                            $post_list[] = $post;
开发者ID:TheReaCompany,项目名称:pooplog,代码行数:67,代码来源:tdomf-moderation.php


示例7: theme

 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;
                     }
                 }
//.........这里部分代码省略.........
开发者ID:Esleelkartea,项目名称:asociacion-tecnicos-artes-escenicas-ATAE-,代码行数:101,代码来源:wordpress-wiki-plugin.php


示例8: rollback_post_types

 protected function rollback_post_types($post_types)
 {
     $success = true;
     foreach ($post_types as $post_type => $posts) {
         if (!empty($posts)) {
             // reverse the array so that we delete children first
             $_posts = array_reverse($posts);
             foreach ($_posts as $guid => $post) {
                 if ($post == 'new') {
                     $_post = new cfd_post(array('guid' => $guid));
                     wp_delete_post($_post->post->ID, true);
                 } else {
                     if ($post['post']['post_type'] == 'attachment') {
                         if ($this->import_post($post) == false) {
                             $success = false;
                             $this->add_import_message('post_types.' . $post_type, '__error__', sprintf(__('Unknown error. Unable to revert post "%s" to revision "%s".', 'cf-deploy'), $guid, $post));
                         }
                     } else {
                         $result = wp_restore_post_revision($post);
                         if (empty($result)) {
                             $success = false;
                             $this->add_import_message('post_types.' . $post_type, '__error__', sprintf(__('Unknown error. Unable to revert post "%s" to revision "%s".', 'cf-deploy'), $guid, $post));
                         }
                     }
                 }
             }
         }
     }
     return $success;
 }
开发者ID:niko-lgdcom,项目名称:wp-install,代码行数:30,代码来源:deploy.class.php


示例9: test_revisions_stores_meta_values

 /**
  * Test the revisions system for storage of meta values
  */
 function test_revisions_stores_meta_values()
 {
     /**
      * Set Up.
      */
     // Set up a new post
     $original_post_id = $post_id = $this->factory->post->create();
     // And update to store an initial revision
     wp_update_post(array('post_content' => 'some initial content', 'ID' => $post_id));
     // One revision so far
     $revisions = wp_get_post_revisions($post_id);
     $this->assertCount(1, $revisions);
     /**
      * First set up a meta value
      */
     // Store a custom meta value, which is not revisioned by default
     update_post_meta($post_id, 'meta_revision_test', 'original');
     // Update the post, storing a revision
     wp_update_post(array('post_content' => 'some more content', 'ID' => $post_id));
     $revisions = wp_get_post_revisions($post_id);
     $this->assertCount(2, $revisions);
     //  Next, store some updated meta values for the same key
     update_post_meta($post_id, 'meta_revision_test', 'update1');
     // Save the post, changing content to force a revision
     wp_update_post(array('post_content' => 'some updated content', 'ID' => $post_id));
     $revisions = wp_get_post_revisions($post_id);
     $this->assertCount(3, $revisions);
     /**
      * Now restore the original revision
      */
     // Restore the previous revision
     $revisions = (array) wp_get_post_revisions($post_id);
     // Go back two to load the previous revision
     array_shift($revisions);
     $last_revision = array_shift($revisions);
     // Restore!
     wp_restore_post_revision($last_revision->ID);
     wp_update_post(array('ID' => $post_id));
     $revisions = wp_get_post_revisions($post_id);
     $this->assertCount(4, $revisions);
     /**
      * Check the meta values to verify they are NOT revisioned - they are not revisioned by default.
      */
     // Custom post meta should NOT be restored, orignal value should not be restored, value still 'update1'
     $this->assertEquals('update1', get_post_meta($post_id, 'meta_revision_test', true));
     update_post_meta($post_id, 'meta_revision_test', 'update2');
     /*
      * Test the revisioning of custom meta when enabled by the wp_post_revision_meta_keys filter
      */
     // Add the custom field to be revised via the wp_post_revision_meta_keys filter
     add_filter('wp_post_revision_meta_keys', array($this, 'add_revisioned_keys'));
     // Save the post, changing content to force a revision
     wp_update_post(array('post_content' => 'more updated content', 'ID' => $post_id));
     $revisions = wp_get_post_revisions($post_id);
     $this->assertCount(5, $revisions);
     // Store custom meta values, which should now be revisioned
     update_post_meta($post_id, 'meta_revision_test', 'update3');
     /**
      * Save the post again, custom meta should now be revisioned
      *
      * Note that a revision is saved even though there is no change
      * in post content, because the revisioned post_meta has changed
      *
      */
     wp_update_post(array('ID' => $post_id));
     // This revision contains the existing post meta ('update3')
     $revisions = wp_get_post_revisions($post_id);
     $this->assertCount(6, $revisions);
     // Verify that previous post meta is set
     $this->assertEquals('update3', get_post_meta($post_id, 'meta_revision_test', true));
     // Restore the previous revision
     $revisions = wp_get_post_revisions($post_id);
     // Go back two to load the previous revision
     array_shift($revisions);
     $last_revision = array_shift($revisions);
     wp_restore_post_revision($last_revision->ID);
     /**
      * Verify that previous post meta is restored.
      */
     $this->assertEquals('update2', get_post_meta($post_id, 'meta_revision_test', true));
     // Try storing a blank meta
     update_post_meta($post_id, 'meta_revision_test', '');
     wp_update_post(array('ID' => $post_id));
     update_post_meta($post_id, 'meta_revision_test', 'update 4');
     wp_update_post(array('ID' => $post_id));
     // Restore the previous revision
     $revisions = wp_get_post_revisions($post_id);
     array_shift($revisions);
     $last_revision = array_shift($revisions);
     wp_restore_post_revision($last_revision->ID);
     /**
      * Verify that previous blank post meta is restored
      */
     $this->assertEquals('', get_post_meta($post_id, 'meta_revision_test', true));
     /*
      * Test not tracking a key - remove the key from the revisioned meta.
      */
//.........这里部分代码省略.........
开发者ID:boquiabierto,项目名称:wp-post-meta-revisions,代码行数:101,代码来源:test-meta-revisions.php


示例10: setup_action

 /**
  * 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;
//.........这里部分代码省略.........
开发者ID:pausaura,项目名称:agora_nodes,代码行数:101,代码来源:addon-history.php


示例11: save_post

 function save_post($post_id, $post)
 {
     global $wpdb;
     $is_new = false;
     if ($post->post_type == 'page') {
         return $post_id;
     }
     //remove_action( 'save_post', array(&$this, 'save_post'), 1, 2 );
     if ($this->done) {
         return $post_id;
     }
     if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
         return $post_id;
     }
     if ($post->post_status == 'auto-draft' || $post->post_status == 'inherit') {
         return $post_id;
     }
     // if using workflow
     //if((isset($_POST['aw_submit_to_workflow']) && $_POST['aw_submit_to_workflow'] == on)){
     if (!current_user_can('publish_' . $post->post_type . 's')) {
         // WordPress always appends an 's' to the end of the capability
         if ($post->post_status == 'pending') {
             $this->resetApproval($post_id);
         }
         // Get custom fields
         $custom = get_post_custom($post_id);
         // Get revisions from db
         $revisions = wp_get_post_revisions($post_id, array('posts_per_page' => 1));
         $last_revision = array_pop($revisions);
         // Is this a new post
         if (count($revisions) <= 1 || empty($last_revision) || empty($last_revision->post_content)) {
             $is_new = true;
         }
         // wp_update_post( array( 'ID' => $post_id, 'post_status' => 'pending' ) );
         if (!$is_new) {
             // Set published content to previous version
             $last_revision = $last_revision->ID;
             wp_restore_post_revision($last_revision);
         }
         update_post_meta($post_id, '_in_progress', 1);
         // If submitting to workflow
         if (isset($_POST['aw_submit_to_workflow']) && $_POST['aw_submit_to_workflow'] == 'on') {
             update_post_meta($post_id, '_waiting_for_approval', 1);
             $this->notify_approvers($post);
         }
     } else {
         if ($post->post_status == 'publish') {
             if ($this->options->force_workflow == 'on' && !$this->isAllApproved($post_id)) {
                 // reset to pending if nobody yet approved
                 wp_update_post(array('ID' => $post_id, 'post_status' => 'pending'));
             } else {
                 $this->done = true;
                 $this->clear_post_workflow_settings($post_id);
             }
         } else {
             if ($post->post_status == 'pending') {
                 $this->resetApproval($post_id);
                 update_post_meta($post_id, '_in_progress', 1);
                 update_post_meta($post_id, '_waiting_for_approval', 1);
             }
         }
     }
     return $post_id;
 }
开发者ID:KelasKayu,项目名称:wordpress,代码行数:64,代码来源:approval-workflow.php


示例12: save_post

 /**
  * Revert to the previous revision and notify the reviewers if necessary
  * @param int $post_ID the ID of the post being saved
  * @param stdClass $post the post object
  */
 function save_post($post_ID, $post)
 {
     if ($this->done) {
         return $post_ID;
     }
     if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
         return $post_ID;
     }
     if ('auto-draft' == $post->post_status || 'inherit' == $post->post_status) {
         return $post_ID;
     }
     $this->done = true;
     if (!isset($_REQUEST['_dpn_nonce']) || !wp_verify_nonce($_REQUEST['_dpn_nonce'], 'dpn-nonce')) {
         return $post_ID;
     }
     if (!isset($_REQUEST['dpn_notify']) || 0 == $_REQUEST['dpn_notify']) {
         return $post_ID;
     }
     if (1 == $_REQUEST['dpn_notify'] || 3 == $_REQUEST['dpn_notify']) {
         $dowhat = 'draft';
     } else {
         $dowhat = 'publish';
     }
     if (1 == $_REQUEST['dpn_notify'] || 2 == $_REQUEST['dpn_notify']) {
         $notify = true;
     } else {
         $notify = false;
     }
     if (isset($_REQUEST['dpn_notify_address']) && strstr($_REQUEST['dpn_notify_address'], ',')) {
         $_REQUEST['dpn_notify_address'] = explode(',', str_replace(' ', '', $_REQUEST['dpn_notify_address']));
     }
     $revs = isset($_REQUEST['dpn_notify_address']) && !empty($_REQUEST['dpn_notify_address']) ? $_REQUEST['dpn_notify_address'] : array();
     if (!is_array($revs)) {
         $revs = array_map('trim', explode(',', $revs));
     }
     $revs = array_filter($revs, 'is_email');
     $this->reviewers = !empty($revs) ? $revs : $this->get_reviewers();
     global $wpdb;
     if ('draft' == $dowhat) {
         $last_revision = array_pop(wp_get_post_revisions($post_ID, array('posts_per_page' => 1)));
         if (empty($last_revision) || empty($last_revision->post_content)) {
             return $post_ID;
         }
         $last_revision = $last_revision->ID;
         wp_restore_post_revision($last_revision);
     }
     if ($notify) {
         $this->notify_reviewer($post_ID, $post, $dowhat);
     }
     return $post_ID;
 }
开发者ID:gopinathshiva,项目名称:wordpress-vip-plugins,代码行数:56,代码来源:class-post-revision-workflow.php


示例13: undo

 /**
  * Undo an entire import.  All newly-created posts and associated comments are deleted.
  * Any categories and tags that were created during the import are also
  * deleted, but only if they have no reference count once the posts/comments are gone.
  *
  * For posts that were updated (rather than created), the last revision is restored.
  * If no revisions are available then the post is deleted.
  *
  * The import profile is retained and is not deleted, but the status is set to 'UNDO'.
  *
  * The instance will update itself back to the options database.
  */
 function undo($id)
 {
     global $current_user, $blog_id;
     $original_blog_id = $blog_id;
     $import = TI_Import::get($id);
     if ($import === false) {
         return new WP_Error('ERROR', sprintf(__('Unable to read import id %s for undo'), $id));
     }
     get_currentuserinfo();
     $import->log(__("Undo started by: {$current_user->user_login}"), 'INFO');
     $import->import_start();
     foreach ((array) $import->get_imported_posts() as $post) {
         // Switch blogs if needed
         if (is_multisite() && isset($post['blog_id']) && $post['blog_id'] != $blog_id) {
             switch_to_blog($post['blog_id']);
         }
         // If post was updated during import, and revisions is on, then try to roll back to previous version
         if (defined('WP_POST_REVISIONS') && WP_POST_REVISIONS && isset($post['updated']) && $post['updated'] && isset($post['revision_id'])) {
             $result = wp_restore_post_revision($post['revision_id']);
             if (is_wp_error($result)) {
                 $import->log(sprintf(__("Unable to restore original version of post %s (%s): %s"), $post['post_title'], $post['post_id'], $result->get_error_message()));
             }
             if (!$result) {
                 $import->log(sprintf(__("Unable to restore original version of post %s (%s)"), $post['post_title'], $post['post_id']));
             }
         } else {
             // If no revisions, or post was created during import, then delete it
             $result = wp_delete_post($post['post_id']);
             if (is_wp_error($result)) {
                 $import->log(sprintf(__("Error deleting post %s (%s): %s"), $post['post_title'], $post['post_id'], $result->get_error_message()));
             }
         }
     }
     // NOTE: counts seem to be incorrect for custom taxonomies - they include deleted posts - see wordpress trac #14084, #14073, #14392
     // Delete tags, categories and custom taxonomies
     foreach ((array) $import->imported_terms as $taxonomy => $terms) {
         foreach ($terms as $term) {
             // Switch blogs if needed
             if (is_multisite() && isset($term->blog_id) && $term->blog_id != $blog_id) {
                 switch_to_blog($term->blog_id);
             }
             // Get current name in case it's changed
             $wp_term = get_term($term->term_id, $taxonomy);
             if (!is_wp_error($wp_term) && $wp_term) {
                 // get_term() returns either wp_error or null
                 $term->name = $wp_term->name;
             }
             // Term doesn't exist
             if (!$wp_term || is_wp_error($wp_term)) {
                 $import->log(sprintf(__('Could not delete term "%s" in taxonomy "%s" because it no longer exists'), $term->name, $taxonomy), 'WARNING');
                 continue;
             }
             // Term still in use
             if ($wp_term->count > 0) {
                 $import->log(sprintf(__('Term "%s" in taxonomy "%s" was not deleted because it is still in use'), $term->name, $taxonomy), 'WARNING');
                 continue;
             }
             // Delete term
             $result = wp_delete_term($term->term_id, $taxonomy);
             if (!$result) {
                 $import->log(sprintf(__('Uknown error deleting term "%s" in taxonomy "%s"'), $term->name, $taxonomy), 'ERROR');
             }
             if (is_wp_error($result)) {
                 $import->log(sprintf(__('Error deleting term "%s" in taxonomy "%s" : "%s"'), $term->name, $taxonomy, $result->get_error_message()), 'ERROR');
             }
         }
     }
     // Switch back to original blog before writing out the import logs to the database
     if ($original_blog_id != $blog_id) {
         switch_to_blog($original_blog_id);
     }
     // Update terms cache
     $import->clean_term_cache();
     // Set status and save back to db
     $import->log(__('Undo finished.'), 'INFO');
     $import->status = 'UNDO';
     $import->save();
     return true;
 }
开发者ID:adisonc,项目名称:MaineLearning,代码行数:91,代码来源:ti_pro.php



注:本文中的wp_restore_post_revision函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP wp_revisions_enabled函数代码示例发布时间:2022-05-23
下一篇:
PHP wp_restore_image函数代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap