Make WordPress Core

Opened 13 years ago

Closed 13 years ago

Last modified 13 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
Priority: normal Milestone: 3.7.1
Component: Taxonomy Version: 3.7
Severity: normal Keywords:
Cc: Focuses:

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 13 years ago.

Download all attachments as: .zip

Change History (13)

#1 @n.uddin.w
13 years ago

  • Keywords has-patch added

#2 @ocean90
13 years ago

  • Component GeneralTaxonomy
  • Keywords needs-patch added; has-patch removed
  • Milestone Awaiting Review3.7.1
  • Summary in_category function in wp 3.7in_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
13 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
13 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
13 years ago

  • Keywords needs-unit-tests added

#6 in reply to: ↑ 4 @ericlewis
13 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
13 years ago

#8 @ericlewis
13 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
13 years ago

  • Owner set to nacin
  • Resolutionfixed
  • Status newclosed

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
13 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
13 years ago

  • Keywords needs-unit-tests removed

#12 @ericlewis
13 years ago

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