WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 6 years ago

#25852 closed defect (bug) (fixed)

Saving term broken. If no term parent is set - sets to term ID 1.

Reported by: mattheu Owned by: SergeyBiryukov
Milestone: 3.8 Priority: normal
Severity: normal Version: 3.8
Component: Taxonomy Keywords: has-patch
Focuses: Cc:

Description

This was introduced by the fix for ticket #17646

When saving a term with no parent selected - the parent is saved as term 1. It should be set to 0. For non-category terms - this causes them to dissapear from the admin.

From category-template.php line 346 - The term parent select field uses -1 for none - and this is now cast to 1 by the sanitize_term_field function - which saves the term parent as 1.

I've added a patch that sets any negative values to 0.

Attachments (3)

25852.diff (575 bytes) - added by mattheu 6 years ago.
25852-2.diff (381 bytes) - added by mattheu 6 years ago.
25852.3.diff (1.9 KB) - added by SergeyBiryukov 6 years ago.

Download all attachments as: .zip

Change History (7)

@mattheu
6 years ago

#1 @SergeyBiryukov
6 years ago

  • Component changed from General to Taxonomy
  • Milestone changed from Awaiting Review to 3.8
  • Version set to trunk

@mattheu
6 years ago

#2 @mattheu
6 years ago

Updated patch to not use a ternary operator

#3 @SergeyBiryukov
6 years ago

25852-2.diff would not work as expected, since $value is already changed to 1 in line 1714. The check should also be inside the in_array() condition, not after it.

25852.3.diff reverts that part of [26010] and adds a basic unit test.

#4 @SergeyBiryukov
6 years ago

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

In 26028:

A negative term parent value should be sanitized to 0, not 1. Fix a regression in sanitize_term_field() caused by [26010].

props mattheu for initial patch.
fixes #25852.

Note: See TracTickets for help on using tickets.