[wp-trac] [WordPress Trac] #47029: Custom Taxonomies, with no post_type association and custom submenu location, UX experience is broken when on Taxonomy management page

WordPress Trac noreply at wordpress.org
Wed Apr 24 14:52:15 UTC 2019


#47029: Custom Taxonomies, with no post_type association and custom submenu
location, UX experience is broken when on Taxonomy management page
--------------------------+-----------------------------
 Reporter:  son9ne        |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Taxonomy      |    Version:  5.1.1
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 When creating a custom taxonomy with no `post_type` association, then
 adding a `add_submenu_page` option for it under any specific menu, the
 link will show in the proper location. The problem is when you view the
 taxonomy management page, the UX is not as expected.

 One would expect the main menu location to be open and the submenu to be
 bolded (normal nav UX).

 e.g.
  - Posts
  - Custom Main Menu Item
   - Add New
   - **Custom Taxonomy**

 What actually happens is that the Posts main menu is open and nothing is
 highlighted.

 e.g.
  - Posts
   - All Posts
   - Add New
   - Categories
  - Custom Main Menu Item

 When you do go to the main menu location that the taxonomy is assigned to,
 you do see what is expected. Meaning, the submenu option is bolded, the
 main menu just is closed and not opened. Only the Posts main menu item is
 open.


 The issue appears to be that when there is no post_type association, the
 Posts main menu is always the open main menu item.

 I provided an example below.

 This example adds a new taxonomy to the plugin:
 [https://wordpress.org/plugins/query-wrangler/]
 (This was a quick way to duplicate the issue but to be honest, I have this
 exact issue on every custom taxonomy with no `post_type` association. )

 It creates the menus structure:

  - Query Wrangler
   - Add New
   - Import
   - Settings
   - Content Groups

 When I click on the Content Groups taxonomy, I am taken to the taxonomy
 management page as expected. The issue is the admin nav now shows:

  - Posts
   - All Posts
   - Add New
   - Categories
  - Custom Main Menu Item

 Instead of:

  - Query Wrangler
   - Add New
   - Import
   - Settings
   - **Content Groups**


 {{{
 <?php

 /**
  * Class Content_Groups
  * Allows building content groups by associating Query Wrangler and Custom
 queries
  */
 class Content_Groups {

     /**
      * Taxonomy identifier
      */
     const TAX_NAME = 'content-groups';

     /**
      * Query Wrangler page slug
      */
     const MENU_SLUG = 'query-wrangler';


     public function __construct() {
         \add_action('init', array($this, 'register'));
         \add_action('admin_menu', [$this, 'add_sub_menu'], 99999); // Must
 be lower than Query Wrangler's value: 9999
     }

     /**
      * Registers Taxonomy
      * @link
 https://codex.wordpress.org/Function_Reference/register_taxonomy
      * @link https://core.trac.wordpress.org/ticket/28033
      */
     public function register() {
         $capability_type = str_replace('-', '_', self::TAX_NAME);
         $args           = array(
             'hierarchical' => false,
             'labels'       => [
                 'name'                       => _x('Content Groups',
 'taxonomy general name', 'text-domain'),
                 'singular_name'              => _x('Content Group',
 'taxonomy singular name', 'text-domain'),
                 'menu_name'                  => _x('Content Groups',
 'menu_name', 'text-domain'),
                 'all_items'                  => _x('All Content Groups',
 'all_items', 'text-domain'),
                 'edit_item'                  => _x('Edit Content Group',
 'edit_item', 'text-domain'),
                 'view_item'                  => _x('View Content Group',
 'view_item', 'text-domain'),
                 'update_item'                => _x('Update Content Group',
 'update_item', 'text-domain'),
                 'add_new_item'               => _x('Add New Content
 Group', 'add_new_item', 'text-domain'),
                 'new_item_name'              => _x('New Content Group
 Name', 'new_item_name', 'text-domain'),
                 'parent_item'                => _x('Parent Content Group',
 'new_item_name', 'text-domain'),
                 'parent_item_colon'          => _x('Parent Content
 Group:', 'parent_item_colon', 'text-domain'),
                 'search_items'               => _x('Search Content
 Groups', 'search_items', 'text-domain'),
                 'popular_items'              => _x('Popular Content
 Groups', 'popular_items', 'text-domain'),
                 'separate_items_with_commas' => _x('Separate content
 groups with commas', 'separate_items_with_commas', 'text-domain'),
                 'add_or_remove_items'        => _x('Add or Remove Content
 Groups', 'add_or_remove_items', 'text-domain'),
                 'choose_from_most_used'      => _x('Choose from the most
 used content groups', 'choose_from_most_used', 'text-domain'),
                 'not_found'                  => _x('No content groups
 found', 'not_found', 'text-domain'),
             ],
             'capabilities' => [
                 'manage_terms' => "manage_{$capability_type}",
                 'edit_terms'   => "edit_{$capability_type}",
                 'delete_terms' => "delete_{$capability_type}",
                 'assign_terms' => "assign_{$capability_type}",
             ],
             'show_ui'      => true,
             'show_menu_ui' => true,
             'query_var'    => true
         );

         // Register the taxonomy
         \register_taxonomy(self::TAX_NAME, NULL, $args);
     }

     /**
      * Builds the menu
      */
     public function add_sub_menu() {
         $capability_type = str_replace('-', '_', self::TAX_NAME);
         \add_submenu_page(
             self::MENU_SLUG,
             _x('Content Groups', 'menu_name', 'text-domain'),
             _x('Content Groups', 'menu_name', 'text-domain'),
             "manage_{$capability_type}",
             'edit-tags.php?taxonomy=' . self::TAX_NAME
         );
     }

 }
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/47029>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list