Ticket #6593 (closed defect: fixed)

Opened 5 months ago

Last modified 3 weeks ago

Tags with custom slugs get recreated on post edit screen

Reported by: jhodgdon Assigned to: ryan
Priority: normal Milestone: 2.6.1
Component: Administration Version: 2.5
Severity: normal Keywords: tags, has-patch
Cc: jhodgdon, count_0

Description

Here is how to reproduce this bug (the short summary might not be clear about what I am talking about). This applies to 2.5 released version. It was working in earlier 2.5 bleeding, early on, but then got broken by the time of the release, not sure exactly when.

a) Go to the Manage Tags screen, and create a new tag with name "abcdef" and slug "ghi" (without the quotes in all cases). Note that the slug does not match the "sanitized" slug WordPress would create by default.

b) Go to the Write Post screen (edit an existing or create a new post, enter a title and something in the body just to have something to work with).

c) In the Tags section of the Write Post screen, start typing "abc" in the Add Tag box. When "abcdef" appears, click on it, and then click "Add". You'll see it below.

d) Save the post.

e) Return to the Manage Tags screen. You will see that there are now two "abcdef" tags, and the new one has slug "abcdef". The new one is the one that is attached to the post.

The reason for this happening is that when you save the post, WP is taking the tag *names* (which it has carefully saved in a hidden field "tags_input" on the edit screen), and then using is_term to see if they already exist in the DB. is_term just sanitizes the tag name and searches for it as a slug. It doesn't match, so WP creates a brand-new tag.

The reason this is important is that (a) some people override slugs (e.g. non-Euro language users) and (b) if you pick an existing tag from a drop-down list, you should certainly get the tag you picked, not create a new one!!!

The solutions I can imagine:

1) Save the tag slugs rather than tag names in the hidden field, so they will match. This would probably also mean that tag slugs rather than tag names would appear on the post edit screen in the "tags to delete" area, since these delete links and display names are generated from that field.

2) Use something other than is_tag to do the matching.

Any thoughts on which solution to pursue? (1) is probably easier, but (2) might be nicer on the display.

Attachments

match_tag_names.diff (2.5 kB) - added by jhodgdon on 04/04/08 22:33:01.
Patch to allow matching of tag names when saving post
is_term.diff (2.4 kB) - added by ryan on 07/18/08 05:04:17.
is_term.2.diff (2.9 kB) - added by ryan on 07/18/08 23:29:37.

Change History

04/04/08 22:33:01 changed by jhodgdon

  • attachment match_tag_names.diff added.

Patch to allow matching of tag names when saving post

04/04/08 22:34:13 changed by jhodgdon

Here's a patch that lets is_tag match on tag names as well as tag slugs (but leaves previous behavior unchanged for back compatibility). It fixes this problem, and I don't think it should introduce any other problems...

04/08/08 00:42:49 changed by jhodgdon

  • keywords changed from tags to tags, has-patch.

04/08/08 01:24:33 changed by ryan

This might be behavior we want to do by default, without a flag. Either way, I think we will need to add an index on the name to make the query reasonably fast.

07/03/08 14:45:12 changed by jhodgdon

Any chance of getting this into 2.6? Can I do anything to help? There is a patch here...

07/15/08 16:24:07 changed by ryan

  • milestone changed from 2.5.2 to 2.9.

Milestone 2.5.2 deleted

07/18/08 05:04:17 changed by ryan

  • attachment is_term.diff added.

07/18/08 05:06:40 changed by ryan

Patch adds an index to term.name and does a query on the name of the slug query does not match anything. I decided to do two queries instead of lumping it into so that the typical case of where the slug matches doesn't get slowed down. "slug" has a UNIQUE index meaning the SELECT does a very fast const join type. SELECTing on slug OR name results in a slower index_merge. Since we expect to be matching on the slug in most cases, lets keep that as fast a possible.

07/18/08 05:08:55 changed by ryan

  • milestone changed from 2.9 to 2.7.

See also #6313

07/18/08 20:07:23 changed by ryan

  • owner changed from anonymous to ryan.

07/18/08 22:56:18 changed by jhodgdon

I just tested in 2.7-bleeding [8372].

First, I verified that the bug as described originally still exists (it does).

Then I applied Ryan's patch (is_term.diff from above) (it required me to update my database).

As I had created two tags I no longer wanted during the first test, the first thing after updating was to go to the Manage Tags screen to delete the dummy tags and start over. But I couldn't successfully delete tags there -- I checked some tags and clicked the Delete button, and although the message on the screen said they were deleted, they weren't deleted.

I reverted the patch (it again required me to update my database). Now I can delete tags.

So, I think there is something wrong with the patch... I don't know exactly what, but I wouldn't advise adding this patch to WordPress yet.

07/18/08 23:29:37 changed by ryan

  • attachment is_term.2.diff added.

07/18/08 23:30:16 changed by ryan

The ID case was not being handled. is_term.2.diff fixes deletes for me.

07/24/08 19:28:40 changed by ryan

  • status changed from new to closed.
  • resolution set to fixed.

(In [8433]) Check both slug and name when determining if is_term(). fixes #6593 for trunk

08/05/08 21:07:59 changed by ryan

(In [8555]) Use get_term_by() instead of is_term() to query slug. see #6593

08/05/08 22:05:49 changed by ryan

  • milestone changed from 2.7 to 2.6.1.

08/05/08 22:05:54 changed by ryan

(In [8559]) Check both slug and name when determining if is_term(). fixes #6593 for 2.6

08/05/08 22:31:52 changed by jhodgdon

I just tested this in the 2.6 branch [8559], and it looks fine. Thanks for making this part of 2.6.1! Much appreciated.

08/09/08 06:25:07 changed by count_0

  • status changed from closed to reopened.
  • resolution deleted.

I tested 2.6 branch.I use japanese tag and english slug.That is fine only one tagging for the article.

If some tagging for the article,first tag is fine.but other tags recreated slug.[6313] solve a this problem.Please include [6313] in 2.6.1.

08/09/08 06:47:40 changed by ryan

The fix here is a more correct version of the fix on #6313. I cannot reproduce the problem you describe. Can you give us some example tag names and describe the steps you take to make the problem happen?

08/09/08 07:56:01 changed by count_0

  • cc changed from jhodgdon to jhodgdon, count_0.

I mistake WikiFormatting.I want to include this patch.

Steps

  1. Make a new tag at manage -> Tags with tag name "フー", tag slug "foo", "バー", tag slug "bar".
  2. Write a post, add a tag "フー" and "バー" hit the save button.
  3. Back to tag manage -> Tags no recreated(no problem).
  4. Go post manage and reedit post that tagged "フー" and "バー". -> Don't touch tags.Edit and Save post.
  5. Back to tag manage -> "フー" tag not recreated."バー" tag recreated.

08/09/08 12:22:37 changed by count_0

Other case:

  1. Make a new tag at manage -> Tag name "San Andreas", slug "sa" and Tag name "Vice City", slug "vc"
  2. Write a post, add tags "San Andreas" and "Vice City" -> Save post.
  3. Back to tag manage -> "Vice City" recreated.New "Vice City" slug is "vice-city".

First tag is not recreated.but second or more tags are recreated. This problem happen wordpress 2.6 branch.

I apply Ticket #6313: wp-admin-includes-taxonomy.diff.

Test:

  1. Delete recreated Tag on tag manage(Tag name "Vice City", slug is "vice-city")
  2. Edit post tagged "San Andreas" -> Tagging "Vice City" again.
  3. Back to tag manage."Vice City" is not recreated.

08/09/08 17:13:28 changed by ryan

  • status changed from reopened to closed.
  • resolution set to fixed.

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

08/09/08 17:13:41 changed by ryan

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

08/09/08 17:14:47 changed by ryan

Oops, I overlooked that. Thanks for pointing this out and providing the steps to reproduce.

08/11/08 14:21:18 changed by lilyfan

  • status changed from closed to reopened.
  • resolution deleted.

In 2.6.1 beta1, the issue is fixed when creating a new post. But, not fixed at editing the existing posts.

Example: 1. Creat a tag "プラグイン" with a custom slug "plugin". ("プラグイン" means "plugin" in Japanese) 2. Write a new post with tag "プラグイン". The post has the tag with slug "plugin". This is desired behavior. 3. Edit the post. The tag of it will change to a new one with slug "プラグイン". Tag is duplicated: The same name "プラグイン", one has slug of "plugin" and the other has slug of "プラグイン".

08/11/08 15:33:51 changed by ryan

[8602] should fix. The next beta will include [8602].

08/13/08 21:20:25 changed by jhodgdon

Looks good, from a multilingual perspective, in 2.6.2 [8640]

08/13/08 21:21:05 changed by jhodgdon

Sorry, that was the 2.6.1 branch, changeset [8640], not 2.6.2 -- my finger slipped.

08/13/08 21:22:15 changed by jhodgdon

  • status changed from reopened to closed.
  • resolution set to fixed.