Make WordPress Core

Opened 16 years ago

Closed 15 years ago

#9323 closed defect (bug) (fixed)

Legacy get_category_link function call in get_term_link function should probably use $term->ID or be removed

Reported by: ev3rywh3re's profile ev3rywh3re Owned by: ryan's profile ryan
Milestone: 2.8 Priority: normal
Severity: normal Version: 2.8
Component: Taxonomy Keywords: has-patch tested commit
Focuses: Cc:

Description

To replicate this bug in a loop somehow use something like:

$cats = get_the_term_list( $post->ID, 'category', '', '|', '' );

In this case get_the_term_list puts together a term object but then when it calls get_term_link the get_term_link function tries to pass the term object to get_category_link which is really asking for a category ID.

The culprit is wp-includes/taxonomy.php lines 2122-2123

	if ( $taxonomy == 'category' )
		return get_category_link($term);

For testing I removed that line and it worked when using get_the_term_list from the example. I also modified $term to pass $term->ID instead and that worked as well. There's no patch because it has multiple solutions and I don't think I have enough test cases to make a proper judgment call for a solution.

I know category functions need to be modified to use the taxonomy functions more elegantly. I also know this is considered an internal function and get_the_category_list should be used instead, but I mistakenly thought get_the_term_list was pretty cool looking.

Attachments (1)

get_term_link.9323.diff (1.8 KB) - added by filosofo 15 years ago.

Download all attachments as: .zip

Change History (20)

#1 follow-up: @ev3rywh3re
16 years ago

Great, I may have reported too soon. It may be a Dreamhost PHP CGI issue. Other systems I maintain don't seem to cause an error. Switching that domain to Fast-CGI fixed it. The error does not reproduce on the mod_php version 4.x or 5.x servers I maintain.

#2 in reply to: ↑ 1 @filosofo
16 years ago

  • Keywords has-patch added

Replying to ev3rywh3re:

Great, I may have reported too soon. It may be a Dreamhost PHP CGI issue. Other systems I maintain don't seem to cause an error. Switching that domain to Fast-CGI fixed it. The error does not reproduce on the mod_php version 4.x or 5.x servers I maintain.

Actually, what you're probably seeing is that the bug shows up only if "pretty" permalinks are not enabled.

I've attached a patch with what I think is the best solution: make get_term_link() accept only a term id as its first argument, instead of the multiple options it currently (sorta) does: term object, term id, or term slug.

This is only place in core WP where get_term_link() is called with something that might not be a term ID, and that can easily be corrected (see patch). Also, both get_category_link() and get_tag_link() expect term IDs, so it's consistent behavior to require the ID.

#3 follow-up: @Denis-de-Bernardy
15 years ago

  • Keywords needs-patch added; has-patch removed

there would be a few calls to get_term_link() that would need to be changed, no? namely in get_the_taxonomies()

#4 in reply to: ↑ 3 @filosofo
15 years ago

  • Keywords has-patch added; needs-patch removed

Replying to Denis-de-Bernardy:

there would be a few calls to get_term_link() that would need to be changed, no? namely in get_the_taxonomies()

Don't know why I missed that one, but I've refreshed the patch.

#5 follow-up: @Denis-de-Bernardy
15 years ago

  • Keywords tested 2nd-opinion added

I dunno how many plugins this'll break if any were relying on get_term_link($term) to work, but patch works.

An alternative approach would be to make get_tag_link and get_category_link work with terms too.

#6 in reply to: ↑ 5 @filosofo
15 years ago

Replying to Denis-de-Bernardy:

I dunno how many plugins this'll break if any were relying on get_term_link($term) to work, but patch works.

Just for fun I grepped through the plugins repository. Of over 7000 plugins, 3 call get_term_link() and only 1 of them, Custom Taxonomies, passes something other than a term id to the first argument. If we can commit this, I'll be happy to send the author an email to let him know.

#7 @Denis-de-Bernardy
15 years ago

  • Keywords commit added; 2nd-opinion removed

I'm +1 to the patch, then.

#8 @Denis-de-Bernardy
15 years ago

  • Keywords needs-patch added; has-patch tested commit removed

broken patch

#9 @filosofo
15 years ago

  • Keywords has-patch commit added; needs-patch removed

Refreshed the patch.

#10 @Denis-de-Bernardy
15 years ago

  • Keywords tested added

+1

#11 @filosofo
15 years ago

Refreshed patch again against [11257]

#12 @ryan
15 years ago

Whoops, didn't see this one.

#13 @Denis-de-Bernardy
15 years ago

broken again. :-(

#14 @Denis-de-Bernardy
15 years ago

  • Keywords needs-patch added; has-patch commit removed

#15 @Denis-de-Bernardy
15 years ago

  • Keywords has-patch commit added; get_the_term_list get_term_link get_category_link needs-patch removed

nevermind. svn updated and it worked.

#16 @ryan
15 years ago

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

(In [11263]) Accept only IDs for get_term_link(). Prop filosofo. fixes #9323

#17 @ryan
15 years ago

(In [11324]) Revert [11263]. Busted several themes. see #9323

#18 @ryan
15 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

This broke several themes and plugins, especially ones that used get_term_link() as part of their custom taxonomy support.

#19 @ryan
15 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

I think [11257] fixed the core problem.

Note: See TracTickets for help on using tickets.