Ticket #6313 (closed defect (bug): duplicate)

Opened 4 years ago

Last modified 4 years ago

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

Reported by: tai Owned by: mtekk
Priority: normal Milestone:
Component: General Version: 2.6
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 Download (468 bytes) - added by mtekk 4 years ago.
This patch fixes the issue where when you save twice you get double tags
wp-includes-taxonomy.diff Download (652 bytes) - added by mtekk 4 years ago.
This fixes lilyfan's code to follow WP code conventions

Change History

  • Priority changed from high to normal
  • Severity changed from critical to normal
  • Milestone changed from 2.5 to 2.6

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!!

Closed #6545 as a duplicate of this bug

  • 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.

mtekk4 years ago

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

  • Keywords has-patch added

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.

comment:6 follow-up: ↓ 8   jyoshida4 years ago

if ( $taxonomy = 'post_tag' ) {

Isn't this wrong?

if ( $taxonomy == 'post_tag' ) {

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

comment:8 in reply to: ↑ 6   Nazgul4 years ago

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

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

This way PHP will complain if you forget an =.

mtekk4 years ago

This fixes lilyfan's code to follow WP code conventions

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.

  • Version changed from 2.5 to 2.6

WordPress 2.6 can not use this patch

  • Milestone 2.9 deleted

So you're saying the patches won't work in 2.6 (and the problem still exists). I'll look at that this evening.

  • Milestone set to 2.7

Ok, in [8367] we still have this problem. The old patches do not fully fix the problem any longer. Now UTF-8 stuff just plainly fails on insert when in the write post part. Something else changed in taxonomy.php it looks like.

Can someone else verify that the old patches do not work with 2.6? Also can someone verify that UTF-8 tags do not work correctly either?

yes! i'm using ZH-TW to written my blog,it's pitches works on 2.5.x but when I up to 2.6 , I try to fixed it by same way. It's not works.

and the UTF-8 Tag url works good but when I set the slug for those tag, It will duplicate again...

"Something else changed in taxonomy.php it looks like. " I think it the really! and so sad it happen again...not in the fix-list of WP 2.6.

Could mtekk help us to fixed it?

I'll keep fallow this post, if u need any test or verify, I'll give a hand!

It may be a week or so before I can fully dig into this (unless I can sneak some work in on it tomorrow), if one of the developers wants to pick this up go ahead, the wp-admin-includes-taxonomy.diff patch should still be applied, but wp-includes-taxonomy.diff needs to be expanded upon.

If I insert a UTF-8 character into the Tags field in the Edit Post form, it seems to not like saving it. Which is back to square one again.

comment:15 follow-up: ↓ 17   ryan4 years ago

Possibly related to #6867. Trying applying the patches here on top of the new taxonomy.php file linked there.

  • Status changed from assigned to closed
  • Resolution set to duplicate
  • Milestone 2.7 deleted

#6593 has some fresh patches to try. I'm going to mark this ticket as a duplicate of that and do the bug fixing over there.

comment:17 in reply to: ↑ 15   rocavence4 years ago

Replying to ryan:

Possibly related to #6867. Trying applying the patches here on top of the new taxonomy.php file linked there.

the #6967 does not fixed the problem of tag duplicate......it very important for Asia user of Chinese, Korean, Japanese, so hold u guys could help!

comment:18 follow-up: ↓ 19   ryan4 years ago

I know #6867 doesn't fix this ticket. It probably will fix the problem mtekk described in comments 12 and 13, which is a separate issue that compounds the problem described here. Regardless, #6593 has the latest patch to try. You'll need the latest from the 2.6 branch to use it though.

comment:19 in reply to: ↑ 18 ; follow-up: ↓ 21   rocavence4 years ago

Replying to ryan:

I know #6867 doesn't fix this ticket. It probably will fix the problem mtekk described in comments 12 and 13, which is a separate issue that compounds the problem described here. Regardless, #6593 has the latest patch to try. You'll need the latest from the 2.6 branch to use it though.

I' m now using stupid way to fixed it. that is create one Chinese tag with English slug and when I edit post, use "slug" to add tag...it's would works ok for me temporarily.

hope and waiting for really fixed file...

may I ask is there possible way to make that when I edit a post ,and the tag select view as slug. show slug now show tag?

comment:21 in reply to: ↑ 19   rocavence4 years ago

Replying to rocavence:

Replying to ryan:

I know #6867 doesn't fix this ticket. It probably will fix the problem mtekk described in comments 12 and 13, which is a separate issue that compounds the problem described here. Regardless, #6593 has the latest patch to try. You'll need the latest from the 2.6 branch to use it though.

I' m now using stupid way to fixed it. that is create one Chinese tag with English slug and when I edit post, use "slug" to add tag...it's would works ok for me temporarily.

hope and waiting for really fixed file...

Newly test... I using this stupid way and close AutoSave, It still duplicate =.=

  • Priority changed from normal to high

When this bug fixed? No patch, update wordpress! Thanks!

  • Priority changed from high to highest omg bbq
  • Status changed from closed to reopened
  • Resolution duplicate deleted

WordPress help us, please!

  • Priority changed from highest omg bbq to normal
  • Status changed from reopened to closed
  • Resolution set to duplicate

This should have been fixed in [8364]. If it wasn't, post on #6867 with reproducible test cases. Re-closing this as a duplicate.

It really wasn't a duplicate, but it seems to be fixed in [8524]. I assume that both of my patches were worked around, though my wp-admin-includes-taxonomy.diff one may still be applied in my build.

(In [8602]) Fix tag duplication when saving posts with multiple tags that have custom slugs. Props mtekk and count_0. fixes #6593 see #6313

(In [8603]) Fix tag duplication when saving posts with multiple tags that have custom slugs. Props mtekk and count_0. fixes #6593 see #6313

Note: See TracTickets for help on using tickets.