Make WordPress Core

Opened 11 years ago

Closed 10 years ago

#11838 closed task (blessed) (fixed)

Add hierarchical taxonomies to the Menu bar

Reported by: dd32 Owned by: dd32
Milestone: 3.0 Priority: normal
Severity: normal Version: 3.0
Component: Taxonomy Keywords: has-patch
Focuses: Cc:


Along side the current Custom post types, I think we should expose custom hierarchical taxonomies as well finally.

I'll write a basic patch which exposes it, but some basic functionality may not work.

Attachments (8)

11838.diff (14.0 KB) - added by dd32 11 years ago.
11838.2.patch (14.1 KB) - added by dd32 11 years ago.
11838.3.diff (21.4 KB) - added by dd32 11 years ago.
my#11838.patch (4.6 KB) - added by arena 11 years ago.
code shorter than long speeches
my#11838.2.patch (4.4 KB) - added by arena 11 years ago.
my#11838.3.patch (4.3 KB) - added by arena 11 years ago.
last code optimization
11838.crazy.translations.diff (12.8 KB) - added by dd32 11 years ago.
11838.2.diff (3.0 KB) - added by jfarthing84 10 years ago.
Changes needed to make wp_list_categories() custom taxonomy aware.

Download all attachments as: .zip

Change History (49)

11 years ago

#1 @dd32
11 years ago

  • Keywords has-patch added; needs-patch removed

attachment 11838.diff added

  • Exposes the hierarchical taxonomies menu items
  • Adds the ability to Add a custom item via non-js methods
  • Works with custom post types. See #9674

A lot of hacking at the category functions there.. I think it might be better to just create a new generic functionset which does it.

A few things are needed in addition to this..

  • Singular vs plural forms of names, "Thing" and "Things" for example, "Taxonomy" "Taxonomies"
  • JS modifications to handle the taxonomies.. I think its hidden amongst the wp-lists functionality (Something i got lost in last time IIRC)

See also #10122 for adding the metaboxes to the edit pages.

This is designed as a first-scrape draft.

#2 @sirzooro
11 years ago

  • Cc sirzooro added

#3 @ryan
11 years ago

Looks good in general, although it causes come breakage in categories.php. All subcats are listed first, with top-level cats following.

#4 @dd32
11 years ago

Ah.. probably missed a heirachial call somewhere.. I'll take a look

#5 @dd32
11 years ago

Turns out, That was the removal of the Output buffering.

Removal of the output buffer means that the function now returns instead of echo'ing, As cat_rows() should be called instead of _cat_rows() it should be safe to change that... see next patch

11 years ago

#6 @dd32
11 years ago

Things to note:

  • No Ajax still
  • String like the following are.. how to handle them?
    <p><?php printf(__('<strong>Note:</strong><br />Deleting a %1$s does not delete the objects in that %1$s. Instead, objects that were only assigned to the deleted %1$s are set to the %1$s <strong>%2$s</strong>.'), $tax->label, apply_filters('the_category', get_cat_name(get_option('default_' . $taxonomy)))) ?></p> 
  • Need Singular / Plural forms for all tax pages (This goes for posts too)
  • "Category" needs to be removed and replaced with Taxonomy name

#7 @dd32
11 years ago

  • Default Category
    • Deprecate the usage of it? See #11576
    • Perhaps we should offer to set a default term ID on registration? or just allow for and option of default_<taxonomy> as i've done there?

#8 @ryan
11 years ago

(In [12694]) Show custom hierarchical taxonomies in the menus. Props dd32. see #11838

#9 @dd32
11 years ago

Just looking at this closely, I've got some huge worries about continuing to modify the category functions to pass a taxonomy.

I'm coming to the thought, of that perhaps, it'll be better to delete the categories.php file, and merge into a generic taxonomy terms page, specifically, tags.php for a start.

A lot of the category functionality is wraped in functions which wrap the taxonomy API, which makes it hard, as you're then only returning either "category"-specific errors, or preventing deleting the default term.

My suggestion is to move the default-deletion from the wrappers, into a hook of wp_delete_term, and merge the hierachial functionalities from categories.php into tags.php, or perhaps, into a new file terms.php as to stay reasonably filename-neutral.

Any feedback on that thought line?

Eg. Look at the category related functions in http://core.trac.wordpress.org/browser/trunk/wp-admin/includes/taxonomy.php combine that with get_category() and the compat code for categories.. I'd rather just deprecate the functions there and move to the taxonomy API directly or create a new set of neutral wrappers

#10 @ShaneF
11 years ago

  • Cc ShaneF added

+1 to this idea. Smaller is better and less files to find problems. This way we don't have to also double up code as well.

11 years ago

#11 @dd32
11 years ago

(In [12818]) Merge Categories/Hierarchical taxonomies into edit-tags.php. See #11838

I've left all the category related files and ajax handlers in for now, Will clean them up afterwards assuming no issues.

A few changes were made in the merge, notably, the handling of searching and paging.

During searches, the hierarchy cannot be displayed 'correctly', child nodes will appear as childs of the incorrect term, and root nodes may duplicate as childs themselves.. Thats why i've disabled the hirachial display of them for now. - Related #11575

Paging: The final page may display more than per_page, due to the parent nodes being included in the listing. Its impossible to split these into extra pages due to the paging being determined before the category listing is created.

Strings: the entire taxonomy editing section needs new strings, to either make them generic (non tag/category) or to support them being specified. I'm thinking that 'edit_label', 'label_plural', 'new_label', etc may be needed upon taxonomy registration (Else, fall back to a generic string).

#12 @dd32
11 years ago

  • Owner changed from filosofo to dd32
  • Status changed from new to accepted
  • Type changed from defect (bug) to enhancement

#13 @arena
11 years ago

From #11575


read ticket #11838

hard to show you screenshots on nightly build wordpress because categories admin page displays a left column with tags and a right column with categories. Waiting for the admin page to be more stable.

However i noticed the search form does not works properly as hierarchy is not respected !

11 years ago

code shorter than long speeches

11 years ago

11 years ago

last code optimization

#14 @dd32
11 years ago

See Also: #12035 for addition of caps related to taxonomies.

#15 @dd32
11 years ago

Need thoughts from translators/UI people for how to name things here i think.

At present there are a lot of strings in this interface which relate to Tags specifically, or Categories in the sense of the Parent interface.

I'm not sure if we could get away with a Singular_label and multiple_label fields and insert them into generic strings ("Add <singular_label>"), or if we'll be better allowing register_taxonomy() to be passed a list of strings.. That has the downside that it'll not be translated for some languages.

A possibility is to go for a in-between, Allow plugins to specify the exact strings to be displayed, if not, fall back to a generic string which inserts the tax name. But that still goes back to the 90% of plugins which use it probably wont have the same translation count as WordPress does itself.

The strings which i'm thinking of would be Add a New Tag, Add Tag, Edit Tag, Popular Tags, Search Tags

#16 @dd32
11 years ago

(In [12835]) Display correct Taxonomy heading. See #11838

#17 @dd32
11 years ago

(In [12941]) Migrate Category Edit UI hooks, Standardise on custom-taxonomies hooks, add custom-fields for taxonomies UI hooks. See #11838, Fixes #11191

#18 @dd32
11 years ago

(In [12942]) Remove redundant Category forms/code/ajax. See #11838

As with the Pages php files, We can restore categories.php as a stub if need be later.

#19 @dd32
11 years ago

attachment 11838.crazy.translations.diff added

Thats my first attempt at giving the strings in the file a neutral tone, or one which works with multiple taxonomies.

I'm not 100% sure if having a Singular/plural form and statically inserting that into those strings is going to be a workable solution for translations, Can any translators comment on that?

This also has a let-down with the "Post Tags" label, which is only used in the Menu and the Meta box title. Everything else refers to it as "Tags" in paragraphs. With the addition of register_taxonomy_for_post_type() it doesnt always mean it'll apply to only posts either - My vote would be to change it to simply "Tags" and "Tag"..

#20 @dd32
11 years ago

(In [13008]) Remove cat_rows() admin template functions. See #11838

#21 @dd32
11 years ago

Few things noticed:

  • Not all of the sanitization of the terms was brought accross from categoeies
    • As a result, Multiple categories with the same Name are allowed (they differ with slugs however).
      • Everything appears working.
      • See #8167
  • Quick edit doesnt handle Parents currently
    • Never did.
    • Probably best disabling that as while the parent can be updated, the row will not appear in the right location
  • Quick edit throws a E_NOTICE when changing the slug to something that already exists
  • You can create a Term in multiple Taxonomies
    • Eg, "Test Category Tag" as a Category, If you then add it as a Tag, It'll recieve the same term_id (ie. it picks up the underlying term instead of creating a new one with a new slug)

#22 @dd32
11 years ago

(In [13009]) Remove hierarchical taxonomy parent support from Quick Edit (field added in error). See #11838

#23 @dd32
11 years ago

(In [13010]) $term is an array not object, Fixes Notice on duplicate term checking. See #11838

#24 @dd32
10 years ago

(In [13077]) Introduce Custom Taxonomies Translation strings, Correctly identifies the taxonomy in the Strings of the edit pages. See #11838

#25 @dd32
10 years ago

(In [13081]) Fix Terms Per Page for taxonomies, Apply old Category filter to value. See #11838

#26 @automattor
10 years ago

(In [13083]) Introduce Custom Taxonomies Translation strings, Correctly identifies the taxonomy in the Strings of the edit pages. See #11838

#27 @automattor
10 years ago

(In [13086]) Convert Terms page to use WP_Ajax_Response(), hierarchical terms will now appear under their parent OR have the parents prefixed, Terms will be removed from tag cloud/parent list upon deletion, Terms will be added to Parent list in correct order upon ajax creation, Errors on term creation flow back to UI, clean up _tag_row() alternate class handling, Show None text in Category dropdown if empty and show_if_empty = true. See #11838

#28 @automattor
10 years ago

(In [13087]) Prevent Terms from being created in multiple taxonomies. If a slug is provided by the user, error out if it exists, else make the auto slug unique. See #11838

#29 @dd32
10 years ago

(In [13088]) Flow on tax-modification errors on Tax inline edit to the UI. See #11838

#30 @dd32
10 years ago

(In [13092]) Bump tags JS version. See #11838

#31 @aaroncampbell
10 years ago

In [13077] I think it should read "An item ..." rather than "A item ..." on line 14 of trunk/wp-admin/edit-tag-form.php

#32 @dd32
10 years ago

I think it should read "An item ..." rather than "A item ..."

Probably, Thanks for noticing :)

#33 @nacin
10 years ago

(In [13160]) Only show "Popular Terms" header when there is a tag cloud to show. see #11838

#34 @dd32
10 years ago

(In [13162]) Grammar fix, s/A item/An item/. Props aaroncampbell. See #11838

#35 @dd32
10 years ago

(In [13213]) Fix $post_type handling/passing in the Taxonomy edit links. Fix the Tag selection query var for edit.php in the Posts links. See #12270, See #11838

#36 @nacin
10 years ago

  • Type changed from enhancement to task (blessed)

#37 @nacin
10 years ago

(In [13538]) Add some custom taxonomy flags to allow fully customize strings in the taxonomy meta box. see #11838

#38 @jfarthing84
10 years ago

  • Cc jeff@… added

A couple of functions need to be adapted, or new functions added to cater to our hierarchical (and non-hierarchical) taxonomies, namely wp_list_categories() and its corresponding Walker_Category class. If you use either of these, you'll notice that they only generate links for categories (e.g. ?cat=12).

We need to alter wp_list_categories() to accept a 'taxonomy' argument (just as wp_dropdown_categories() has been adapted). Also, the Walker_Category class needs to use get_term_link() instead of get_category_link() for any term that is not a category.

10 years ago

Changes needed to make wp_list_categories() custom taxonomy aware.

#39 @dd32
10 years ago

Those changes mostly look sane.

The only one i can see, is that get_term_link() should be able to be used instead of get_category_link(). no need for the if there.

#40 @dd32
10 years ago

(In [13854]) Update wp_list_categories() to be custom taxonomy aware. Props jfarthing84. See #11838

#41 @nacin
10 years ago

  • Resolution set to fixed
  • Status changed from accepted to closed

I think this one is good.

Note: See TracTickets for help on using tickets.