Adding And Removing Taxonomies

Quality Control comes with a bunch of ticket taxonomies built in: Status, Priority, Milestone and of course Category and Tag. While these should cover most project management needs, you may want to switch them up.

Removing An Existing Taxonomy

First of all, you might not need some of the provided taxonomies and it’s pretty easy to remove them. Just add the following code to your child theme‘s functions.php file:

function qc_remove_taxonomies() {
    remove_theme_support( 'ticket-milestones' );
}
add_action( 'after_setup_theme', 'qc_remove_taxonomies', 11 );

You will find all the corresponding add_theme_support() calls in qualitycontrol/includes/core.php.

The QC_Taxonomy Class

Each taxonomy can show up in quite a few places throughout the theme, so we keep all the common pieces in a generic QC_Taxonomy class. It has methods that register the taxonomy, show the dropdown on the ticket form etc. It is defined in qualitycontrol/includes/class-qc-taxonomy.php.

Each taxonomy has it’s own child class, which extends the QC_Taxonomy class.

Adding A New Taxonomy

Let’s say the Tag taxonomy isn’t enough to describe what the ticket is about and you would like to add a ‘Focus’ taxonomy, with terms like ‘performance’, ‘security’ and ‘ui’.

We’re going to create a plugin folder, namely wp-content/plugins/qc-focus and we’ll make a plugin.php file inside, with all the appropriate headers and some init code:

<?php
/*
Plugin Name: QC Focus Taxonomy
Description: Adds a Focus Taxonomy for the Quality Control theme
Version: 1.0
Author: scribu
Author URI: http://appthemes.com
License: GPL2
*/
 
function qc_focus_init() {
    if ( !class_exists( 'QC_Taxonomy' ) )
        return;
 
    require dirname(__FILE__) . '/taxonomy.php';
}
 
add_action( 'after_setup_theme', 'qc_focus_init' );

Then, all we have to do is create taxonomy.php and define a child class for our new taxonomy:

<?php
 
class QC_Ticket_Focus extends QC_Taxonomy {
 
    function __construct() {
        parent::__construct(
            'ticket_focus',
            'focus',
            array(
                'name' => __( 'Focus', APP_TD ),
                'singular_name' => __( 'Focus', APP_TD ),
                'search_items' => __( 'Search Focus', APP_TD ),
                'update_item' => __( 'Update Focus', APP_TD ),
                'add_new_item' => __( 'Add New Focus', APP_TD ),
                'new_item_name' => __( 'New Focus Name', APP_TD ),
                'edit_item' => __( 'Edit Focus', APP_TD )
            )
        );
    }
}
 
$GLOBALS['ticket_focus'] = new QC_Ticket_Focus;

The first parameter is the taxonomy name, the second is the URL slug and the third is an associative array of labels. All these parameters get passed directly to register_taxonomy().

If you would like to customize a certain aspect of how that taxonomy is displayed, just overwrite the corresponding method from QC_Taxonomy.

Like this tutorial? Subscribe and get the latest tutorials delivered straight to your inbox or feed reader.

Your rating: none
Rating: 4.5 - 6 votes

Popular Add-ons

Mapsupreme for Vantage

A plugin that adds additional Google Maps to your Vantage theme.


(28)
$29

Category Icons

Add icons to your ClassiPress categories


(6)
$19

Coupon Countdown

Add dynamic countdown to show the expiry time left for each coupon


(3)
$19