Ticket #6313 (assigned defect)

Opened 4 months ago

Last modified 3 months ago

When you have a custom tag slug, it will duplicate tags

Reported by: tai Assigned to: mtekk (accepted)
Priority: normal Milestone: 2.6
Component: General Version: 2.5
Severity: normal Keywords: has-patch
Cc:

Description

When you have a custom tag slug that is different from the tag name, you will have duplicate tags after saving a post with the tag.

Steps to reproduce (I reproduced with trunk r 7414.):

  1. Make a new tag at Manage -> Tags with tag name "aaa", tag slug "bbb"
  2. Write a post, add a tag "aaa" and hit the save button
  3. Go back to Manage -> Tags, you will find two "aaa" tags

So, editing tag slugs make little sense...

Attachments

wp-admin-includes-taxonomy.diff (468 bytes) - added by mtekk on 04/03/08 22:16:37.
This patch fixes the issue where when you save twice you get double tags
wp-includes-taxonomy.diff (0.6 kB) - added by mtekk on 04/09/08 21:36:33.
This fixes lilyfan's code to follow WP code conventions

Change History

03/20/08 19:00:19 changed by lloydbudd

  • priority changed from high to normal.
  • severity changed from critical to normal.
  • milestone changed from 2.5 to 2.6.

03/28/08 15:27:33 changed by lilyfan

I think the root cause is that is_term() (at wp-includes/taxonomy.php: line around 746) only sees tag slug.

Original Code:

if ( '' === $term = sanitize_title($term) )
	return 0;
$where = $wpdb->prepare( "t.slug = %s", $term );

if is_term() recognize tag name as below, this issue will be resolved.

Patch:

if ( '' === $sanitized = sanitize_title($term) )
	return 0;
if ( $taxonomy = 'post_tag' ) {
	$where = $wpdb->prepare( "(t.slug = %s OR t.name = %s)", $sanitized , $term );
} else {
	$where = $wpdb->prepare( "t.slug = %s", $sanitized );
}

ex)
1) Make a tag name "abcde" with slug "aaa".
2) Write a post, and add "abcde" tag
3) is_term() wil pickup "abcde" tag!!

04/02/08 14:23:23 changed by mtekk

Closed #6545 as a duplicate of this bug

04/03/08 20:38:24 changed by mtekk

  • owner changed from anonymous to mtekk.
  • status changed from new to assigned.

lilyfan's code seems to not work for UTF-8 character sets, thus duplicate ticket #6545 was created. I'm looking into this.

04/03/08 22:16:37 changed by mtekk

  • attachment wp-admin-includes-taxonomy.diff added.

This patch fixes the issue where when you save twice you get double tags

04/03/08 22:20:55 changed by mtekk

  • keywords set to has-patch.

Ok, so the problem was not just related to UTF-8 characters, it was a space added in between a comma by in taxonomy.php located in wp-admin/includes on line 136. Originally:

$tags_to_edit = join( ', ', $tag_names );

Changing that line to:

$tags_to_edit = join( ',', $tag_names );

seems to fix things. Was there any reason that there was a space in there? This gets rid of all custom tag slugs causing two tags being created problems.

(follow-up: ↓ 8 ) 04/09/08 16:40:50 changed by jyoshida

if ( $taxonomy = 'post_tag' ) {

Isn't this wrong?

if ( $taxonomy == 'post_tag' ) {

04/09/08 19:38:13 changed by mtekk

Good catch jyoshida, I'll retest and post a new patch shortly

(in reply to: ↑ 6 ) 04/09/08 20:11:41 changed by Nazgul

A good way to prevent those kind of bug is to write

if ( 'constant' == $variable) ) {

This way PHP will complain if you forget an =.

04/09/08 21:36:33 changed by mtekk

  • attachment wp-includes-taxonomy.diff added.

This fixes lilyfan's code to follow WP code conventions

04/09/08 21:39:00 changed by mtekk

Nazgul, yeah I really should have looked through lilyfan's code more. It's fixed now, and using === as that's the appropriate comparator for this situation. I attached a new patch that has these changes, they appear to work as expected.