本文整理汇总了PHP中wp_get_post_revisions函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_get_post_revisions函数的具体用法?PHP wp_get_post_revisions怎么用?PHP wp_get_post_revisions使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_get_post_revisions函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: test_get_previous_revision
function test_get_previous_revision()
{
$instance = $this->get_instance();
//start out with a softball
$fork = $this->create_fork(true);
$revs = wp_get_post_revisions(get_post($fork)->post_parent);
$this->assertEquals(reset($revs)->ID, $instance->revisions->get_previous_revision($fork));
}
开发者ID:ZitaArlen,项目名称:post-forking,代码行数:8,代码来源:test_post_forking_revisions.php
示例2: render
/**
* @param WP_Post $post
*/
public function render(WP_Post $post)
{
$revisions = wp_get_post_revisions($post->ID);
$nonceField = wp_nonce_field($this->getKey() . '_meta_box', $this->getKey() . '_meta_box_nonce', true, false);
$items = array_reduce($this->items, function ($html, MetaboxItemInterface $item) use($post, $revisions) {
return $html . $item->render($post, $revisions);
}, '');
echo $nonceField . $items;
}
开发者ID:tmf,项目名称:wp-metabox-helper,代码行数:12,代码来源:class-metabox.php
示例3: get_post_latest_revision
function get_post_latest_revision($post_id)
{
// vars
$revisions = wp_get_post_revisions($post_id);
// shift off and return first revision (will return null if no revisions)
$revision = array_shift($revisions);
// return
return $revision;
}
开发者ID:Garth619,项目名称:Femi9,代码行数:9,代码来源:revisions.php
示例4: setUp
function setUp()
{
parent::setUp();
$this->post_id = $this->factory->post->create(array('post_content' => 'edit1'));
wp_insert_post(array('ID' => $this->post_id, 'post_content' => 'edit2'));
$revisions = wp_get_post_revisions($this->post_id);
$revision = array_shift($revisions);
$this->revision_id = $revision->ID;
}
开发者ID:rmccue,项目名称:wordpress-unit-tests,代码行数:9,代码来源:restoreRevision.php
示例5: setUp
public function setUp()
{
parent::setUp();
$revisions = wp_get_post_revisions(self::$post_id);
$this->revision_1 = array_pop($revisions);
$this->revision_id1 = $this->revision_1->ID;
$this->revision_2 = array_pop($revisions);
$this->revision_id2 = $this->revision_2->ID;
}
开发者ID:aaemnnosttv,项目名称:develop.git.wordpress.org,代码行数:9,代码来源:rest-revisions-controller.php
示例6: test_is_revision_dont_flush_cache
public function test_is_revision_dont_flush_cache()
{
$post = $this->factory->post->create_and_get();
wp_update_post(array('post_status' => 'draft', 'post_title' => 'some-post', 'post_type' => 'post', 'post_content' => 'some_content', 'ID' => $post->ID));
$salt = $this->obj->cache_salt;
$revisions = wp_get_post_revisions($post->ID);
$revision = array_shift($revisions);
$this->obj->clean_post_cache($revision->ID, $revision);
$this->assertsame($salt, $this->obj->cache_salt);
}
开发者ID:timeincoss,项目名称:enhanced-post-cache,代码行数:10,代码来源:test-flush-cache.php
示例7: test_get_previous_revision
function test_get_previous_revision()
{
$instance = $this->get_instance();
//start out with a softball
$fork = $this->create_fork(true);
$revs = wp_get_post_revisions(get_post($fork)->post_parent);
$this->assertEquals(reset($revs)->ID, $instance->revisions->get_previous_revision($fork));
//best guess approach, should return parent post
$fork = $this->create_fork(false, false);
$this->assertEquals(get_post($fork)->post_parent, $instance->revisions->get_previous_revision($fork));
}
开发者ID:fancyguy,项目名称:post-forking,代码行数:11,代码来源:test_post_forking_revisions.php
示例8: get_current_revision
function get_current_revision()
{
if (!($js = $this->get_js_post())) {
return false;
}
if (!empty($js['ID'])) {
$revisions = wp_get_post_revisions($js['ID'], 'orderby=ID&order=DESC&limit=1');
}
if (empty($revisions)) {
return $js;
}
return get_object_vars(array_shift($revisions));
}
开发者ID:hwasawoo,项目名称:Custom-Javascript-Editor,代码行数:13,代码来源:custom-javascript-editor.php
示例9: get_items
/**
* Get a collection of revisions
*
* @param WP_REST_Request $request Full data about the request.
* @return WP_Error|WP_REST_Response
*/
public function get_items($request)
{
$parent = get_post($request['parent_id']);
if (!$request['parent_id'] || !$parent || $this->parent_post_type !== $parent->post_type) {
return new WP_Error('rest_post_invalid_parent_id', __('Invalid post parent ID.'), array('status' => 404));
}
$revisions = wp_get_post_revisions($request['parent_id']);
$struct = array();
foreach ($revisions as $revision) {
$struct[] = $this->prepare_item_for_response($revision, $request);
}
return $struct;
}
开发者ID:nathansh,项目名称:gifzone,代码行数:19,代码来源:class-wp-rest-revisions-controller.php
示例10: get_items
/**
* Get a collection of revisions
*
* @param WP_REST_Request $request Full data about the request.
* @return WP_Error|WP_REST_Response
*/
public function get_items($request)
{
$parent = get_post($request['parent_id']);
if (!$request['parent_id'] || !$parent || $this->parent_post_type !== $parent->post_type) {
return new WP_Error('rest_post_invalid_parent_id', __('Invalid post parent id.'), array('status' => 404));
}
$revisions = wp_get_post_revisions($request['parent_id']);
$response = array();
foreach ($revisions as $revision) {
$data = $this->prepare_item_for_response($revision, $request);
$response[] = $this->prepare_response_for_collection($data);
}
return rest_ensure_response($response);
}
开发者ID:Datartisan,项目名称:datartery-wp,代码行数:20,代码来源:class-wp-rest-revisions-controller.php
示例11: setUp
public function setUp()
{
parent::setUp();
$this->post_id = $this->factory->post->create();
$this->page_id = $this->factory->post->create(array('post_type' => 'page'));
$this->editor_id = $this->factory->user->create(array('role' => 'editor'));
$this->contributor_id = $this->factory->user->create(array('role' => 'contributor'));
wp_update_post(array('post_content' => 'This content is better.', 'ID' => $this->post_id));
wp_update_post(array('post_content' => 'This content is marvelous.', 'ID' => $this->post_id));
$revisions = wp_get_post_revisions($this->post_id);
$this->revision_1 = array_pop($revisions);
$this->revision_id1 = $this->revision_1->ID;
$this->revision_2 = array_pop($revisions);
$this->revision_id2 = $this->revision_2->ID;
}
开发者ID:nathansh,项目名称:gifzone,代码行数:15,代码来源:test-rest-revisions-controller.php
示例12: get
/**
* Get revisions for a post
*
* @since 0.9.5
*
* @param array $data
*
* @return array
*/
public static function get($data)
{
$args = array();
if (isset($data['limit'])) {
$args['posts_per_page'] = $data['limit'];
} else {
$args['posts_per_page'] = 6;
// we start at revision 0
}
$revisions = wp_get_post_revisions($data['postid'], $args);
if (is_array($revisions) && !empty($revisions)) {
self::set_revisions($data['postid'], $revisions);
}
return self::$revisions;
}
开发者ID:rhurling,项目名称:lasso,代码行数:24,代码来源:revision.php
示例13: hook
/**
* Conditionally hooks the filters needed to fetch a revision meta data.
*/
public function hook()
{
$is_event_revision = $this->is_previewing() || $this->is_saving_preview();
if ($is_event_revision) {
$this->event_id = $this->get_event_id();
if (empty($this->event_id)) {
return;
}
$revisions = wp_get_post_revisions($this->event_id);
if (empty($revisions)) {
return;
}
$this->latest_revision = reset($revisions);
add_filter('get_post_metadata', array($this, 'intercept_post_metadata'), 50, 4);
}
}
开发者ID:nullify005,项目名称:shcc-website,代码行数:19,代码来源:Preview.php
示例14: get_revisions
/**
* Get revisions for a specific post.
*
* @param int $id Post ID
* @uses wp_get_post_revisions
* @return WP_JSON_Response
*/
public function get_revisions($id)
{
$id = (int) $id;
$parent = get_post($id, ARRAY_A);
if (empty($id) || empty($parent['ID'])) {
return new WP_Error('json_post_invalid_id', __('Invalid post ID.'), array('status' => 404));
}
if (!json_check_post_permission($parent, 'edit')) {
return new WP_Error('json_cannot_view', __('Sorry, you cannot view the revisions for this post.'), array('status' => 403));
}
// Todo: Query args filter for wp_get_post_revisions
$revisions = wp_get_post_revisions($id);
$struct = array();
foreach ($revisions as $revision) {
$post = get_object_vars($revision);
$struct[] = $this->prepare_post($post, 'view-revision');
}
return $struct;
}
开发者ID:safetycat,项目名称:edibleurban,代码行数:26,代码来源:class-wp-json-posts.php
示例15: get_revisions
/**
* Get revisions for a specific post.
*
* @param int $id Post ID
* @uses wp_get_post_revisions
* @return WP_JSON_Response
*/
public function get_revisions($id)
{
$id = (int) $id;
$parent = get_post($id, ARRAY_A);
if (empty($id) || empty($parent['ID'])) {
json_error(BigAppErr::$post['code'], "Invalid post ID.");
}
if (!json_check_post_permission($parent, 'edit')) {
json_error(BigAppErr::$post['code'], __("Sorry, you cannot view the revisions for this post."));
}
// Todo: Query args filter for wp_get_post_revisions
$revisions = wp_get_post_revisions($id);
$struct = array();
foreach ($revisions as $revision) {
$post = get_object_vars($revision);
$struct[] = $this->prepare_post($post, 'view-revision');
}
return $struct;
}
开发者ID:Mushan3420,项目名称:BigApp-PHP7,代码行数:26,代码来源:class-wp-json-posts.php
示例16: list_post_revisions
function list_post_revisions($post)
{
if ($revisions = wp_get_post_revisions($post->ID)) {
$items = '';
$revision_id = valid_revision_id() ? $revision_id = $_GET['revision'] : $post->ID;
foreach ($revisions as $revision) {
$date = wp_post_revision_title($revision, 0);
$name = get_author_name($revision->post_author);
$query_string = get_query_string($revision);
$items .= "<li>";
if ($revision_id == $revision->ID) {
$items .= "{$date} by {$name} (<em>displayed above</em>)";
} else {
$items .= "<a href=\"{$query_string}\">{$date}</a> by {$name}";
}
$items .= "</li>";
}
return "<ul class='revision-list'>{$items}</ul>";
}
}
开发者ID:jkeyes,项目名称:revision-history-wordpress-plugin,代码行数:20,代码来源:revision_history.php
示例17: wp_save_post_revision
/**
* Saves an already existing post as a post revision.
*
* Typically used immediately prior to post updates.
*
* @package WordPress
* @subpackage Post_Revisions
* @since 2.6.0
*
* @uses _wp_put_post_revision()
*
* @param int $post_id The ID of the post to save as a revision.
* @return mixed Null or 0 if error, new revision ID, if success.
*/
function wp_save_post_revision($post_id)
{
// We do autosaves manually with wp_create_post_autosave()
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return;
}
// WP_POST_REVISIONS = 0, false
if (!WP_POST_REVISIONS) {
return;
}
if (!($post = get_post($post_id, ARRAY_A))) {
return;
}
if (!post_type_supports($post['post_type'], 'revisions')) {
return;
}
$return = _wp_put_post_revision($post);
// WP_POST_REVISIONS = true (default), -1
if (!is_numeric(WP_POST_REVISIONS) || WP_POST_REVISIONS < 0) {
return $return;
}
// all revisions and (possibly) one autosave
$revisions = wp_get_post_revisions($post_id, array('order' => 'ASC'));
// WP_POST_REVISIONS = (int) (# of autosaves to save)
$delete = count($revisions) - WP_POST_REVISIONS;
if ($delete < 1) {
return $return;
}
$revisions = array_slice($revisions, 0, $delete);
for ($i = 0; isset($revisions[$i]); $i++) {
if (false !== strpos($revisions[$i]->post_name, 'autosave')) {
continue;
}
wp_delete_post_revision($revisions[$i]->ID);
}
return $return;
}
开发者ID:BGCX261,项目名称:zombie-craft-svn-to-git,代码行数:51,代码来源:post.php
示例18: wp_prepare_revisions_for_js
/**
* Prepare revisions for JavaScript.
*
* @since 3.6.0
*
* @param object $post The post object.
* @param int $selected_revision_id The selected revision id.
* @param int $from (optional) The revision id to compare from.
*
* @return array An associative array of revision data and related settings.
*/
function wp_prepare_revisions_for_js($post, $selected_revision_id, $from = null)
{
$post = get_post($post);
$revisions = $authors = array();
$now_gmt = time();
$revisions = wp_get_post_revisions($post->ID, array('order' => 'ASC', 'check_enabled' => false));
// If revisions are disabled, we only want autosaves and the current post.
if (!wp_revisions_enabled($post)) {
foreach ($revisions as $revision_id => $revision) {
if (!wp_is_post_autosave($revision)) {
unset($revisions[$revision_id]);
}
}
$revisions = array($post->ID => $post) + $revisions;
}
$show_avatars = get_option('show_avatars');
cache_users(wp_list_pluck($revisions, 'post_author'));
$can_restore = current_user_can('edit_post', $post->ID);
foreach ($revisions as $revision) {
$modified = strtotime($revision->post_modified);
$modified_gmt = strtotime($revision->post_modified_gmt);
if ($can_restore) {
$restore_link = str_replace('&', '&', wp_nonce_url(add_query_arg(array('revision' => $revision->ID, 'action' => 'restore'), admin_url('revision.php')), "restore-post_{$revision->ID}"));
}
if (!isset($authors[$revision->post_author])) {
$authors[$revision->post_author] = array('id' => (int) $revision->post_author, 'avatar' => $show_avatars ? get_avatar($revision->post_author, 32) : '', 'name' => get_the_author_meta('display_name', $revision->post_author));
}
$autosave = (bool) wp_is_post_autosave($revision);
$current = !$autosave && $revision->post_modified_gmt === $post->post_modified_gmt;
if ($current && !empty($current_id)) {
// If multiple revisions have the same post_modified_gmt, highest ID is current.
if ($current_id < $revision->ID) {
$revisions[$current_id]['current'] = false;
$current_id = $revision->ID;
} else {
$current = false;
}
} elseif ($current) {
$current_id = $revision->ID;
}
$revisions[$revision->ID] = array('id' => $revision->ID, 'title' => get_the_title($post->ID), 'author' => $authors[$revision->post_author], 'date' => date_i18n(__('M j, Y @ G:i'), $modified), 'dateShort' => date_i18n(_x('j M @ G:i', 'revision date short format'), $modified), 'timeAgo' => sprintf(__('%s ago'), human_time_diff($modified_gmt, $now_gmt)), 'autosave' => $autosave, 'current' => $current, 'restoreUrl' => $can_restore ? $restore_link : false);
}
// If a post has been saved since the last revision (no revisioned fields were changed)
// we may not have a "current" revision. Mark the latest revision as "current".
if (empty($current_id)) {
if ($revisions[$revision->ID]['autosave']) {
$revision = end($revisions);
while ($revision['autosave']) {
$revision = prev($revisions);
}
$current_id = $revision['id'];
} else {
$current_id = $revision->ID;
}
$revisions[$current_id]['current'] = true;
}
// Now, grab the initial diff
$compare_two_mode = is_numeric($from);
if (!$compare_two_mode) {
$found = array_search($selected_revision_id, array_keys($revisions));
if ($found) {
$from = array_keys(array_slice($revisions, $found - 1, 1, true));
$from = reset($from);
} else {
$from = 0;
}
}
$from = absint($from);
$diffs = array(array('id' => $from . ':' . $selected_revision_id, 'fields' => wp_get_revision_ui_diff($post->ID, $from, $selected_revision_id)));
return array('postId' => $post->ID, 'nonce' => wp_create_nonce('revisions-ajax-nonce'), 'revisionData' => array_values($revisions), 'to' => $selected_revision_id, 'from' => $from, 'diffData' => $diffs, 'baseUrl' => parse_url(admin_url('revision.php'), PHP_URL_PATH), 'compareTwoMode' => absint($compare_two_mode), 'revisionIds' => array_keys($revisions));
}
开发者ID:pankajsinghjarial,项目名称:SYLC-AMERICAN,代码行数:82,代码来源:revision.php
示例19: wp_getRevisions
/**
* Retrieve revisions for a specific post.
*
* @since 3.5.0
*
* The optional $fields parameter specifies what fields will be included
* in the response array.
*
* @uses wp_get_post_revisions()
* @see wp_getPost() for more on $fields
*
* @param array $args Method parameters. Contains:
* - int $blog_id (unused)
* - string $username
* - string $password
* - int $post_id
* - array $fields
* @return array|IXR_Error contains a collection of posts.
*/
public function wp_getRevisions($args)
{
if (!$this->minimum_args($args, 4)) {
return $this->error;
}
$this->escape($args);
$username = $args[1];
$password = $args[2];
$post_id = (int) $args[3];
if (isset($args[4])) {
$fields = $args[4];
} else {
/**
* Filter the default revision query fields used by the given XML-RPC method.
*
* @since 3.5.0
*
* @param array $field An array of revision query fields.
* @param string $method The method name.
*/
$fields = apply_filters('xmlrpc_default_revision_fields', array('post_date', 'post_date_gmt'), 'wp.getRevisions');
}
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.getRevisions');
if (!($post = get_post($post_id))) {
return new IXR_Error(404, __('Invalid post ID'));
}
if (!current_user_can('edit_post', $post_id)) {
return new IXR_Error(401, __('Sorry, you are not allowed to edit posts.'));
}
// Check if revisions are enabled.
if (!wp_revisions_enabled($post)) {
return new IXR_Error(401, __('Sorry, revisions are disabled.'));
}
$revisions = wp_get_post_revisions($post_id);
if (!$revisions) {
return array();
}
$struct = array();
foreach ($revisions as $revision) {
if (!current_user_can('read_post', $revision->ID)) {
continue;
}
// Skip autosaves
if (wp_is_post_autosave($revision)) {
continue;
}
$struct[] = $this->_prepare_post(get_object_vars($revision), $fields);
}
return $struct;
}
开发者ID:sb-xs,项目名称:que-pour-elle,代码行数:73,代码来源:class-wp-xmlrpc-server.php
示例20: wp_ajax_get_revision_diffs
/**
* Ajax handler for getting revision diffs.
*
* @since 3.6.0
*/
function wp_ajax_get_revision_diffs()
{
require ABSPATH . 'wp-admin/includes/revision.php';
if (!($post = get_post((int) $_REQUEST['post_id']))) {
wp_send_json_error();
}
if (!current_user_can('read_post', $post->ID)) {
wp_send_json_error();
}
// Really just pre-loading the cache here.
if (!($revisions = wp_get_post_revisions($post->ID, array('check_enabled' => false)))) {
wp_send_json_error();
}
$return = array();
@set_time_limit(0);
foreach ($_REQUEST['compare'] as $compare_key) {
list($compare_from, $compare_to) = explode(':', $compare_key);
// from:to
$return[] = array('id' => $compare_key, 'fields' => wp_get_revision_ui_diff($post, $compare_from, $compare_to));
}
wp_send_json_success($return);
}
开发者ID:hughnet,项目名称:WordPress,代码行数:27,代码来源:ajax-actions.php
注:本文中的wp_get_post_revisions函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论