WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#25706 closed defect (bug) (fixed)

in_category() returns true if the first parameter is empty

Reported by: n.uddin.w Owned by: nacin
Milestone: 3.7.1 Priority: normal
Severity: normal Version: 3.7
Component: Taxonomy Keywords:
Focuses: Cc:
PR Number:

Description

in wp 3.7, in_category function returns true if the first parameter ($category) is an empty array or null.

in_category( $category, $_post )

Attachments (1)

25706.diff (1.3 KB) - added by ericlewis 6 years ago.

Download all attachments as: .zip

Change History (13)

#1 @n.uddin.w
6 years ago

  • Keywords has-patch added

#2 @ocean90
6 years ago

  • Component changed from General to Taxonomy
  • Keywords needs-patch added; has-patch removed
  • Milestone changed from Awaiting Review to 3.7.1
  • Summary changed from in_category function in wp 3.7 to in_category() returns true if the first parameter is empty

Could reproduce this.

3.6:
var_dump( in_category( '', 1177) ); // bool(false)

3.7:
var_dump( in_category( '', 1177) ); // bool(true)

#3 @ocean90
6 years ago

This belongs to [25119]. There was an empty() check which is gone now.

has_tag() returns also true, but in 3.6 too. Should we add the empty() check to has_term() directly?

#4 follow-up: @nacin
6 years ago

has_tag() returns also true, but in 3.6 too.

Let's reduce the regression here and not cause any others. Did it return false at any point previously?

#5 @nacin
6 years ago

  • Keywords needs-unit-tests added

#6 in reply to: ↑ 4 @ericlewis
6 years ago

Replying to nacin:

Did has_tag() return false at any point previously?

No, it hasn't since its inception in 3.1. The long description of the has_term() is spot on here - "If no terms are given, determines if post has any terms." since it uses is_object_in_term(), which has that logic built into it. And since every category always has at least one term, that's why we're seeing the true return in the OP's example.

Let's add the empty( $category ) check back into in_category() to fix the regression, and leave has_tag() as-is.

@ericlewis
6 years ago

#8 @ericlewis
6 years ago

attachment:25706.diff

  • brings back the empty() check in in_category()
  • adds a test for passing falsy values to in_category() which should return false, as well as testing for a positive result.

#9 @nacin
6 years ago

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

In 25923:

3.7 regression from [25119]: Have in_category() return false when the first argument is empty.

Adds unit tests.

props ericlewis.
fixes #25706 for trunk.

#10 @nacin
6 years ago

In 25924:

3.7 regression from [25119]: Have in_category() return false when the first argument is empty.

Merges [25923] to the 3.7 branch.

props ericlewis.
fixes #25706.

#11 @ericmann
6 years ago

  • Keywords needs-unit-tests removed

#12 @ericlewis
6 years ago

  • Keywords needs-patch removed
Note: See TracTickets for help on using tickets.