WordPress.org

Make WordPress Core

Opened 9 years ago

Last modified 9 months ago

#14691 new enhancement

Allow commas in tag names

Reported by: mdawaffe Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 3.0.1
Component: Taxonomy Keywords: needs-refresh
Focuses: Cc:

Description

Adding tags to posts via the web interface involves a lot of what boils down to

explode( ',', join( ',', array( $tag_name, ... ) ) );

both in PHP and JS.

We settled on commas so we could have tags with spaces in them (see #10320, for example).

It'd be nice if tags (and other taxonomies) could have commas in them, though. Example use case: normalized locations ("Portland, OR"). Admittedly, commas in tag names is an edge case.

The attached treats tag inputs as "real" CSV strings instead of just exploding by commas.

That way, you can enter:

hello, "hello, world"

in the tags input field and the following tags would be added to the post.

  • hello
  • hello, world

This addresses commas in tag names but makes entering double quotes in tag names more annoying. If you wanted a tag named double"quote, you'd have to enter the following.

"double""quote"

This may also help with #7897.

Attachments (4)

14691.diff (14.5 KB) - added by mdawaffe 9 years ago.
tags-with-commas.diff (8.2 KB) - added by joehoyle 6 years ago.
tags-with-commas.2.diff (9.1 KB) - added by joehoyle 6 years ago.
tags-with-commas.3.diff (11.4 KB) - added by joehoyle 6 years ago.
Actually added tags

Download all attachments as: .zip

Change History (29)

@mdawaffe
9 years ago

#1 follow-up: @mdawaffe
9 years ago

The patch makes use of a slightly modified version of http://www.bennadel.com/blog/1504-Ask-Ben-Parsing-CSV-Strings-With-Javascript-Exec-Regular-Expression-Command.htm

I've emailed the author asking him under what license the code was released.

#2 @scribu
9 years ago

Pretty neat solution.

#4 @Denis-de-Bernardy
9 years ago

  • Keywords needs-unit-tests added

#5 in reply to: ↑ 3 @mdawaffe
9 years ago

Replying to Denis-de-Bernardy:

http://bugs.php.net/bug.php?id=50686

I'm not too worried if fgetcsv/fputcsv don't quite meet the spec as long as they're each other's inverses and that the JS code is compatible enough. I don't know if either is the case.

I agree it needs unit testing, thanks for the tag.

#6 in reply to: ↑ 1 @mdawaffe
9 years ago

Replying to mdawaffe:

The patch makes use of a slightly modified version of http://www.bennadel.com/blog/1504-Ask-Ben-Parsing-CSV-Strings-With-Javascript-Exec-Regular-Expression-Command.htm

I've emailed the author asking him under what license the code was released.

Ben Nadel, the author, says the code can be used however WP may like to use it. If WP needs an explicit license, he's happy to give it.

#7 @nacin
8 years ago

  • Milestone changed from Awaiting Review to Future Release

#8 @mau
7 years ago

  • Cc ngomau@… added

#9 @abackstrom
7 years ago

  • Cc abackstrom added

#10 @wonderboymusic
6 years ago

#13606 was marked as a duplicate.

#11 @joehoyle
6 years ago

I am not a fan of this implementation. In my opinion there should be better separation of concerns so the front end is responsible for passing an array of terms to the backend. The current implementation passes the terms as a CSV string (in a textarea) which seems like a total hack - we can pass arrays in POST so let's use that.

This would require changing the tax meta box's javascript to store each term in a separate input with a name like tax_input[post_tag][] rather than parsing a CSV string on the backend.

I am inclined to think including the library is more than necessary, also the patch is so old it doesn't apply as post.js has changed significantly since it was written.

#12 @joehoyle
6 years ago

So, I took a bash at getting this working, which included updating some of the tags JavaScript as it's frankly rather convoluted right now. Rather than having to rely on a storing the current tags in the <textarea> which makes parsing difficult when removing tags etc, it just parses the <textarea> once on page load, and then uses a jQuery data object on the tagsdiv. This means we don't need to do any flushTags or cleaning because the tags are stored in <input type="hidden" /> and also on in the tagsdiv jQuery object.

Here is a quick demo of me using it:

https://f.cloud.github.com/assets/161683/1310981/4f9e5f90-31fc-11e3-83c0-bd95179dfea4.gif

I also had to patch the jQuery Suggest library as it currently doesn't support selecting options that contain the delimiter. I think this is a "bug" with the current library so don't see any issue with the fix I propose.

This is still compatible with JS disabled.

#13 follow-up: @joehoyle
6 years ago

Added some qunit tests and tweak the functionality of removeTag so it removed the hidden <input> field too.

@joehoyle
6 years ago

Actually added tags

#14 @bhwebworks
5 years ago

Any progress being made on this?

#15 @iv.dimova
4 years ago

Is there any chance for some progress on this?

#16 in reply to: ↑ description @jbenes
4 years ago

Just a follow up - has anyone had any chance to tackle this? I'm still running into this problem.

#17 in reply to: ↑ 13 @lisota
4 years ago

Replying to joehoyle:

Added some qunit tests and tweak the functionality of removeTag so it removed the hidden <input> field too.

Any way we can get this ticket moving forward? The bug has been around for 5 years and still exists in 4.3.

It is not unreasonable that someone would want to have a taxonomy name with a comma included. Ours is "Asbestos, Mold & Lead Testers". The taxonomy picker still misbehaves when there is a comma, dividing it improperly.

#18 @boonebgorges
4 years ago

  • Keywords needs-refresh added; has-patch needs-testing needs-unit-tests removed

Basic approach seems OK to me, but the patch needs some love in order to apply to trunk.

#19 @mgwhitfield
2 years ago

This ticket is six years old, lol

#20 @piersb
20 months ago

Seven years, now.

#21 @johnbillion
20 months ago

Long running issues such as this one can be very frustrating, but comments such as this one are not productive.

The last patch for this was written four years ago and needs to be updated. If you want this to move forward, a more productive means would be to find somebody to update the patch and ensure it the proposed functionality still works as expected.

#22 @piersb
20 months ago

I wasn't sure how to express my interest in the patch and thus push it to the top of the queue, other than flagging it with a watch and a comment.

This ticket was mentioned in Slack in #core by piersb. View the logs.


20 months ago

#24 @inlate
19 months ago

A use case of comma in tag are names.

In publications name and family name are separated by comma:
Doe, John
Multiple names are separated by a semicolon or other character.

You can have a look at some publication db:
http://porto.polito.it/view/creators/
https://www.researchgate.net/publication/291754505_InViTo_An_interactive_visualisation_tool_to_support_spatial_decision_processes
(on the top right try download citation, whatever format)

At present it is very difficult to reproduce the same behavior in Wordpress and not particularly effective hacks are suggested as:
https://wordpress.stackexchange.com/questions/25043/how-can-i-allow-commas-in-tag-names

It is my opinion that it is appropriate to have the ability to change the separator, per taxonomy.
Or, even better, the ability to disable the parsing feature, uploading taxonomy one at the time.

Thank you,
Riccardo

Last edited 18 months ago by inlate (previous) (diff)

#25 @boonebgorges
9 months ago

#44525 was marked as a duplicate.

Note: See TracTickets for help on using tickets.