Menu

Taxonomy Management Interface

Relevant source files

The Taxonomy Management Interface provides administrative UI components for linking taxonomy terms (categories, tags, custom taxonomies) across language blogs in a multisite network. This system allows editors to establish translation relationships between terms, similar to how posts are linked but with taxonomy-specific considerations.

This page documents the term linking interface. For post/page linking, see 4.2. For information about how term relationships are stored, see 5.1.

Purpose and Scope

The taxonomy management system consists of two primary components:

  1. Input interfaces on term add/edit screens where administrators link terms across blogs
  2. List table columns that display translation status indicators for terms

The system operates in two modes: autocomplete mode (MslsPostTag) and classic mode (MslsPostTagClassic), controlled by the activate_autocomplete option.

Sources: includes/MslsPostTag.php1-274 includes/MslsPostTagClassic.php1-153

System Architecture

System Components:

ComponentPurposeFile
MslsPostTagAutocomplete-based term linking interfaceincludes/MslsPostTag.php
MslsPostTagClassicDropdown-based term linking interfaceincludes/MslsPostTagClassic.php
MslsCustomColumnTaxonomyTranslation status in list tablesincludes/MslsCustomColumnTaxonomy.php
MslsOptionsTaxTerm relationship storageReferenced in taxonomy classes
MslsAdminIconTaxonomyIcon generation for termsReferenced via factory

Sources: includes/MslsPostTag.php74-87 includes/MslsPostTagClassic.php1-12 includes/MslsCustomColumnTaxonomy.php1-44

Initialization and Mode Selection

The taxonomy management interface initializes by detecting the current taxonomy and selecting the appropriate UI mode:

The factory pattern at includes/MslsPostTag.php74-87 selects between autocomplete and classic modes based on configuration. The taxonomy is detected using msls_content_types()->acl_request(), which returns the current taxonomy slug from the request context.

Sources: includes/MslsPostTag.php74-87 includes/MslsPostTagClassic.php1-12

Term Linking Workflow

The following diagram illustrates the complete user workflow for linking taxonomy terms across blogs:

This workflow demonstrates:

  1. Pre-population: When creating a term from another blog's "create" link, the origin term is pre-linked
  2. Bidirectional saving: Relationships are saved on both the current term and all linked terms
  3. Blog switching: The system switches context to each blog to save relationships

Sources: includes/MslsPostTag.php120-146 includes/MslsPostTag.php218-222 includes/MslsMain.php131-179

Add Term Screen Interface

Autocomplete Mode

In autocomplete mode, the add term screen displays text input fields with AJAX-powered suggestions:

The HTML structure generated includes:

  • A hidden field msls_id_{blog_id} storing the selected term ID
  • A text input msls_title_{blog_id} for autocomplete suggestions
  • Hidden fields identifying the taxonomy and action type

Sources: includes/MslsPostTag.php94-112 includes/MslsPostTag.php159-211

Classic Mode

Classic mode renders dropdown select boxes populated with all available terms:

The print_option() method at includes/MslsPostTagClassic.php116-152 queries all terms in the target blog's taxonomy and generates <option> elements with selected attributes for already-linked terms.

Sources: includes/MslsPostTagClassic.php22-40 includes/MslsPostTagClassic.php84-106 includes/MslsPostTagClassic.php116-152

Edit Term Screen Interface

The edit screen differs from the add screen primarily in HTML structure (table rows vs. form fields) and the availability of existing term data:

Autocomplete Mode

Key differences from add screen:

  • Uses table structure (<tr>, <th>, <td>) instead of <div> wrapper
  • Loads existing term data to populate input values
  • Icon href is set when translation exists

Sources: includes/MslsPostTag.php120-146 includes/MslsPostTag.php159-211

Classic Mode

The classic mode edit screen follows the same pattern but uses <select> elements:

Note the hide_empty: false parameter at includes/MslsPostTagClassic.php131 ensures all terms are available for linking, not just those with posts.

Sources: includes/MslsPostTagClassic.php48-72 includes/MslsPostTagClassic.php116-152

Autocomplete Suggestion System

The autocomplete functionality uses AJAX to fetch term suggestions as the user types:

The suggestion endpoint at includes/MslsPostTag.php23-72 performs these operations:

  1. Blog context switch: Changes to the target blog to query its terms
  2. Term query: Uses get_terms() with configurable arguments
  3. Filtering: Applies msls_post_tag_suggest_args and msls_post_tag_suggest_term filters
  4. JSON encoding: Returns term IDs and names as JSON

Sources: includes/MslsPostTag.php23-72

Data Storage and Retrieval

Save Process

When a term is saved with translation links, the system executes a bidirectional save operation:

The get_input_array() method at includes/MslsMain.php67-90 extracts term IDs from POST data by looking for keys prefixed with msls_input_. The save process ensures relationships are recorded bidirectionally across all linked blogs.

Sources: includes/MslsPostTag.php218-222 includes/MslsMain.php131-179 includes/MslsMain.php67-90

When an administrator clicks a "create" link from a term's list table, the new term form is pre-populated with a link back to the origin term:

This mechanism at includes/MslsPostTag.php231-261 checks for msls_id and msls_lang query parameters, validates the origin term exists, and pre-populates the relationship.

Sources: includes/MslsPostTag.php231-261 includes/MslsMetaBox.php378-407

List Table Integration

The MslsCustomColumnTaxonomy class adds translation status indicators to taxonomy list tables:

Icon States

The icons displayed in the list table column have three states:

StateIconMeaning
No TranslationPlus icon (dashicons-plus)No translation exists; click to create
Translation ExistsEdit icon (dashicons-edit)Translation exists; click to edit
Flag/Label ModeFlag or language badgeVisual indicator only (when icon_type is flag or label)

The icon type is determined by options->get_icon_type() which can be flag, label, or action. When set to action, the icons are interactive and link to either the create or edit screen.

Sources: includes/MslsCustomColumnTaxonomy.php1-44 includes/MslsCustomColumn.php1-110 includes/MslsAdminIcon.php206-220

Filtering and Hooks

The taxonomy management interface provides several filter hooks for customization:

Available Filters

FilterPurposeLocationParameters
msls_post_tag_suggest_argsModify term query arguments for autocompleteincludes/MslsPostTag.php53$args (array)
msls_post_tag_suggest_termModify term object before using in suggestionsincludes/MslsPostTag.php62$term (WP_Term)
msls_term_select_titleChange the title displayed above term inputsincludes/MslsPostTag.php269-272None (returns string)
msls_main_saveCompletely override the save routineincludes/MslsMain.php141$object_id, $class_name
msls_admin_icon_get_edit_newCustomize the create/edit URLincludes/MslsAdminIcon.php283$path (string)

Action Hooks

ActionPurposeLocationParameters
msls_post_tag_edit_inputAfter edit form fields renderedincludes/MslsPostTag.php145$tag, $taxonomy
msls_post_tag_add_inputAfter add form fields renderedincludes/MslsPostTag.php111$taxonomy
msls_post_tag_classic_edit_inputAfter classic edit form renderedincludes/MslsPostTagClassic.php71$tag, $taxonomy
msls_post_tag_classic_add_inputAfter classic add form renderedincludes/MslsPostTagClassic.php39$taxonomy

Example: Customizing Suggestion Query

Example: Filtering Suggested Terms

Sources: includes/MslsPostTag.php46-72 includes/MslsPostTag.php111 includes/MslsPostTag.php145

Technical Implementation Details

Input Field Naming Convention

The system uses a specific naming pattern for form fields:

Autocomplete Mode:

  • Hidden ID field: msls_id_{blog_id} (e.g., msls_id_2)
  • Text input field: msls_title_{blog_id} (e.g., msls_title_2)
  • On submission, JavaScript copies the selected ID from a data attribute to the hidden field

Classic Mode:

  • Select field: msls_input_{language} (e.g., msls_input_de_DE)

The get_input_array() method at includes/MslsMain.php67-90 processes these fields by:

  1. Filtering INPUT_POST for keys containing Component::INPUT_PREFIX (which equals msls_input_)
  2. Extracting the language code from the field name
  3. Building an associative array of language => term_id

Sources: includes/MslsPostTag.php103-105 includes/MslsPostTag.php137-139 includes/MslsPostTagClassic.php29-33

Duplicate Prevention

Both MslsPostTag and MslsPostTagClassic use did_action() to prevent duplicate rendering when multiple taxonomies trigger the same hooks:

This check at includes/MslsPostTag.php95 ensures that if multiple taxonomies are registered and the add form is rendered multiple times in a single request, only the first execution proceeds.

Sources: includes/MslsPostTag.php95-97 includes/MslsPostTag.php121-123 includes/MslsPostTagClassic.php23-25

Blog Context Switching

The system extensively uses WordPress's switch_to_blog() and restore_current_blog() functions:

  1. During rendering: To fetch term data and generate icons for each blog
  2. During saving: To save bidirectional relationships in each blog's database
  3. During suggestions: To query terms from the target blog

This switching is critical in a multisite environment where each blog has its own set of terms. The pattern is:

Sources: includes/MslsPostTag.php176 includes/MslsPostTag.php204 includes/MslsMain.php164-177