#18009 closed defect (bug) (wontfix)

term_exists uses is_int so '0' does not equal 0 and so wp_set_object_terms will create 0

Reported by: agalindo Owned by:
Priority: normal Milestone:
Component: General Version: 3.1
Severity: normal Keywords:
Cc:

Description

If setting object terms and one has not type casted string 0 to integer 0 then term_exists will see this as a category name and return false, the category 0 does not exists and wp_set_object_terms will create it.

It exists on line 1452 of taxonomy.php (http://core.trac.wordpress.org/browser/tags/3.2/wp-includes/taxonomy.php#L1452)

The fix is simple, switching is_int to is_numeric

Change History (3)

comment:1 follow-up: ↓ 2   nacin23 months ago

That's actually proper behavior. The term API makes a distinct difference between a numeric string, treating it as a slug, and an integer, which it treats as an ID.

comment:2 in reply to: ↑ 1   agalindo23 months ago

Replying to nacin:

That's actually proper behavior. The term API makes a distinct difference between a numeric string, treating it as a slug, and an integer, which it treats as an ID.

It seems rather counter-intuitive to the normal PHP workflow (ignoring types, that is) to make that sort of behavior built into the term API.

Last edited 23 months ago by agalindo (previous) (diff)
  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

It is indeed confusing. A taxnomy API cleanup will happen some day. In the mean time this is what we have.

Version 0, edited 23 months ago by ryan (next)
Note: See TracTickets for help on using tickets.