Ticket #5381 (new defect)

Opened 1 year ago

Last modified 1 year ago

type mismatch between is_term and get_term_by

Reported by: tellyworth Assigned to: anonymous
Priority: normal Milestone: 2.9
Component: General Version:
Severity: normal Keywords:
Cc:

Description

get_term_by() and similar functions return a row that includes the term_id as a numeric string. is_term() requires that a term_id be passed in as an int; a numeric string will fail.

I don't know what the solution is but this seems like a likely cause of bugs. Code that looks like it ought to work fails:

	$term_id = get_term_by('name', $term, $taxonomy);
	if ( is_term($term_id) ) ... // fails because is_term returns false

test_is_term_type() in http://svn.automattic.com/wordpress-tests/wp-testcase/test_includes_taxonomy.php reproduces the problem.

There are other related type inconsistencies in taxonomy.php also - for example, is_term() returns a 0, NULL, term ID, WP_Error object or row object depending on the context and circumstances, which makes handling the return result difficult. Mostly due I think to the functions being overloaded to magically handle both term ids and names.

Change History

11/23/07 17:24:42 changed by ryan

Overloading was a mistake, but here we are. Part of the problem is that we changed sanitize_term() to return immediately for the raw context. It should probably do int casts for the IDs before returning.