本文整理汇总了PHP中wp_get_post_revisions函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_get_post_revisions函数的具体用法?PHP wp_get_post_revisions怎么用?PHP wp_get_post_revisions使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_get_post_revisions函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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));
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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));
}
示例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));
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
}
示例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;
}
示例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;
}