WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#6313 closed defect (bug) (duplicate)

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

Reported by: tai Owned by: mtekk
Milestone: Priority: normal
Severity: normal Version: 2.6
Component: General Keywords: has-patch
Focuses: 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 (2)

wp-admin-includes-taxonomy.diff (468 bytes) - added by mtekk 6 years ago.
This patch fixes the issue where when you save twice you get double tags
wp-includes-taxonomy.diff (652 bytes) - added by mtekk 6 years ago.
This fixes lilyfan's code to follow WP code conventions

Download all attachments as: .zip

Change History (29)

comment:1 lloydbudd6 years ago

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

comment:2 lilyfan6 years ago

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

comment:3 mtekk6 years ago

Closed #6545 as a duplicate of this bug

comment:4 mtekk6 years ago

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

mtekk6 years ago

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

comment:5 mtekk6 years ago

  • 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: jyoshida6 years ago

if ( $taxonomy = 'post_tag' ) {

Isn't this wrong?

if ( $taxonomy == 'post_tag' ) {

comment:7 mtekk6 years ago

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

comment:8 in reply to: ↑ 6 Nazgul6 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 =.

mtekk6 years ago

This fixes lilyfan's code to follow WP code conventions

comment:9 mtekk6 years ago

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.

comment:10 free86 years ago

  • Version changed from 2.5 to 2.6

WordPress 2.6 can not use this patch

comment:11 mtekk6 years ago

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

comment:12 mtekk6 years ago

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

comment:13 rocavence6 years ago

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!

comment:14 mtekk6 years ago

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: ryan6 years ago

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

comment:16 ryan6 years ago

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

#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 rocavence6 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: ryan6 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: rocavence6 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...

comment:20 rocavence6 years ago

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 rocavence6 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 =.=

comment:22 free86 years ago

  • Priority changed from normal to high

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

comment:23 free86 years ago

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

WordPress help us, please!

comment:24 ionfish6 years ago

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

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

comment:25 mtekk6 years ago

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.

comment:26 ryan6 years ago

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

comment:27 ryan6 years ago

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