Make WordPress Core

Opened 11 years ago

Closed 11 years ago

#26686 closed defect (bug) (fixed)

XMLRPC call will not remove all terms in a taxonomy when passed an empty array

Reported by: jstraitiff's profile jstraitiff Owned by: nacin's profile nacin
Milestone: 3.9 Priority: normal
Severity: normal Version: 3.4
Component: XML-RPC Keywords: has-patch
Focuses: Cc:

Description

When calling wp.editPost from XMLRPC, if you pass an empty array for a set of terms it will not remove all the terms in that taxonomy for a post. If the array has even one term id in it, it will set it properly, but empty arrays get ignored and thus don't change the current terms.

I found and fixed the issue and have attached a patch. I'm adding one line in _insert_post (in wp-includes/class-wp-xmlrpc-server.php) to initialize the $terms array for a particular taxonomy, thus when the following foreach is called (and skips because of the empty array) then an empty array will be passed along and cause the terms deletion to happen.

Attachments (2)

_insert_post.patch (580 bytes) - added by jstraitiff 11 years ago.
26686.patch (1.9 KB) - added by maxcutler 11 years ago.

Download all attachments as: .zip

Change History (8)

#1 follow-up: @markoheijnen
11 years ago

Related #25037

#2 in reply to: ↑ 1 @dinomic
11 years ago

Replying to markoheijnen:

Related #25037

markoheijnen, it's "related" but it's not the same issue. jstraitiff reported the issue with regards to terms and your related link is to do with categories.

I know that the official terminology refers to them both as being "taxonomies", but a bug definitely exists! Sure, the related link points to the fact that there should always be at least 1 selected category, but I'm not aware of a similar rule existing for terms.

I tried jstraitiff's fix on our test server, but it doesn't resolve the problem completely. Here's an example:
1) The current state of our post is assigned to the "Uncategorized" category, and the term "News"
2) I want to remove the Term "News", so I remove it and send the XML. Our app sends terms as "terms_names" and the categories as "terms" (see XML snippet below). However, "News" still stays attached to the post.

	<member><name>terms_names</name><value><struct>
		<member><name>post_tag</name><value>
			<array><data></data></array>
		</value></member>
	</struct></value></member>
	<member><name>terms</name><value><struct>
	<member><name>category</name><value>
		<array><data>
			<value><int>1</int></value>
		</data></array>
	</value></member>
	</struct></value></member>

#3 @SergeyBiryukov
11 years ago

#27194 was marked as a duplicate.

#4 @SergeyBiryukov
11 years ago

  • Keywords has-patch added
  • Milestone changed from Awaiting Review to 3.9
  • Version changed from 3.7.1 to 3.4

#27194 was marked for 3.9.

@maxcutler
11 years ago

#5 @maxcutler
11 years ago

Updated the patch with the unit test I had on #27194.

#6 @nacin
11 years ago

  • Owner set to nacin
  • Resolution set to fixed
  • Status changed from new to closed

In 27554:

XML-RPC: In wp.editPost, Remove all terms in a taxonomy when an empty array is explicitly passed.

props jstraitiff, maxcutler.
fixes #26686.

Note: See TracTickets for help on using tickets.