WordPress.org

Make WordPress Core

Opened 22 months ago

Last modified 14 months ago

#43060 new enhancement

register taxonomy should accept a label to affect the description under each field on the Add Tag form

Reported by: mclaurent Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Taxonomy Keywords: good-first-bug has-patch
Focuses: administration Cc:
PR Number:

Description

Hi

When registering a custom taxonomy WordPress uses the default UI to allow content editors to manage terms in this taxonomy. The descriptions under the Tag name and Slug may in some cases not be adequate and/or require additionnal guidance. For instance when the names of tags should follow a certain convention or standard.
For instance for a Countries taxonomy we would wish to give the user information on what standard to follow (for instance ISO-3166-2).

I have attached images of what it currently looks like on the Add Tag page, and what it should look like in my opinion.

Since there are no hooks allowing to add extra information under the tag-name field on the edit-tags.php:393, I think the best place for this change would be at the time of register_taxonomy. I would suggest introducing new labels for a taxonomy which would overwrite the labels displayed under each field.

The implementation would then look something like this:

<?php
register_taxonomy( 'countries', 'post',array(
        'label' => __( 'Countries' ),
        'labels' => array(
                'name' => __( 'Countries' ),
                'singular_name' => __( 'Countries' ),
                'menu_name' => __( 'Countries' ),
                'all_items' => __( 'All Countries' ),
                'edit_item' => __( 'Edit Country' ),
                'view_item' => __( 'View Country' ),
                'update_item' => __( 'Update Country' ),
                'add_new_item' => __( 'Add New Country' ),
                'new_item_name' => __( 'New Country name' ),
                // The below would be used on the edit-tags.php:393
                'new_item_name_description' => __( 'This name should adhere to the ISO-3166-2 standard.' ),
                'parent_item' => __( 'Parent Country' ),
                'parent_item_colon' => __( 'Parent Country:' ),
                'search_items' => __( 'Search Countries' ),
                'popular_items' => __( 'Popular Countries' ),
                'separate_items_with_commas' => __( 'Separate Countries with commas' ),
                'add_or_remove_items' => __( 'Add or remove Countries' ),
                'choose_from_most_used' => __( 'Choose from the most used Countries' ),
                'not_found' => __( 'No Countries found' ),
        ),
        'public' => true,
));

Attachments (4)

country-taxonomy-currently.PNG (15.9 KB) - added by mclaurent 22 months ago.
The admin screen without custom term naming guidance
country-taxonomy-shouldbe.PNG (20.1 KB) - added by mclaurent 22 months ago.
The admin screen with custom term naming guidance giving specific information (and even links to relevant resources)
43060.diff (7.7 KB) - added by dontgo2sleep 14 months ago.
43060_proper.patch (7.0 KB) - added by dontgo2sleep 14 months ago.

Download all attachments as: .zip

Change History (12)

@mclaurent
22 months ago

The admin screen without custom term naming guidance

@mclaurent
22 months ago

The admin screen with custom term naming guidance giving specific information (and even links to relevant resources)

#1 follow-up: @swissspidy
22 months ago

  • Type changed from defect (bug) to enhancement

I don't see why a new label is needed for that. This can be a regular do_action() call in the edit tag form.

#2 in reply to: ↑ 1 @mclaurent
22 months ago

Replying to swissspidy:

I don't see why a new label is needed for that. This can be a regular do_action() call in the edit tag form.

Yeap that would work aswell. I thought it'd be cleaner to do it in the register_taxonomy as that is where the other labels are defined, too.

Last edited 22 months ago by mclaurent (previous) (diff)

#3 @johnbillion
22 months ago

  • Keywords needs-patch added
  • Version 4.9.1 deleted

I think it makes sense for these to be taxonomy labels.

#4 follow-up: @jeremyescott
22 months ago

Something that seems weird to me about the original example is that the 'new_item_name_description' doesn't replace but appends the default description. The suggestion seems to imagine a behavior more like a filter would than an action or a label.

Which begs the question, should plugin editors have the ability to remove the "the name how it appears on your site" message? I'd say, "yes".

That said, I'm not so sure this should be in the array. If we added this, why wouldn't we do the same for the other tags fields? So 'new_item_name_description', 'new_item_slug_description', and 'new_item_description_description'? And there we find the awkwardness of taking this one step forward... 'description_description'. :D

I think a filter would be most appropriate. My head isn't in the mode to think up a name, but a filter that is dynamic to the post type key, e.g.: taxonomy_$keyname_name_field_description, and taxonomy_$keyname_description_field_description, etc.

#5 in reply to: ↑ 4 @theMikeD
22 months ago

I'd also like these to be part of the taxonomy declaration. And...

Replying to jeremyescott:

That said, I'm not so sure this should be in the array. If we added this, why wouldn't we do the same for the other tags fields? So 'new_item_name_description', 'new_item_slug_description', and 'new_item_description_description'? And there we find the awkwardness of taking this one step forward... 'description_description'. :D

I think a filter would be most appropriate. My head isn't in the mode to think up a name, but a filter that is dynamic to the post type key, e.g.: taxonomy_$keyname_name_field_description, and taxonomy_$keyname_description_field_description, etc.

...adding "_field" in there just to avoid "_description_description" is superfluous IMO.

#6 @jeremyfelt
15 months ago

  • Keywords good-first-bug added

I think it makes sense to add these as part of taxonomy registration to encourage adapting the text for specific needs.

The possibility of new_item_description_description is a little strange, but we've probably seen stranger. :)

Adding good-first-bug to this as I think an initial patch will be relatively straight forward.

#7 @dontgo2sleep
15 months ago

I am on it!

@dontgo2sleep
14 months ago

#8 @dontgo2sleep
14 months ago

  • Keywords has-patch added; needs-patch removed
Note: See TracTickets for help on using tickets.