Make WordPress Core

Opened 14 years ago

Closed 14 years ago

Last modified 14 years ago

#22220 closed defect (bug) (fixed)

XML-RPC wp.editPost clears post categories

Reported by: yousefed Owned by: westi
Priority: normal Milestone: 3.5
Component: XML-RPC Version:
Severity: normal Keywords: has-patch commit
Cc: Focuses:

Description

According to http://codex.wordpress.org/XML-RPC_WordPress_API/Posts#wp.editPost

"Only needs to contain fields that you wish to modify; all other fields will retain their current values."

When I only post custom_fields to update the custom fields of a post (custom post type by the way, didn't check for normal posts) the categories of the post are removed (now "Unassigned").

I think the source of the problem might be the following part in wp_insert_post:

// Make sure we set a valid category.
	if ( empty($post_category) || 0 == count($post_category) || !is_array($post_category) ) {
		// 'post' requires at least one category.
		if ( 'post' == $post_type && 'auto-draft' != $post_status )
			$post_category = array( get_option('default_category') );
		else
			$post_category = array();
	}

Attachments (1)

22220.diff (597 bytes ) - added by nacin 14 years ago.

Download all attachments as: .zip

Change History (17)

#1 @markoheijnen
14 years ago

  • Owner set to markoheijnen
  • Status newassigned

You are using the build in taxonomy "Category" or are you using a custom taxonomy?

Maybe this is related: #19954?

#2 @yousefed
14 years ago

Seems somewhat related, but the patch won't fix the issue for non-'post' post types

Version 0, edited 14 years ago by yousefed (next)

#3 @markoheijnen
14 years ago

  • Milestone Awaiting Review
  • Resolutionduplicate
  • Status assignedclosed

I close this as duplicate. Since it is the same issue as #19954. The patch I wrote doesn't seem to fix it properly then.
I will start writing unit tests for it and hopefully this can be fixed in 3.5

#4 @yousefed
14 years ago

My apologies, I retried and the patch from #19954 does seem to resolve the issue. Thanks.

#5 @SergeyBiryukov
14 years ago

  • Component GeneralXML-RPC

#6 @nacin
14 years ago

  • Milestone3.5
  • Resolution duplicate
  • Status closedreopened

A switch to wp_update_post would be sufficient to fix XML-RPC.

#7 follow-up: @nacin
14 years ago

What are we doing here? I don't know how feasible it is to switch the _insert_post() method to wp_update_post(). This needs unit tests, I gather.

#8 @MikeHansenMe
14 years ago

  • Keywords needs-unit-tests added

#9 in reply to: ↑ 7 @westi
14 years ago

  • Keywords needs-patch punt added

Replying to nacin:

What are we doing here? I don't know how feasible it is to switch the _insert_post() method to wp_update_post(). This needs unit tests, I gather.

We definitely need some tests to cover this agreed.

I also think that we should maybe make _insert_post() work differently for new/editing as we should be using wp_update_post when editing for sure.

@nacin
14 years ago

#10 follow-up: @nacin
14 years ago

  • Keywords has-patch added; needs-patch removed

#11 in reply to: ↑ 10 @westi
14 years ago

Replying to nacin:

Thanks, I guess we just need the requisite tests now ;)

#12 follow-up: @nacin
14 years ago

  • Keywords commit added; needs-unit-tests punt removed
  • Owner changed from markoheijnen to westi
  • Status reopenedassigned

Basic unit test in [UT1133].

#13 in reply to: ↑ 12 @westi
14 years ago

Replying to nacin:

Basic unit test in [UT1133].

Fixed up in [UT1137] as it was broken.

#14 @westi
14 years ago

  • Resolutionfixed
  • Status assignedclosed

In 22584:

XMLRPC: When Editing an existing post make sure to use wp_update_post instead of wp_insert_post so as to not perform destructive actions on the content.

The wp.EditPost() API will accept very limited data to only edit specific attributes of a post, if you didn't supply a category change then we would previously
overwrite the original categories with the default cat.

Fixes #22220 props nacin.

#15 @nacin
14 years ago

The check for IXR_Error makes sense, but I can't reproduce "Previously the test created a post that the test user couldn't edit and so the Post Editing failed." [UT1137] The user was an editor and should have been able to modify any post. The test passed for me (with patch applied), which included the updating of the post title. Perhaps something to look into your local copy of the tests.

#16 @nacin
14 years ago

Seems that only occurs when the test suite is run as a whole.

Note: See TracTickets for help on using tickets.