Make WordPress Core

Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#22686 closed defect (bug) (duplicate)

wp.getRevisions returns auto-drafts

Reported by: maxcutler's profile maxcutler Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.5
Component: XML-RPC Keywords: needs-patch
Focuses: Cc:

Description

The wp.getRevisions XML-RPC method (added in 3.5 trunk) will return auto-drafts for a post if they still exist. Auto-saves are filtered out correctly, but not auto-drafts. Since any post created using XML-RPC will have an auto-draft (due to the implementation of wp.newPost), this adds unnecessary burden on clients to filter out the meaningless auto draft.

I'm not sure what the best way to check if a post is an auto-draft, so I've omitted a patch for now. Would be nice to see this in 3.5, but I understand if it has to be punted.

Change History (5)

#1 @nacin
12 years ago

Hmm. Not sure I understand. auto-drafts are the actual post object before it is converted to a regular draft (or pending post, or published post).

Let's say you have post 5, and want revisions for it. wp_get_post_revisions(), which is used by wp.getRevisions, returns all items with post_type = 'revision' and post_parent = 5. We then filter out autosaves, as autosaves are special kind of revision.

An auto-draft would look like this: ID = 5, post_type = 'post', post_status = 'auto-draft'.

Revisions all get a status of 'inherit' (thus inheriting its parent status), but it's not possible to create a revision against auto-draft, since saving the post to create a revision by definition will promote 'auto-draft' to 'draft'.

#2 @maxcutler
12 years ago

If you create a new post with a title using wp.newPost, and then call wp.getRevisions, you will get two revisions back: one with your "real" title and one with a title "Auto Draft".

The "Auto Draft" one does indeed have a post_status of "inherit", so it's not clear to me why it is surviving the wp.newPost code.

#3 @maxcutler
12 years ago

For repro, try this unit test which fails:

function test_revision_count2() {
	$this->make_user_by_role( 'editor' );

	$post_id = $this->myxmlrpcserver->wp_newPost( array( 1, 'editor', 'editor', array(
		'post_title' => 'Original title',
		'post_content' => 'Test'
		) ) );
	
	$result = $this->myxmlrpcserver->wp_getRevisions( array( 1, 'editor', 'editor', $post_id ) );	
	$this->assertCount( 0, $result );
}

#4 @nacin
12 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Great, that helps a lot. It's a much deeper bug, so I opened #22687 instead.

When a post is created with wp_insert_post(), it will have zero revisions, as verified with test_revision_count().

When a post is created with get_default_post_to_edit(), such as via XML-RPC or the standard Add New screen, it will end up with a single revision. This is the revision you are seeing.

The fix for 3.5 should be to set the post_title properly on this first revision. In 3.6, I'd like to avoid the revision all together.

#5 @nacin
12 years ago

In 22989:

Do not save an initial revision for a post created through the auto-draft mechanism. Prevents a bogus revision, often with the title 'Auto Draft'. Restores pre-auto-draft behavior made obvious by XML-RPC's implementation of both auto-drafts and the subsequent wp.getRevisions method. fixes #22687. see #22686.

Note: See TracTickets for help on using tickets.