Make WordPress Core

Opened 4 months ago

Closed 5 weeks ago

#26686 closed defect (bug) (fixed)

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

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


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 4 months ago.
26686.patch (1.9 KB) - added by maxcutler 8 weeks ago.

Download all attachments as: .zip

Change History (8)

jstraitiff4 months ago

comment:1 follow-up: markoheijnen4 months ago

Related #25037

comment:2 in reply to: ↑ 1 dinomic2 months 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.


comment:3 SergeyBiryukov8 weeks ago

#27194 was marked as a duplicate.

comment:4 SergeyBiryukov8 weeks 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.

maxcutler8 weeks ago

comment:5 maxcutler8 weeks ago

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

comment:6 nacin5 weeks 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.