register_taxonomy

The timeline below displays how wordpress function register_taxonomy has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.2

/**
 * Creates or modifies a taxonomy object.
 *
 * Note: Do not use before the {@see 'init'} hook.
 *
 * A simple function for creating or modifying a taxonomy object based on
 * the parameters given. If modifying an existing taxonomy object, note
 * that the `$object_type` value from the original registration will be
 * overwritten.
 *
 * @since 2.3.0
 * @since 4.2.0 Introduced `show_in_quick_edit` argument.
 * @since 4.4.0 The `show_ui` argument is now enforced on the term editing screen.
 * @since 4.4.0 The `public` argument now controls whether the taxonomy can be queried on the front end.
 * @since 4.5.0 Introduced `publicly_queryable` argument.
 * @since 4.7.0 Introduced `show_in_rest`, 'rest_base' and 'rest_controller_class'
 *              arguments to register the taxonomy in REST API.
 * @since 5.1.0 Introduced `meta_box_sanitize_cb` argument.
 * @since 5.4.0 Added the registered taxonomy object as a return value.
 * @since 5.5.0 Introduced `default_term` argument.
 * @since 5.9.0 Introduced `rest_namespace` argument.
 *
 * @global WP_Taxonomy[] $wp_taxonomies Registered taxonomies.
 *
 * @param string       $taxonomy    Taxonomy key. Must not exceed 32 characters and may only contain
 *                                  lowercase alphanumeric characters, dashes, and underscores. See sanitize_key().
 * @param array|string $object_type Object type or array of object types with which the taxonomy should be associated.
 * @param array|string $args        {
 *     Optional. Array or query string of arguments for registering a taxonomy.
 *
 *     @type string[]      $labels                An array of labels for this taxonomy. By default, Tag labels are
 *                                                used for non-hierarchical taxonomies, and Category labels are used
 *                                                for hierarchical taxonomies. See accepted values in
 *                                                get_taxonomy_labels(). Default empty array.
 *     @type string        $description           A short descriptive summary of what the taxonomy is for. Default empty.
 *     @type bool          $public                Whether a taxonomy is intended for use publicly either via
 *                                                the admin interface or by front-end users. The default settings
 *                                                of `$publicly_queryable`, `$show_ui`, and `$show_in_nav_menus`
 *                                                are inherited from `$public`.
 *     @type bool          $publicly_queryable    Whether the taxonomy is publicly queryable.
 *                                                If not set, the default is inherited from `$public`
 *     @type bool          $hierarchical          Whether the taxonomy is hierarchical. Default false.
 *     @type bool          $show_ui               Whether to generate and allow a UI for managing terms in this taxonomy in
 *                                                the admin. If not set, the default is inherited from `$public`
 *                                                (default true).
 *     @type bool          $show_in_menu          Whether to show the taxonomy in the admin menu. If true, the taxonomy is
 *                                                shown as a submenu of the object type menu. If false, no menu is shown.
 *                                                `$show_ui` must be true. If not set, default is inherited from `$show_ui`
 *                                                (default true).
 *     @type bool          $show_in_nav_menus     Makes this taxonomy available for selection in navigation menus. If not
 *                                                set, the default is inherited from `$public` (default true).
 *     @type bool          $show_in_rest          Whether to include the taxonomy in the REST API. Set this to true
 *                                                for the taxonomy to be available in the block editor.
 *     @type string        $rest_base             To change the base url of REST API route. Default is $taxonomy.
 *     @type string        $rest_namespace        To change the namespace URL of REST API route. Default is wp/v2.
 *     @type string        $rest_controller_class REST API Controller class name. Default is 'WP_REST_Terms_Controller'.
 *     @type bool          $show_tagcloud         Whether to list the taxonomy in the Tag Cloud Widget controls. If not set,
 *                                                the default is inherited from `$show_ui` (default true).
 *     @type bool          $show_in_quick_edit    Whether to show the taxonomy in the quick/bulk edit panel. It not set,
 *                                                the default is inherited from `$show_ui` (default true).
 *     @type bool          $show_admin_column     Whether to display a column for the taxonomy on its post type listing
 *                                                screens. Default false.
 *     @type bool|callable $meta_box_cb           Provide a callback function for the meta box display. If not set,
 *                                                post_categories_meta_box() is used for hierarchical taxonomies, and
 *                                                post_tags_meta_box() is used for non-hierarchical. If false, no meta
 *                                                box is shown.
 *     @type callable      $meta_box_sanitize_cb  Callback function for sanitizing taxonomy data saved from a meta
 *                                                box. If no callback is defined, an appropriate one is determined
 *                                                based on the value of `$meta_box_cb`.
 *     @type string[]      $capabilities {
 *         Array of capabilities for this taxonomy.
 *
 *         @type string $manage_terms Default 'manage_categories'.
 *         @type string $edit_terms   Default 'manage_categories'.
 *         @type string $delete_terms Default 'manage_categories'.
 *         @type string $assign_terms Default 'edit_posts'.
 *     }
 *     @type bool|array    $rewrite {
 *         Triggers the handling of rewrites for this taxonomy. Default true, using $taxonomy as slug. To prevent
 *         rewrite, set to false. To specify rewrite rules, an array can be passed with any of these keys:
 *
 *         @type string $slug         Customize the permastruct slug. Default `$taxonomy` key.
 *         @type bool   $with_front   Should the permastruct be prepended with WP_Rewrite::$front. Default true.
 *         @type bool   $hierarchical Either hierarchical rewrite tag or not. Default false.
 *         @type int    $ep_mask      Assign an endpoint mask. Default `EP_NONE`.
 *     }
 *     @type string|bool   $query_var             Sets the query var key for this taxonomy. Default `$taxonomy` key. If
 *                                                false, a taxonomy cannot be loaded at `?{query_var}={term_slug}`. If a
 *                                                string, the query `?{query_var}={term_slug}` will be valid.
 *     @type callable      $update_count_callback Works much like a hook, in that it will be called when the count is
 *                                                updated. Default _update_post_term_count() for taxonomies attached
 *                                                to post types, which confirms that the objects are published before
 *                                                counting them. Default _update_generic_term_count() for taxonomies
 *                                                attached to other object types, such as users.
 *     @type string|array  $default_term {
 *         Default term to be used for the taxonomy.
 *
 *         @type string $name         Name of default term.
 *         @type string $slug         Slug for default term. Default empty.
 *         @type string $description  Description for default term. Default empty.
 *     }
 *     @type bool          $sort                  Whether terms in this taxonomy should be sorted in the order they are
 *                                                provided to `wp_set_object_terms()`. Default null which equates to false.
 *     @type array         $args                  Array of arguments to automatically use inside `wp_get_object_terms()`
 *                                                for this taxonomy.
 *     @type bool          $_builtin              This taxonomy is a "built-in" taxonomy. INTERNAL USE ONLY!
 *                                                Default false.
 * }
 * @return WP_Taxonomy|WP_Error The registered taxonomy object on success, WP_Error object on failure.
 */
function register_taxonomy($taxonomy, $object_type, $args = array())
{
    global $wp_taxonomies;
    if (!is_array($wp_taxonomies)) {
        $wp_taxonomies = array();
    }
    $args = wp_parse_args($args);
    if (empty($taxonomy) || strlen($taxonomy) > 32) {
        _doing_it_wrong(__FUNCTION__, __('Taxonomy names must be between 1 and 32 characters in length.'), '4.2.0');
        return new WP_Error('taxonomy_length_invalid', __('Taxonomy names must be between 1 and 32 characters in length.'));
    }
    $taxonomy_object = new WP_Taxonomy($taxonomy, $object_type, $args);
    $taxonomy_object->add_rewrite_rules();
    $wp_taxonomies[$taxonomy] = $taxonomy_object;
    $taxonomy_object->add_hooks();
    // Add default term.
    if (!empty($taxonomy_object->default_term)) {
        $term = term_exists($taxonomy_object->default_term['name'], $taxonomy);
        if ($term) {
            update_option('default_term_' . $taxonomy_object->name, $term['term_id']);
        } else {
            $term = wp_insert_term($taxonomy_object->default_term['name'], $taxonomy, array('slug' => sanitize_title($taxonomy_object->default_term['slug']), 'description' => $taxonomy_object->default_term['description']));
            // Update `term_id` in options.
            if (!is_wp_error($term)) {
                update_option('default_term_' . $taxonomy_object->name, $term['term_id']);
            }
        }
    }
    /**
     * Fires after a taxonomy is registered.
     *
     * @since 3.3.0
     *
     * @param string       $taxonomy    Taxonomy slug.
     * @param array|string $object_type Object type or array of object types.
     * @param array        $args        Array of taxonomy registration arguments.
     */
    do_action('registered_taxonomy', $taxonomy, $object_type, (array) $taxonomy_object);
    /**
     * Fires after a specific taxonomy is registered.
     *
     * The dynamic portion of the filter name, `$taxonomy`, refers to the taxonomy key.
     *
     * Possible hook names include:
     *
     *  - `registered_taxonomy_category`
     *  - `registered_taxonomy_post_tag`
     *
     * @since 6.0.0
     *
     * @param string       $taxonomy    Taxonomy slug.
     * @param array|string $object_type Object type or array of object types.
     * @param array        $args        Array of taxonomy registration arguments.
     */
    do_action("registered_taxonomy_{$taxonomy}", $taxonomy, $object_type, (array) $taxonomy_object);
    return $taxonomy_object;
}

WordPress Version: 6.1

/**
 * Creates or modifies a taxonomy object.
 *
 * Note: Do not use before the {@see 'init'} hook.
 *
 * A simple function for creating or modifying a taxonomy object based on
 * the parameters given. If modifying an existing taxonomy object, note
 * that the `$object_type` value from the original registration will be
 * overwritten.
 *
 * @since 2.3.0
 * @since 4.2.0 Introduced `show_in_quick_edit` argument.
 * @since 4.4.0 The `show_ui` argument is now enforced on the term editing screen.
 * @since 4.4.0 The `public` argument now controls whether the taxonomy can be queried on the front end.
 * @since 4.5.0 Introduced `publicly_queryable` argument.
 * @since 4.7.0 Introduced `show_in_rest`, 'rest_base' and 'rest_controller_class'
 *              arguments to register the taxonomy in REST API.
 * @since 5.1.0 Introduced `meta_box_sanitize_cb` argument.
 * @since 5.4.0 Added the registered taxonomy object as a return value.
 * @since 5.5.0 Introduced `default_term` argument.
 * @since 5.9.0 Introduced `rest_namespace` argument.
 *
 * @global WP_Taxonomy[] $wp_taxonomies Registered taxonomies.
 *
 * @param string       $taxonomy    Taxonomy key, must not exceed 32 characters and may only contain lowercase alphanumeric
 *                                  characters, dashes, and underscores. See sanitize_key().
 * @param array|string $object_type Object type or array of object types with which the taxonomy should be associated.
 * @param array|string $args        {
 *     Optional. Array or query string of arguments for registering a taxonomy.
 *
 *     @type string[]      $labels                An array of labels for this taxonomy. By default, Tag labels are
 *                                                used for non-hierarchical taxonomies, and Category labels are used
 *                                                for hierarchical taxonomies. See accepted values in
 *                                                get_taxonomy_labels(). Default empty array.
 *     @type string        $description           A short descriptive summary of what the taxonomy is for. Default empty.
 *     @type bool          $public                Whether a taxonomy is intended for use publicly either via
 *                                                the admin interface or by front-end users. The default settings
 *                                                of `$publicly_queryable`, `$show_ui`, and `$show_in_nav_menus`
 *                                                are inherited from `$public`.
 *     @type bool          $publicly_queryable    Whether the taxonomy is publicly queryable.
 *                                                If not set, the default is inherited from `$public`
 *     @type bool          $hierarchical          Whether the taxonomy is hierarchical. Default false.
 *     @type bool          $show_ui               Whether to generate and allow a UI for managing terms in this taxonomy in
 *                                                the admin. If not set, the default is inherited from `$public`
 *                                                (default true).
 *     @type bool          $show_in_menu          Whether to show the taxonomy in the admin menu. If true, the taxonomy is
 *                                                shown as a submenu of the object type menu. If false, no menu is shown.
 *                                                `$show_ui` must be true. If not set, default is inherited from `$show_ui`
 *                                                (default true).
 *     @type bool          $show_in_nav_menus     Makes this taxonomy available for selection in navigation menus. If not
 *                                                set, the default is inherited from `$public` (default true).
 *     @type bool          $show_in_rest          Whether to include the taxonomy in the REST API. Set this to true
 *                                                for the taxonomy to be available in the block editor.
 *     @type string        $rest_base             To change the base url of REST API route. Default is $taxonomy.
 *     @type string        $rest_namespace        To change the namespace URL of REST API route. Default is wp/v2.
 *     @type string        $rest_controller_class REST API Controller class name. Default is 'WP_REST_Terms_Controller'.
 *     @type bool          $show_tagcloud         Whether to list the taxonomy in the Tag Cloud Widget controls. If not set,
 *                                                the default is inherited from `$show_ui` (default true).
 *     @type bool          $show_in_quick_edit    Whether to show the taxonomy in the quick/bulk edit panel. It not set,
 *                                                the default is inherited from `$show_ui` (default true).
 *     @type bool          $show_admin_column     Whether to display a column for the taxonomy on its post type listing
 *                                                screens. Default false.
 *     @type bool|callable $meta_box_cb           Provide a callback function for the meta box display. If not set,
 *                                                post_categories_meta_box() is used for hierarchical taxonomies, and
 *                                                post_tags_meta_box() is used for non-hierarchical. If false, no meta
 *                                                box is shown.
 *     @type callable      $meta_box_sanitize_cb  Callback function for sanitizing taxonomy data saved from a meta
 *                                                box. If no callback is defined, an appropriate one is determined
 *                                                based on the value of `$meta_box_cb`.
 *     @type string[]      $capabilities {
 *         Array of capabilities for this taxonomy.
 *
 *         @type string $manage_terms Default 'manage_categories'.
 *         @type string $edit_terms   Default 'manage_categories'.
 *         @type string $delete_terms Default 'manage_categories'.
 *         @type string $assign_terms Default 'edit_posts'.
 *     }
 *     @type bool|array    $rewrite {
 *         Triggers the handling of rewrites for this taxonomy. Default true, using $taxonomy as slug. To prevent
 *         rewrite, set to false. To specify rewrite rules, an array can be passed with any of these keys:
 *
 *         @type string $slug         Customize the permastruct slug. Default `$taxonomy` key.
 *         @type bool   $with_front   Should the permastruct be prepended with WP_Rewrite::$front. Default true.
 *         @type bool   $hierarchical Either hierarchical rewrite tag or not. Default false.
 *         @type int    $ep_mask      Assign an endpoint mask. Default `EP_NONE`.
 *     }
 *     @type string|bool   $query_var             Sets the query var key for this taxonomy. Default `$taxonomy` key. If
 *                                                false, a taxonomy cannot be loaded at `?{query_var}={term_slug}`. If a
 *                                                string, the query `?{query_var}={term_slug}` will be valid.
 *     @type callable      $update_count_callback Works much like a hook, in that it will be called when the count is
 *                                                updated. Default _update_post_term_count() for taxonomies attached
 *                                                to post types, which confirms that the objects are published before
 *                                                counting them. Default _update_generic_term_count() for taxonomies
 *                                                attached to other object types, such as users.
 *     @type string|array  $default_term {
 *         Default term to be used for the taxonomy.
 *
 *         @type string $name         Name of default term.
 *         @type string $slug         Slug for default term. Default empty.
 *         @type string $description  Description for default term. Default empty.
 *     }
 *     @type bool          $sort                  Whether terms in this taxonomy should be sorted in the order they are
 *                                                provided to `wp_set_object_terms()`. Default null which equates to false.
 *     @type array         $args                  Array of arguments to automatically use inside `wp_get_object_terms()`
 *                                                for this taxonomy.
 *     @type bool          $_builtin              This taxonomy is a "built-in" taxonomy. INTERNAL USE ONLY!
 *                                                Default false.
 * }
 * @return WP_Taxonomy|WP_Error The registered taxonomy object on success, WP_Error object on failure.
 */
function register_taxonomy($taxonomy, $object_type, $args = array())
{
    global $wp_taxonomies;
    if (!is_array($wp_taxonomies)) {
        $wp_taxonomies = array();
    }
    $args = wp_parse_args($args);
    if (empty($taxonomy) || strlen($taxonomy) > 32) {
        _doing_it_wrong(__FUNCTION__, __('Taxonomy names must be between 1 and 32 characters in length.'), '4.2.0');
        return new WP_Error('taxonomy_length_invalid', __('Taxonomy names must be between 1 and 32 characters in length.'));
    }
    $taxonomy_object = new WP_Taxonomy($taxonomy, $object_type, $args);
    $taxonomy_object->add_rewrite_rules();
    $wp_taxonomies[$taxonomy] = $taxonomy_object;
    $taxonomy_object->add_hooks();
    // Add default term.
    if (!empty($taxonomy_object->default_term)) {
        $term = term_exists($taxonomy_object->default_term['name'], $taxonomy);
        if ($term) {
            update_option('default_term_' . $taxonomy_object->name, $term['term_id']);
        } else {
            $term = wp_insert_term($taxonomy_object->default_term['name'], $taxonomy, array('slug' => sanitize_title($taxonomy_object->default_term['slug']), 'description' => $taxonomy_object->default_term['description']));
            // Update `term_id` in options.
            if (!is_wp_error($term)) {
                update_option('default_term_' . $taxonomy_object->name, $term['term_id']);
            }
        }
    }
    /**
     * Fires after a taxonomy is registered.
     *
     * @since 3.3.0
     *
     * @param string       $taxonomy    Taxonomy slug.
     * @param array|string $object_type Object type or array of object types.
     * @param array        $args        Array of taxonomy registration arguments.
     */
    do_action('registered_taxonomy', $taxonomy, $object_type, (array) $taxonomy_object);
    /**
     * Fires after a specific taxonomy is registered.
     *
     * The dynamic portion of the filter name, `$taxonomy`, refers to the taxonomy key.
     *
     * Possible hook names include:
     *
     *  - `registered_taxonomy_category`
     *  - `registered_taxonomy_post_tag`
     *
     * @since 6.0.0
     *
     * @param string       $taxonomy    Taxonomy slug.
     * @param array|string $object_type Object type or array of object types.
     * @param array        $args        Array of taxonomy registration arguments.
     */
    do_action("registered_taxonomy_{$taxonomy}", $taxonomy, $object_type, (array) $taxonomy_object);
    return $taxonomy_object;
}

WordPress Version: 5.9

/**
 * Creates or modifies a taxonomy object.
 *
 * Note: Do not use before the {@see 'init'} hook.
 *
 * A simple function for creating or modifying a taxonomy object based on
 * the parameters given. If modifying an existing taxonomy object, note
 * that the `$object_type` value from the original registration will be
 * overwritten.
 *
 * @since 2.3.0
 * @since 4.2.0 Introduced `show_in_quick_edit` argument.
 * @since 4.4.0 The `show_ui` argument is now enforced on the term editing screen.
 * @since 4.4.0 The `public` argument now controls whether the taxonomy can be queried on the front end.
 * @since 4.5.0 Introduced `publicly_queryable` argument.
 * @since 4.7.0 Introduced `show_in_rest`, 'rest_base' and 'rest_controller_class'
 *              arguments to register the Taxonomy in REST API.
 * @since 5.1.0 Introduced `meta_box_sanitize_cb` argument.
 * @since 5.4.0 Added the registered taxonomy object as a return value.
 * @since 5.5.0 Introduced `default_term` argument.
 * @since 5.9.0 Introduced `rest_namespace` argument.
 *
 * @global WP_Taxonomy[] $wp_taxonomies Registered taxonomies.
 *
 * @param string       $taxonomy    Taxonomy key, must not exceed 32 characters.
 * @param array|string $object_type Object type or array of object types with which the taxonomy should be associated.
 * @param array|string $args        {
 *     Optional. Array or query string of arguments for registering a taxonomy.
 *
 *     @type string[]      $labels                An array of labels for this taxonomy. By default, Tag labels are
 *                                                used for non-hierarchical taxonomies, and Category labels are used
 *                                                for hierarchical taxonomies. See accepted values in
 *                                                get_taxonomy_labels(). Default empty array.
 *     @type string        $description           A short descriptive summary of what the taxonomy is for. Default empty.
 *     @type bool          $public                Whether a taxonomy is intended for use publicly either via
 *                                                the admin interface or by front-end users. The default settings
 *                                                of `$publicly_queryable`, `$show_ui`, and `$show_in_nav_menus`
 *                                                are inherited from `$public`.
 *     @type bool          $publicly_queryable    Whether the taxonomy is publicly queryable.
 *                                                If not set, the default is inherited from `$public`
 *     @type bool          $hierarchical          Whether the taxonomy is hierarchical. Default false.
 *     @type bool          $show_ui               Whether to generate and allow a UI for managing terms in this taxonomy in
 *                                                the admin. If not set, the default is inherited from `$public`
 *                                                (default true).
 *     @type bool          $show_in_menu          Whether to show the taxonomy in the admin menu. If true, the taxonomy is
 *                                                shown as a submenu of the object type menu. If false, no menu is shown.
 *                                                `$show_ui` must be true. If not set, default is inherited from `$show_ui`
 *                                                (default true).
 *     @type bool          $show_in_nav_menus     Makes this taxonomy available for selection in navigation menus. If not
 *                                                set, the default is inherited from `$public` (default true).
 *     @type bool          $show_in_rest          Whether to include the taxonomy in the REST API. Set this to true
 *                                                for the taxonomy to be available in the block editor.
 *     @type string        $rest_base             To change the base url of REST API route. Default is $taxonomy.
 *     @type string        $rest_namespace        To change the namespace URL of REST API route. Default is wp/v2.
 *     @type string        $rest_controller_class REST API Controller class name. Default is 'WP_REST_Terms_Controller'.
 *     @type bool          $show_tagcloud         Whether to list the taxonomy in the Tag Cloud Widget controls. If not set,
 *                                                the default is inherited from `$show_ui` (default true).
 *     @type bool          $show_in_quick_edit    Whether to show the taxonomy in the quick/bulk edit panel. It not set,
 *                                                the default is inherited from `$show_ui` (default true).
 *     @type bool          $show_admin_column     Whether to display a column for the taxonomy on its post type listing
 *                                                screens. Default false.
 *     @type bool|callable $meta_box_cb           Provide a callback function for the meta box display. If not set,
 *                                                post_categories_meta_box() is used for hierarchical taxonomies, and
 *                                                post_tags_meta_box() is used for non-hierarchical. If false, no meta
 *                                                box is shown.
 *     @type callable      $meta_box_sanitize_cb  Callback function for sanitizing taxonomy data saved from a meta
 *                                                box. If no callback is defined, an appropriate one is determined
 *                                                based on the value of `$meta_box_cb`.
 *     @type string[]      $capabilities {
 *         Array of capabilities for this taxonomy.
 *
 *         @type string $manage_terms Default 'manage_categories'.
 *         @type string $edit_terms   Default 'manage_categories'.
 *         @type string $delete_terms Default 'manage_categories'.
 *         @type string $assign_terms Default 'edit_posts'.
 *     }
 *     @type bool|array    $rewrite {
 *         Triggers the handling of rewrites for this taxonomy. Default true, using $taxonomy as slug. To prevent
 *         rewrite, set to false. To specify rewrite rules, an array can be passed with any of these keys:
 *
 *         @type string $slug         Customize the permastruct slug. Default `$taxonomy` key.
 *         @type bool   $with_front   Should the permastruct be prepended with WP_Rewrite::$front. Default true.
 *         @type bool   $hierarchical Either hierarchical rewrite tag or not. Default false.
 *         @type int    $ep_mask      Assign an endpoint mask. Default `EP_NONE`.
 *     }
 *     @type string|bool   $query_var             Sets the query var key for this taxonomy. Default `$taxonomy` key. If
 *                                                false, a taxonomy cannot be loaded at `?{query_var}={term_slug}`. If a
 *                                                string, the query `?{query_var}={term_slug}` will be valid.
 *     @type callable      $update_count_callback Works much like a hook, in that it will be called when the count is
 *                                                updated. Default _update_post_term_count() for taxonomies attached
 *                                                to post types, which confirms that the objects are published before
 *                                                counting them. Default _update_generic_term_count() for taxonomies
 *                                                attached to other object types, such as users.
 *     @type string|array  $default_term {
 *         Default term to be used for the taxonomy.
 *
 *         @type string $name         Name of default term.
 *         @type string $slug         Slug for default term. Default empty.
 *         @type string $description  Description for default term. Default empty.
 *     }
 *     @type bool          $sort                  Whether terms in this taxonomy should be sorted in the order they are
 *                                                provided to `wp_set_object_terms()`. Default null which equates to false.
 *     @type array         $args                  Array of arguments to automatically use inside `wp_get_object_terms()`
 *                                                for this taxonomy.
 *     @type bool          $_builtin              This taxonomy is a "built-in" taxonomy. INTERNAL USE ONLY!
 *                                                Default false.
 * }
 * @return WP_Taxonomy|WP_Error The registered taxonomy object on success, WP_Error object on failure.
 */
function register_taxonomy($taxonomy, $object_type, $args = array())
{
    global $wp_taxonomies;
    if (!is_array($wp_taxonomies)) {
        $wp_taxonomies = array();
    }
    $args = wp_parse_args($args);
    if (empty($taxonomy) || strlen($taxonomy) > 32) {
        _doing_it_wrong(__FUNCTION__, __('Taxonomy names must be between 1 and 32 characters in length.'), '4.2.0');
        return new WP_Error('taxonomy_length_invalid', __('Taxonomy names must be between 1 and 32 characters in length.'));
    }
    $taxonomy_object = new WP_Taxonomy($taxonomy, $object_type, $args);
    $taxonomy_object->add_rewrite_rules();
    $wp_taxonomies[$taxonomy] = $taxonomy_object;
    $taxonomy_object->add_hooks();
    // Add default term.
    if (!empty($taxonomy_object->default_term)) {
        $term = term_exists($taxonomy_object->default_term['name'], $taxonomy);
        if ($term) {
            update_option('default_term_' . $taxonomy_object->name, $term['term_id']);
        } else {
            $term = wp_insert_term($taxonomy_object->default_term['name'], $taxonomy, array('slug' => sanitize_title($taxonomy_object->default_term['slug']), 'description' => $taxonomy_object->default_term['description']));
            // Update `term_id` in options.
            if (!is_wp_error($term)) {
                update_option('default_term_' . $taxonomy_object->name, $term['term_id']);
            }
        }
    }
    /**
     * Fires after a taxonomy is registered.
     *
     * @since 3.3.0
     *
     * @param string       $taxonomy    Taxonomy slug.
     * @param array|string $object_type Object type or array of object types.
     * @param array        $args        Array of taxonomy registration arguments.
     */
    do_action('registered_taxonomy', $taxonomy, $object_type, (array) $taxonomy_object);
    return $taxonomy_object;
}

WordPress Version: 5.7

/**
 * Creates or modifies a taxonomy object.
 *
 * Note: Do not use before the {@see 'init'} hook.
 *
 * A simple function for creating or modifying a taxonomy object based on
 * the parameters given. If modifying an existing taxonomy object, note
 * that the `$object_type` value from the original registration will be
 * overwritten.
 *
 * @since 2.3.0
 * @since 4.2.0 Introduced `show_in_quick_edit` argument.
 * @since 4.4.0 The `show_ui` argument is now enforced on the term editing screen.
 * @since 4.4.0 The `public` argument now controls whether the taxonomy can be queried on the front end.
 * @since 4.5.0 Introduced `publicly_queryable` argument.
 * @since 4.7.0 Introduced `show_in_rest`, 'rest_base' and 'rest_controller_class'
 *              arguments to register the Taxonomy in REST API.
 * @since 5.1.0 Introduced `meta_box_sanitize_cb` argument.
 * @since 5.4.0 Added the registered taxonomy object as a return value.
 * @since 5.5.0 Introduced `default_term` argument.
 *
 * @global array $wp_taxonomies Registered taxonomies.
 *
 * @param string       $taxonomy    Taxonomy key, must not exceed 32 characters.
 * @param array|string $object_type Object type or array of object types with which the taxonomy should be associated.
 * @param array|string $args        {
 *     Optional. Array or query string of arguments for registering a taxonomy.
 *
 *     @type string[]      $labels                An array of labels for this taxonomy. By default, Tag labels are
 *                                                used for non-hierarchical taxonomies, and Category labels are used
 *                                                for hierarchical taxonomies. See accepted values in
 *                                                get_taxonomy_labels(). Default empty array.
 *     @type string        $description           A short descriptive summary of what the taxonomy is for. Default empty.
 *     @type bool          $public                Whether a taxonomy is intended for use publicly either via
 *                                                the admin interface or by front-end users. The default settings
 *                                                of `$publicly_queryable`, `$show_ui`, and `$show_in_nav_menus`
 *                                                are inherited from `$public`.
 *     @type bool          $publicly_queryable    Whether the taxonomy is publicly queryable.
 *                                                If not set, the default is inherited from `$public`
 *     @type bool          $hierarchical          Whether the taxonomy is hierarchical. Default false.
 *     @type bool          $show_ui               Whether to generate and allow a UI for managing terms in this taxonomy in
 *                                                the admin. If not set, the default is inherited from `$public`
 *                                                (default true).
 *     @type bool          $show_in_menu          Whether to show the taxonomy in the admin menu. If true, the taxonomy is
 *                                                shown as a submenu of the object type menu. If false, no menu is shown.
 *                                                `$show_ui` must be true. If not set, default is inherited from `$show_ui`
 *                                                (default true).
 *     @type bool          $show_in_nav_menus     Makes this taxonomy available for selection in navigation menus. If not
 *                                                set, the default is inherited from `$public` (default true).
 *     @type bool          $show_in_rest          Whether to include the taxonomy in the REST API. Set this to true
 *                                                for the taxonomy to be available in the block editor.
 *     @type string        $rest_base             To change the base url of REST API route. Default is $taxonomy.
 *     @type string        $rest_controller_class REST API Controller class name. Default is 'WP_REST_Terms_Controller'.
 *     @type bool          $show_tagcloud         Whether to list the taxonomy in the Tag Cloud Widget controls. If not set,
 *                                                the default is inherited from `$show_ui` (default true).
 *     @type bool          $show_in_quick_edit    Whether to show the taxonomy in the quick/bulk edit panel. It not set,
 *                                                the default is inherited from `$show_ui` (default true).
 *     @type bool          $show_admin_column     Whether to display a column for the taxonomy on its post type listing
 *                                                screens. Default false.
 *     @type bool|callable $meta_box_cb           Provide a callback function for the meta box display. If not set,
 *                                                post_categories_meta_box() is used for hierarchical taxonomies, and
 *                                                post_tags_meta_box() is used for non-hierarchical. If false, no meta
 *                                                box is shown.
 *     @type callable      $meta_box_sanitize_cb  Callback function for sanitizing taxonomy data saved from a meta
 *                                                box. If no callback is defined, an appropriate one is determined
 *                                                based on the value of `$meta_box_cb`.
 *     @type string[]      $capabilities {
 *         Array of capabilities for this taxonomy.
 *
 *         @type string $manage_terms Default 'manage_categories'.
 *         @type string $edit_terms   Default 'manage_categories'.
 *         @type string $delete_terms Default 'manage_categories'.
 *         @type string $assign_terms Default 'edit_posts'.
 *     }
 *     @type bool|array    $rewrite {
 *         Triggers the handling of rewrites for this taxonomy. Default true, using $taxonomy as slug. To prevent
 *         rewrite, set to false. To specify rewrite rules, an array can be passed with any of these keys:
 *
 *         @type string $slug         Customize the permastruct slug. Default `$taxonomy` key.
 *         @type bool   $with_front   Should the permastruct be prepended with WP_Rewrite::$front. Default true.
 *         @type bool   $hierarchical Either hierarchical rewrite tag or not. Default false.
 *         @type int    $ep_mask      Assign an endpoint mask. Default `EP_NONE`.
 *     }
 *     @type string|bool   $query_var             Sets the query var key for this taxonomy. Default `$taxonomy` key. If
 *                                                false, a taxonomy cannot be loaded at `?{query_var}={term_slug}`. If a
 *                                                string, the query `?{query_var}={term_slug}` will be valid.
 *     @type callable      $update_count_callback Works much like a hook, in that it will be called when the count is
 *                                                updated. Default _update_post_term_count() for taxonomies attached
 *                                                to post types, which confirms that the objects are published before
 *                                                counting them. Default _update_generic_term_count() for taxonomies
 *                                                attached to other object types, such as users.
 *     @type string|array  $default_term {
 *         Default term to be used for the taxonomy.
 *
 *         @type string $name         Name of default term.
 *         @type string $slug         Slug for default term. Default empty.
 *         @type string $description  Description for default term. Default empty.
 *     }
 *     @type bool          $sort                  Whether terms in this taxonomy should be sorted in the order they are
 *                                                provided to `wp_set_object_terms()`. Default null which equates to false.
 *     @type array         $args                  Array of arguments to automatically use inside `wp_get_object_terms()`
 *                                                for this taxonomy.
 *     @type bool          $_builtin              This taxonomy is a "built-in" taxonomy. INTERNAL USE ONLY!
 *                                                Default false.
 * }
 * @return WP_Taxonomy|WP_Error The registered taxonomy object on success, WP_Error object on failure.
 */
function register_taxonomy($taxonomy, $object_type, $args = array())
{
    global $wp_taxonomies;
    if (!is_array($wp_taxonomies)) {
        $wp_taxonomies = array();
    }
    $args = wp_parse_args($args);
    if (empty($taxonomy) || strlen($taxonomy) > 32) {
        _doing_it_wrong(__FUNCTION__, __('Taxonomy names must be between 1 and 32 characters in length.'), '4.2.0');
        return new WP_Error('taxonomy_length_invalid', __('Taxonomy names must be between 1 and 32 characters in length.'));
    }
    $taxonomy_object = new WP_Taxonomy($taxonomy, $object_type, $args);
    $taxonomy_object->add_rewrite_rules();
    $wp_taxonomies[$taxonomy] = $taxonomy_object;
    $taxonomy_object->add_hooks();
    // Add default term.
    if (!empty($taxonomy_object->default_term)) {
        $term = term_exists($taxonomy_object->default_term['name'], $taxonomy);
        if ($term) {
            update_option('default_term_' . $taxonomy_object->name, $term['term_id']);
        } else {
            $term = wp_insert_term($taxonomy_object->default_term['name'], $taxonomy, array('slug' => sanitize_title($taxonomy_object->default_term['slug']), 'description' => $taxonomy_object->default_term['description']));
            // Update `term_id` in options.
            if (!is_wp_error($term)) {
                update_option('default_term_' . $taxonomy_object->name, $term['term_id']);
            }
        }
    }
    /**
     * Fires after a taxonomy is registered.
     *
     * @since 3.3.0
     *
     * @param string       $taxonomy    Taxonomy slug.
     * @param array|string $object_type Object type or array of object types.
     * @param array        $args        Array of taxonomy registration arguments.
     */
    do_action('registered_taxonomy', $taxonomy, $object_type, (array) $taxonomy_object);
    return $taxonomy_object;
}

WordPress Version: 5.5

/**
 * Creates or modifies a taxonomy object.
 *
 * Note: Do not use before the {@see 'init'} hook.
 *
 * A simple function for creating or modifying a taxonomy object based on
 * the parameters given. If modifying an existing taxonomy object, note
 * that the `$object_type` value from the original registration will be
 * overwritten.
 *
 * @since 2.3.0
 * @since 4.2.0 Introduced `show_in_quick_edit` argument.
 * @since 4.4.0 The `show_ui` argument is now enforced on the term editing screen.
 * @since 4.4.0 The `public` argument now controls whether the taxonomy can be queried on the front end.
 * @since 4.5.0 Introduced `publicly_queryable` argument.
 * @since 4.7.0 Introduced `show_in_rest`, 'rest_base' and 'rest_controller_class'
 *              arguments to register the Taxonomy in REST API.
 * @since 5.1.0 Introduced `meta_box_sanitize_cb` argument.
 * @since 5.4.0 Added the registered taxonomy object as a return value.
 * @since 5.5.0 Introduced `default_term` argument.
 *
 * @global array $wp_taxonomies Registered taxonomies.
 *
 * @param string       $taxonomy    Taxonomy key, must not exceed 32 characters.
 * @param array|string $object_type Object type or array of object types with which the taxonomy should be associated.
 * @param array|string $args        {
 *     Optional. Array or query string of arguments for registering a taxonomy.
 *
 *     @type array         $labels                An array of labels for this taxonomy. By default, Tag labels are
 *                                                used for non-hierarchical taxonomies, and Category labels are used
 *                                                for hierarchical taxonomies. See accepted values in
 *                                                get_taxonomy_labels(). Default empty array.
 *     @type string        $description           A short descriptive summary of what the taxonomy is for. Default empty.
 *     @type bool          $public                Whether a taxonomy is intended for use publicly either via
 *                                                the admin interface or by front-end users. The default settings
 *                                                of `$publicly_queryable`, `$show_ui`, and `$show_in_nav_menus`
 *                                                are inherited from `$public`.
 *     @type bool          $publicly_queryable    Whether the taxonomy is publicly queryable.
 *                                                If not set, the default is inherited from `$public`
 *     @type bool          $hierarchical          Whether the taxonomy is hierarchical. Default false.
 *     @type bool          $show_ui               Whether to generate and allow a UI for managing terms in this taxonomy in
 *                                                the admin. If not set, the default is inherited from `$public`
 *                                                (default true).
 *     @type bool          $show_in_menu          Whether to show the taxonomy in the admin menu. If true, the taxonomy is
 *                                                shown as a submenu of the object type menu. If false, no menu is shown.
 *                                                `$show_ui` must be true. If not set, default is inherited from `$show_ui`
 *                                                (default true).
 *     @type bool          $show_in_nav_menus     Makes this taxonomy available for selection in navigation menus. If not
 *                                                set, the default is inherited from `$public` (default true).
 *     @type bool          $show_in_rest          Whether to include the taxonomy in the REST API. Set this to true
 *                                                for the taxonomy to be available in the block editor.
 *     @type string        $rest_base             To change the base url of REST API route. Default is $taxonomy.
 *     @type string        $rest_controller_class REST API Controller class name. Default is 'WP_REST_Terms_Controller'.
 *     @type bool          $show_tagcloud         Whether to list the taxonomy in the Tag Cloud Widget controls. If not set,
 *                                                the default is inherited from `$show_ui` (default true).
 *     @type bool          $show_in_quick_edit    Whether to show the taxonomy in the quick/bulk edit panel. It not set,
 *                                                the default is inherited from `$show_ui` (default true).
 *     @type bool          $show_admin_column     Whether to display a column for the taxonomy on its post type listing
 *                                                screens. Default false.
 *     @type bool|callable $meta_box_cb           Provide a callback function for the meta box display. If not set,
 *                                                post_categories_meta_box() is used for hierarchical taxonomies, and
 *                                                post_tags_meta_box() is used for non-hierarchical. If false, no meta
 *                                                box is shown.
 *     @type callable      $meta_box_sanitize_cb  Callback function for sanitizing taxonomy data saved from a meta
 *                                                box. If no callback is defined, an appropriate one is determined
 *                                                based on the value of `$meta_box_cb`.
 *     @type array         $capabilities {
 *         Array of capabilities for this taxonomy.
 *
 *         @type string $manage_terms Default 'manage_categories'.
 *         @type string $edit_terms   Default 'manage_categories'.
 *         @type string $delete_terms Default 'manage_categories'.
 *         @type string $assign_terms Default 'edit_posts'.
 *     }
 *     @type bool|array    $rewrite {
 *         Triggers the handling of rewrites for this taxonomy. Default true, using $taxonomy as slug. To prevent
 *         rewrite, set to false. To specify rewrite rules, an array can be passed with any of these keys:
 *
 *         @type string $slug         Customize the permastruct slug. Default `$taxonomy` key.
 *         @type bool   $with_front   Should the permastruct be prepended with WP_Rewrite::$front. Default true.
 *         @type bool   $hierarchical Either hierarchical rewrite tag or not. Default false.
 *         @type int    $ep_mask      Assign an endpoint mask. Default `EP_NONE`.
 *     }
 *     @type string|bool   $query_var             Sets the query var key for this taxonomy. Default `$taxonomy` key. If
 *                                                false, a taxonomy cannot be loaded at `?{query_var}={term_slug}`. If a
 *                                                string, the query `?{query_var}={term_slug}` will be valid.
 *     @type callable      $update_count_callback Works much like a hook, in that it will be called when the count is
 *                                                updated. Default _update_post_term_count() for taxonomies attached
 *                                                to post types, which confirms that the objects are published before
 *                                                counting them. Default _update_generic_term_count() for taxonomies
 *                                                attached to other object types, such as users.
 *     @type string|array  $default_term {
 *         Default term to be used for the taxonomy.
 *
 *         @type string $name         Name of default term.
 *         @type string $slug         Slug for default term. Default empty.
 *         @type string $description  Description for default term. Default empty.
 *     }
 *     @type bool          $_builtin              This taxonomy is a "built-in" taxonomy. INTERNAL USE ONLY!
 *                                                Default false.
 * }
 * @return WP_Taxonomy|WP_Error The registered taxonomy object on success, WP_Error object on failure.
 */
function register_taxonomy($taxonomy, $object_type, $args = array())
{
    global $wp_taxonomies;
    if (!is_array($wp_taxonomies)) {
        $wp_taxonomies = array();
    }
    $args = wp_parse_args($args);
    if (empty($taxonomy) || strlen($taxonomy) > 32) {
        _doing_it_wrong(__FUNCTION__, __('Taxonomy names must be between 1 and 32 characters in length.'), '4.2.0');
        return new WP_Error('taxonomy_length_invalid', __('Taxonomy names must be between 1 and 32 characters in length.'));
    }
    $taxonomy_object = new WP_Taxonomy($taxonomy, $object_type, $args);
    $taxonomy_object->add_rewrite_rules();
    $wp_taxonomies[$taxonomy] = $taxonomy_object;
    $taxonomy_object->add_hooks();
    // Add default term.
    if (!empty($taxonomy_object->default_term)) {
        $term = term_exists($taxonomy_object->default_term['name'], $taxonomy);
        if ($term) {
            update_option('default_term_' . $taxonomy_object->name, $term['term_id']);
        } else {
            $term = wp_insert_term($taxonomy_object->default_term['name'], $taxonomy, array('slug' => sanitize_title($taxonomy_object->default_term['slug']), 'description' => $taxonomy_object->default_term['description']));
            // Update `term_id` in options.
            if (!is_wp_error($term)) {
                update_option('default_term_' . $taxonomy_object->name, $term['term_id']);
            }
        }
    }
    /**
     * Fires after a taxonomy is registered.
     *
     * @since 3.3.0
     *
     * @param string       $taxonomy    Taxonomy slug.
     * @param array|string $object_type Object type or array of object types.
     * @param array        $args        Array of taxonomy registration arguments.
     */
    do_action('registered_taxonomy', $taxonomy, $object_type, (array) $taxonomy_object);
    return $taxonomy_object;
}

WordPress Version: 5.4

/**
 * Creates or modifies a taxonomy object.
 *
 * Note: Do not use before the {@see 'init'} hook.
 *
 * A simple function for creating or modifying a taxonomy object based on
 * the parameters given. If modifying an existing taxonomy object, note
 * that the `$object_type` value from the original registration will be
 * overwritten.
 *
 * @since 2.3.0
 * @since 4.2.0 Introduced `show_in_quick_edit` argument.
 * @since 4.4.0 The `show_ui` argument is now enforced on the term editing screen.
 * @since 4.4.0 The `public` argument now controls whether the taxonomy can be queried on the front end.
 * @since 4.5.0 Introduced `publicly_queryable` argument.
 * @since 4.7.0 Introduced `show_in_rest`, 'rest_base' and 'rest_controller_class'
 *              arguments to register the Taxonomy in REST API.
 * @since 5.1.0 Introduced `meta_box_sanitize_cb` argument.
 * @since 5.4.0 Added the registered taxonomy object as a return value.
 *
 * @global array $wp_taxonomies Registered taxonomies.
 *
 * @param string       $taxonomy    Taxonomy key, must not exceed 32 characters.
 * @param array|string $object_type Object type or array of object types with which the taxonomy should be associated.
 * @param array|string $args        {
 *     Optional. Array or query string of arguments for registering a taxonomy.
 *
 *     @type array         $labels                An array of labels for this taxonomy. By default, Tag labels are
 *                                                used for non-hierarchical taxonomies, and Category labels are used
 *                                                for hierarchical taxonomies. See accepted values in
 *                                                get_taxonomy_labels(). Default empty array.
 *     @type string        $description           A short descriptive summary of what the taxonomy is for. Default empty.
 *     @type bool          $public                Whether a taxonomy is intended for use publicly either via
 *                                                the admin interface or by front-end users. The default settings
 *                                                of `$publicly_queryable`, `$show_ui`, and `$show_in_nav_menus`
 *                                                are inherited from `$public`.
 *     @type bool          $publicly_queryable    Whether the taxonomy is publicly queryable.
 *                                                If not set, the default is inherited from `$public`
 *     @type bool          $hierarchical          Whether the taxonomy is hierarchical. Default false.
 *     @type bool          $show_ui               Whether to generate and allow a UI for managing terms in this taxonomy in
 *                                                the admin. If not set, the default is inherited from `$public`
 *                                                (default true).
 *     @type bool          $show_in_menu          Whether to show the taxonomy in the admin menu. If true, the taxonomy is
 *                                                shown as a submenu of the object type menu. If false, no menu is shown.
 *                                                `$show_ui` must be true. If not set, default is inherited from `$show_ui`
 *                                                (default true).
 *     @type bool          $show_in_nav_menus     Makes this taxonomy available for selection in navigation menus. If not
 *                                                set, the default is inherited from `$public` (default true).
 *     @type bool          $show_in_rest          Whether to include the taxonomy in the REST API. Set this to true
 *                                                for the taxonomy to be available in the block editor.
 *     @type string        $rest_base             To change the base url of REST API route. Default is $taxonomy.
 *     @type string        $rest_controller_class REST API Controller class name. Default is 'WP_REST_Terms_Controller'.
 *     @type bool          $show_tagcloud         Whether to list the taxonomy in the Tag Cloud Widget controls. If not set,
 *                                                the default is inherited from `$show_ui` (default true).
 *     @type bool          $show_in_quick_edit    Whether to show the taxonomy in the quick/bulk edit panel. It not set,
 *                                                the default is inherited from `$show_ui` (default true).
 *     @type bool          $show_admin_column     Whether to display a column for the taxonomy on its post type listing
 *                                                screens. Default false.
 *     @type bool|callable $meta_box_cb           Provide a callback function for the meta box display. If not set,
 *                                                post_categories_meta_box() is used for hierarchical taxonomies, and
 *                                                post_tags_meta_box() is used for non-hierarchical. If false, no meta
 *                                                box is shown.
 *     @type callable      $meta_box_sanitize_cb  Callback function for sanitizing taxonomy data saved from a meta
 *                                                box. If no callback is defined, an appropriate one is determined
 *                                                based on the value of `$meta_box_cb`.
 *     @type array         $capabilities {
 *         Array of capabilities for this taxonomy.
 *
 *         @type string $manage_terms Default 'manage_categories'.
 *         @type string $edit_terms   Default 'manage_categories'.
 *         @type string $delete_terms Default 'manage_categories'.
 *         @type string $assign_terms Default 'edit_posts'.
 *     }
 *     @type bool|array    $rewrite {
 *         Triggers the handling of rewrites for this taxonomy. Default true, using $taxonomy as slug. To prevent
 *         rewrite, set to false. To specify rewrite rules, an array can be passed with any of these keys:
 *
 *         @type string $slug         Customize the permastruct slug. Default `$taxonomy` key.
 *         @type bool   $with_front   Should the permastruct be prepended with WP_Rewrite::$front. Default true.
 *         @type bool   $hierarchical Either hierarchical rewrite tag or not. Default false.
 *         @type int    $ep_mask      Assign an endpoint mask. Default `EP_NONE`.
 *     }
 *     @type string|bool   $query_var             Sets the query var key for this taxonomy. Default `$taxonomy` key. If
 *                                                false, a taxonomy cannot be loaded at `?{query_var}={term_slug}`. If a
 *                                                string, the query `?{query_var}={term_slug}` will be valid.
 *     @type callable      $update_count_callback Works much like a hook, in that it will be called when the count is
 *                                                updated. Default _update_post_term_count() for taxonomies attached
 *                                                to post types, which confirms that the objects are published before
 *                                                counting them. Default _update_generic_term_count() for taxonomies
 *                                                attached to other object types, such as users.
 *     @type bool          $_builtin              This taxonomy is a "built-in" taxonomy. INTERNAL USE ONLY!
 *                                                Default false.
 * }
 * @return WP_Taxonomy|WP_Error The registered taxonomy object on success, WP_Error object on failure.
 */
function register_taxonomy($taxonomy, $object_type, $args = array())
{
    global $wp_taxonomies;
    if (!is_array($wp_taxonomies)) {
        $wp_taxonomies = array();
    }
    $args = wp_parse_args($args);
    if (empty($taxonomy) || strlen($taxonomy) > 32) {
        _doing_it_wrong(__FUNCTION__, __('Taxonomy names must be between 1 and 32 characters in length.'), '4.2.0');
        return new WP_Error('taxonomy_length_invalid', __('Taxonomy names must be between 1 and 32 characters in length.'));
    }
    $taxonomy_object = new WP_Taxonomy($taxonomy, $object_type, $args);
    $taxonomy_object->add_rewrite_rules();
    $wp_taxonomies[$taxonomy] = $taxonomy_object;
    $taxonomy_object->add_hooks();
    /**
     * Fires after a taxonomy is registered.
     *
     * @since 3.3.0
     *
     * @param string       $taxonomy    Taxonomy slug.
     * @param array|string $object_type Object type or array of object types.
     * @param array        $args        Array of taxonomy registration arguments.
     */
    do_action('registered_taxonomy', $taxonomy, $object_type, (array) $taxonomy_object);
    return $taxonomy_object;
}

WordPress Version: 5.3

/**
 * Creates or modifies a taxonomy object.
 *
 * Note: Do not use before the {@see 'init'} hook.
 *
 * A simple function for creating or modifying a taxonomy object based on
 * the parameters given. If modifying an existing taxonomy object, note
 * that the `$object_type` value from the original registration will be
 * overwritten.
 *
 * @since 2.3.0
 * @since 4.2.0 Introduced `show_in_quick_edit` argument.
 * @since 4.4.0 The `show_ui` argument is now enforced on the term editing screen.
 * @since 4.4.0 The `public` argument now controls whether the taxonomy can be queried on the front end.
 * @since 4.5.0 Introduced `publicly_queryable` argument.
 * @since 4.7.0 Introduced `show_in_rest`, 'rest_base' and 'rest_controller_class'
 *              arguments to register the Taxonomy in REST API.
 * @since 5.1.0 Introduced `meta_box_sanitize_cb` argument.
 *
 * @global array $wp_taxonomies Registered taxonomies.
 *
 * @param string       $taxonomy    Taxonomy key, must not exceed 32 characters.
 * @param array|string $object_type Object type or array of object types with which the taxonomy should be associated.
 * @param array|string $args        {
 *     Optional. Array or query string of arguments for registering a taxonomy.
 *
 *     @type array         $labels                An array of labels for this taxonomy. By default, Tag labels are
 *                                                used for non-hierarchical taxonomies, and Category labels are used
 *                                                for hierarchical taxonomies. See accepted values in
 *                                                get_taxonomy_labels(). Default empty array.
 *     @type string        $description           A short descriptive summary of what the taxonomy is for. Default empty.
 *     @type bool          $public                Whether a taxonomy is intended for use publicly either via
 *                                                the admin interface or by front-end users. The default settings
 *                                                of `$publicly_queryable`, `$show_ui`, and `$show_in_nav_menus`
 *                                                are inherited from `$public`.
 *     @type bool          $publicly_queryable    Whether the taxonomy is publicly queryable.
 *                                                If not set, the default is inherited from `$public`
 *     @type bool          $hierarchical          Whether the taxonomy is hierarchical. Default false.
 *     @type bool          $show_ui               Whether to generate and allow a UI for managing terms in this taxonomy in
 *                                                the admin. If not set, the default is inherited from `$public`
 *                                                (default true).
 *     @type bool          $show_in_menu          Whether to show the taxonomy in the admin menu. If true, the taxonomy is
 *                                                shown as a submenu of the object type menu. If false, no menu is shown.
 *                                                `$show_ui` must be true. If not set, default is inherited from `$show_ui`
 *                                                (default true).
 *     @type bool          $show_in_nav_menus     Makes this taxonomy available for selection in navigation menus. If not
 *                                                set, the default is inherited from `$public` (default true).
 *     @type bool          $show_in_rest          Whether to include the taxonomy in the REST API. Set this to true
 *                                                for the taxonomy to be available in the block editor.
 *     @type string        $rest_base             To change the base url of REST API route. Default is $taxonomy.
 *     @type string        $rest_controller_class REST API Controller class name. Default is 'WP_REST_Terms_Controller'.
 *     @type bool          $show_tagcloud         Whether to list the taxonomy in the Tag Cloud Widget controls. If not set,
 *                                                the default is inherited from `$show_ui` (default true).
 *     @type bool          $show_in_quick_edit    Whether to show the taxonomy in the quick/bulk edit panel. It not set,
 *                                                the default is inherited from `$show_ui` (default true).
 *     @type bool          $show_admin_column     Whether to display a column for the taxonomy on its post type listing
 *                                                screens. Default false.
 *     @type bool|callable $meta_box_cb           Provide a callback function for the meta box display. If not set,
 *                                                post_categories_meta_box() is used for hierarchical taxonomies, and
 *                                                post_tags_meta_box() is used for non-hierarchical. If false, no meta
 *                                                box is shown.
 *     @type callable      $meta_box_sanitize_cb  Callback function for sanitizing taxonomy data saved from a meta
 *                                                box. If no callback is defined, an appropriate one is determined
 *                                                based on the value of `$meta_box_cb`.
 *     @type array         $capabilities {
 *         Array of capabilities for this taxonomy.
 *
 *         @type string $manage_terms Default 'manage_categories'.
 *         @type string $edit_terms   Default 'manage_categories'.
 *         @type string $delete_terms Default 'manage_categories'.
 *         @type string $assign_terms Default 'edit_posts'.
 *     }
 *     @type bool|array    $rewrite {
 *         Triggers the handling of rewrites for this taxonomy. Default true, using $taxonomy as slug. To prevent
 *         rewrite, set to false. To specify rewrite rules, an array can be passed with any of these keys:
 *
 *         @type string $slug         Customize the permastruct slug. Default `$taxonomy` key.
 *         @type bool   $with_front   Should the permastruct be prepended with WP_Rewrite::$front. Default true.
 *         @type bool   $hierarchical Either hierarchical rewrite tag or not. Default false.
 *         @type int    $ep_mask      Assign an endpoint mask. Default `EP_NONE`.
 *     }
 *     @type string|bool   $query_var             Sets the query var key for this taxonomy. Default `$taxonomy` key. If
 *                                                false, a taxonomy cannot be loaded at `?{query_var}={term_slug}`. If a
 *                                                string, the query `?{query_var}={term_slug}` will be valid.
 *     @type callable      $update_count_callback Works much like a hook, in that it will be called when the count is
 *                                                updated. Default _update_post_term_count() for taxonomies attached
 *                                                to post types, which confirms that the objects are published before
 *                                                counting them. Default _update_generic_term_count() for taxonomies
 *                                                attached to other object types, such as users.
 *     @type bool          $_builtin              This taxonomy is a "built-in" taxonomy. INTERNAL USE ONLY!
 *                                                Default false.
 * }
 * @return WP_Error|void WP_Error, if errors.
 */
function register_taxonomy($taxonomy, $object_type, $args = array())
{
    global $wp_taxonomies;
    if (!is_array($wp_taxonomies)) {
        $wp_taxonomies = array();
    }
    $args = wp_parse_args($args);
    if (empty($taxonomy) || strlen($taxonomy) > 32) {
        _doing_it_wrong(__FUNCTION__, __('Taxonomy names must be between 1 and 32 characters in length.'), '4.2.0');
        return new WP_Error('taxonomy_length_invalid', __('Taxonomy names must be between 1 and 32 characters in length.'));
    }
    $taxonomy_object = new WP_Taxonomy($taxonomy, $object_type, $args);
    $taxonomy_object->add_rewrite_rules();
    $wp_taxonomies[$taxonomy] = $taxonomy_object;
    $taxonomy_object->add_hooks();
    /**
     * Fires after a taxonomy is registered.
     *
     * @since 3.3.0
     *
     * @param string       $taxonomy    Taxonomy slug.
     * @param array|string $object_type Object type or array of object types.
     * @param array        $args        Array of taxonomy registration arguments.
     */
    do_action('registered_taxonomy', $taxonomy, $object_type, (array) $taxonomy_object);
}

WordPress Version: 5.1

/**
 * Creates or modifies a taxonomy object.
 *
 * Note: Do not use before the {@see 'init'} hook.
 *
 * A simple function for creating or modifying a taxonomy object based on
 * the parameters given. If modifying an existing taxonomy object, note
 * that the `$object_type` value from the original registration will be
 * overwritten.
 *
 * @since 2.3.0
 * @since 4.2.0 Introduced `show_in_quick_edit` argument.
 * @since 4.4.0 The `show_ui` argument is now enforced on the term editing screen.
 * @since 4.4.0 The `public` argument now controls whether the taxonomy can be queried on the front end.
 * @since 4.5.0 Introduced `publicly_queryable` argument.
 * @since 4.7.0 Introduced `show_in_rest`, 'rest_base' and 'rest_controller_class'
 *              arguments to register the Taxonomy in REST API.
 * @since 5.1.0 Introduced `meta_box_sanitize_cb` argument.
 *
 * @global array $wp_taxonomies Registered taxonomies.
 *
 * @param string       $taxonomy    Taxonomy key, must not exceed 32 characters.
 * @param array|string $object_type Object type or array of object types with which the taxonomy should be associated.
 * @param array|string $args        {
 *     Optional. Array or query string of arguments for registering a taxonomy.
 *
 *     @type array         $labels                An array of labels for this taxonomy. By default, Tag labels are
 *                                                used for non-hierarchical taxonomies, and Category labels are used
 *                                                for hierarchical taxonomies. See accepted values in
 *                                                get_taxonomy_labels(). Default empty array.
 *     @type string        $description           A short descriptive summary of what the taxonomy is for. Default empty.
 *     @type bool          $public                Whether a taxonomy is intended for use publicly either via
 *                                                the admin interface or by front-end users. The default settings
 *                                                of `$publicly_queryable`, `$show_ui`, and `$show_in_nav_menus`
 *                                                are inherited from `$public`.
 *     @type bool          $publicly_queryable    Whether the taxonomy is publicly queryable.
 *                                                If not set, the default is inherited from `$public`
 *     @type bool          $hierarchical          Whether the taxonomy is hierarchical. Default false.
 *     @type bool          $show_ui               Whether to generate and allow a UI for managing terms in this taxonomy in
 *                                                the admin. If not set, the default is inherited from `$public`
 *                                                (default true).
 *     @type bool          $show_in_menu          Whether to show the taxonomy in the admin menu. If true, the taxonomy is
 *                                                shown as a submenu of the object type menu. If false, no menu is shown.
 *                                                `$show_ui` must be true. If not set, default is inherited from `$show_ui`
 *                                                (default true).
 *     @type bool          $show_in_nav_menus     Makes this taxonomy available for selection in navigation menus. If not
 *                                                set, the default is inherited from `$public` (default true).
 *     @type bool          $show_in_rest          Whether to include the taxonomy in the REST API.
 *     @type string        $rest_base             To change the base url of REST API route. Default is $taxonomy.
 *     @type string        $rest_controller_class REST API Controller class name. Default is 'WP_REST_Terms_Controller'.
 *     @type bool          $show_tagcloud         Whether to list the taxonomy in the Tag Cloud Widget controls. If not set,
 *                                                the default is inherited from `$show_ui` (default true).
 *     @type bool          $show_in_quick_edit    Whether to show the taxonomy in the quick/bulk edit panel. It not set,
 *                                                the default is inherited from `$show_ui` (default true).
 *     @type bool          $show_admin_column     Whether to display a column for the taxonomy on its post type listing
 *                                                screens. Default false.
 *     @type bool|callable $meta_box_cb           Provide a callback function for the meta box display. If not set,
 *                                                post_categories_meta_box() is used for hierarchical taxonomies, and
 *                                                post_tags_meta_box() is used for non-hierarchical. If false, no meta
 *                                                box is shown.
 *     @type callable      $meta_box_sanitize_cb  Callback function for sanitizing taxonomy data saved from a meta
 *                                                box. If no callback is defined, an appropriate one is determined
 *                                                based on the value of `$meta_box_cb`.
 *     @type array         $capabilities {
 *         Array of capabilities for this taxonomy.
 *
 *         @type string $manage_terms Default 'manage_categories'.
 *         @type string $edit_terms   Default 'manage_categories'.
 *         @type string $delete_terms Default 'manage_categories'.
 *         @type string $assign_terms Default 'edit_posts'.
 *     }
 *     @type bool|array    $rewrite {
 *         Triggers the handling of rewrites for this taxonomy. Default true, using $taxonomy as slug. To prevent
 *         rewrite, set to false. To specify rewrite rules, an array can be passed with any of these keys:
 *
 *         @type string $slug         Customize the permastruct slug. Default `$taxonomy` key.
 *         @type bool   $with_front   Should the permastruct be prepended with WP_Rewrite::$front. Default true.
 *         @type bool   $hierarchical Either hierarchical rewrite tag or not. Default false.
 *         @type int    $ep_mask      Assign an endpoint mask. Default `EP_NONE`.
 *     }
 *     @type string        $query_var             Sets the query var key for this taxonomy. Default `$taxonomy` key. If
 *                                                false, a taxonomy cannot be loaded at `?{query_var}={term_slug}`. If a
 *                                                string, the query `?{query_var}={term_slug}` will be valid.
 *     @type callable      $update_count_callback Works much like a hook, in that it will be called when the count is
 *                                                updated. Default _update_post_term_count() for taxonomies attached
 *                                                to post types, which confirms that the objects are published before
 *                                                counting them. Default _update_generic_term_count() for taxonomies
 *                                                attached to other object types, such as users.
 *     @type bool          $_builtin              This taxonomy is a "built-in" taxonomy. INTERNAL USE ONLY!
 *                                                Default false.
 * }
 * @return WP_Error|void WP_Error, if errors.
 */
function register_taxonomy($taxonomy, $object_type, $args = array())
{
    global $wp_taxonomies;
    if (!is_array($wp_taxonomies)) {
        $wp_taxonomies = array();
    }
    $args = wp_parse_args($args);
    if (empty($taxonomy) || strlen($taxonomy) > 32) {
        _doing_it_wrong(__FUNCTION__, __('Taxonomy names must be between 1 and 32 characters in length.'), '4.2.0');
        return new WP_Error('taxonomy_length_invalid', __('Taxonomy names must be between 1 and 32 characters in length.'));
    }
    $taxonomy_object = new WP_Taxonomy($taxonomy, $object_type, $args);
    $taxonomy_object->add_rewrite_rules();
    $wp_taxonomies[$taxonomy] = $taxonomy_object;
    $taxonomy_object->add_hooks();
    /**
     * Fires after a taxonomy is registered.
     *
     * @since 3.3.0
     *
     * @param string       $taxonomy    Taxonomy slug.
     * @param array|string $object_type Object type or array of object types.
     * @param array        $args        Array of taxonomy registration arguments.
     */
    do_action('registered_taxonomy', $taxonomy, $object_type, (array) $taxonomy_object);
}

WordPress Version: 4.9

/**
 * Creates or modifies a taxonomy object.
 *
 * Note: Do not use before the {@see 'init'} hook.
 *
 * A simple function for creating or modifying a taxonomy object based on
 * the parameters given. If modifying an existing taxonomy object, note
 * that the `$object_type` value from the original registration will be
 * overwritten.
 *
 * @since 2.3.0
 * @since 4.2.0 Introduced `show_in_quick_edit` argument.
 * @since 4.4.0 The `show_ui` argument is now enforced on the term editing screen.
 * @since 4.4.0 The `public` argument now controls whether the taxonomy can be queried on the front end.
 * @since 4.5.0 Introduced `publicly_queryable` argument.
 * @since 4.7.0 Introduced `show_in_rest`, 'rest_base' and 'rest_controller_class'
 *              arguments to register the Taxonomy in REST API.
 *
 * @global array $wp_taxonomies Registered taxonomies.
 *
 * @param string       $taxonomy    Taxonomy key, must not exceed 32 characters.
 * @param array|string $object_type Object type or array of object types with which the taxonomy should be associated.
 * @param array|string $args        {
 *     Optional. Array or query string of arguments for registering a taxonomy.
 *
 *     @type array         $labels                An array of labels for this taxonomy. By default, Tag labels are
 *                                                used for non-hierarchical taxonomies, and Category labels are used
 *                                                for hierarchical taxonomies. See accepted values in
 *                                                get_taxonomy_labels(). Default empty array.
 *     @type string        $description           A short descriptive summary of what the taxonomy is for. Default empty.
 *     @type bool          $public                Whether a taxonomy is intended for use publicly either via
 *                                                the admin interface or by front-end users. The default settings
 *                                                of `$publicly_queryable`, `$show_ui`, and `$show_in_nav_menus`
 *                                                are inherited from `$public`.
 *     @type bool          $publicly_queryable    Whether the taxonomy is publicly queryable.
 *                                                If not set, the default is inherited from `$public`
 *     @type bool          $hierarchical          Whether the taxonomy is hierarchical. Default false.
 *     @type bool          $show_ui               Whether to generate and allow a UI for managing terms in this taxonomy in
 *                                                the admin. If not set, the default is inherited from `$public`
 *                                                (default true).
 *     @type bool          $show_in_menu          Whether to show the taxonomy in the admin menu. If true, the taxonomy is
 *                                                shown as a submenu of the object type menu. If false, no menu is shown.
 *                                                `$show_ui` must be true. If not set, default is inherited from `$show_ui`
 *                                                (default true).
 *     @type bool          $show_in_nav_menus     Makes this taxonomy available for selection in navigation menus. If not
 *                                                set, the default is inherited from `$public` (default true).
 *     @type bool          $show_in_rest          Whether to include the taxonomy in the REST API.
 *     @type string        $rest_base             To change the base url of REST API route. Default is $taxonomy.
 *     @type string        $rest_controller_class REST API Controller class name. Default is 'WP_REST_Terms_Controller'.
 *     @type bool          $show_tagcloud         Whether to list the taxonomy in the Tag Cloud Widget controls. If not set,
 *                                                the default is inherited from `$show_ui` (default true).
 *     @type bool          $show_in_quick_edit    Whether to show the taxonomy in the quick/bulk edit panel. It not set,
 *                                                the default is inherited from `$show_ui` (default true).
 *     @type bool          $show_admin_column     Whether to display a column for the taxonomy on its post type listing
 *                                                screens. Default false.
 *     @type bool|callable $meta_box_cb           Provide a callback function for the meta box display. If not set,
 *                                                post_categories_meta_box() is used for hierarchical taxonomies, and
 *                                                post_tags_meta_box() is used for non-hierarchical. If false, no meta
 *                                                box is shown.
 *     @type array         $capabilities {
 *         Array of capabilities for this taxonomy.
 *
 *         @type string $manage_terms Default 'manage_categories'.
 *         @type string $edit_terms   Default 'manage_categories'.
 *         @type string $delete_terms Default 'manage_categories'.
 *         @type string $assign_terms Default 'edit_posts'.
 *     }
 *     @type bool|array    $rewrite {
 *         Triggers the handling of rewrites for this taxonomy. Default true, using $taxonomy as slug. To prevent
 *         rewrite, set to false. To specify rewrite rules, an array can be passed with any of these keys:
 *
 *         @type string $slug         Customize the permastruct slug. Default `$taxonomy` key.
 *         @type bool   $with_front   Should the permastruct be prepended with WP_Rewrite::$front. Default true.
 *         @type bool   $hierarchical Either hierarchical rewrite tag or not. Default false.
 *         @type int    $ep_mask      Assign an endpoint mask. Default `EP_NONE`.
 *     }
 *     @type string        $query_var             Sets the query var key for this taxonomy. Default `$taxonomy` key. If
 *                                                false, a taxonomy cannot be loaded at `?{query_var}={term_slug}`. If a
 *                                                string, the query `?{query_var}={term_slug}` will be valid.
 *     @type callable      $update_count_callback Works much like a hook, in that it will be called when the count is
 *                                                updated. Default _update_post_term_count() for taxonomies attached
 *                                                to post types, which confirms that the objects are published before
 *                                                counting them. Default _update_generic_term_count() for taxonomies
 *                                                attached to other object types, such as users.
 *     @type bool          $_builtin              This taxonomy is a "built-in" taxonomy. INTERNAL USE ONLY!
 *                                                Default false.
 * }
 * @return WP_Error|void WP_Error, if errors.
 */
function register_taxonomy($taxonomy, $object_type, $args = array())
{
    global $wp_taxonomies;
    if (!is_array($wp_taxonomies)) {
        $wp_taxonomies = array();
    }
    $args = wp_parse_args($args);
    if (empty($taxonomy) || strlen($taxonomy) > 32) {
        _doing_it_wrong(__FUNCTION__, __('Taxonomy names must be between 1 and 32 characters in length.'), '4.2.0');
        return new WP_Error('taxonomy_length_invalid', __('Taxonomy names must be between 1 and 32 characters in length.'));
    }
    $taxonomy_object = new WP_Taxonomy($taxonomy, $object_type, $args);
    $taxonomy_object->add_rewrite_rules();
    $wp_taxonomies[$taxonomy] = $taxonomy_object;
    $taxonomy_object->add_hooks();
    /**
     * Fires after a taxonomy is registered.
     *
     * @since 3.3.0
     *
     * @param string       $taxonomy    Taxonomy slug.
     * @param array|string $object_type Object type or array of object types.
     * @param array        $args        Array of taxonomy registration arguments.
     */
    do_action('registered_taxonomy', $taxonomy, $object_type, (array) $taxonomy_object);
}

WordPress Version: 4.7

/**
 * Creates or modifies a taxonomy object.
 *
 * Note: Do not use before the {@see 'init'} hook.
 *
 * A simple function for creating or modifying a taxonomy object based on the
 * parameters given. The function will accept an array (third optional
 * parameter), along with strings for the taxonomy name and another string for
 * the object type.
 *
 * @since 2.3.0
 * @since 4.2.0 Introduced `show_in_quick_edit` argument.
 * @since 4.4.0 The `show_ui` argument is now enforced on the term editing screen.
 * @since 4.4.0 The `public` argument now controls whether the taxonomy can be queried on the front end.
 * @since 4.5.0 Introduced `publicly_queryable` argument.
 * @since 4.7.0 Introduced `show_in_rest`, 'rest_base' and 'rest_controller_class'
 *              arguments to register the Taxonomy in REST API.
 *
 * @global array $wp_taxonomies Registered taxonomies.
 *
 * @param string       $taxonomy    Taxonomy key, must not exceed 32 characters.
 * @param array|string $object_type Object type or array of object types with which the taxonomy should be associated.
 * @param array|string $args        {
 *     Optional. Array or query string of arguments for registering a taxonomy.
 *
 *     @type array         $labels                An array of labels for this taxonomy. By default, Tag labels are
 *                                                used for non-hierarchical taxonomies, and Category labels are used
 *                                                for hierarchical taxonomies. See accepted values in
 *                                                get_taxonomy_labels(). Default empty array.
 *     @type string        $description           A short descriptive summary of what the taxonomy is for. Default empty.
 *     @type bool          $public                Whether a taxonomy is intended for use publicly either via
 *                                                the admin interface or by front-end users. The default settings
 *                                                of `$publicly_queryable`, `$show_ui`, and `$show_in_nav_menus`
 *                                                are inherited from `$public`.
 *     @type bool          $publicly_queryable    Whether the taxonomy is publicly queryable.
 *                                                If not set, the default is inherited from `$public`
 *     @type bool          $hierarchical          Whether the taxonomy is hierarchical. Default false.
 *     @type bool          $show_ui               Whether to generate and allow a UI for managing terms in this taxonomy in
 *                                                the admin. If not set, the default is inherited from `$public`
 *                                                (default true).
 *     @type bool          $show_in_menu          Whether to show the taxonomy in the admin menu. If true, the taxonomy is
 *                                                shown as a submenu of the object type menu. If false, no menu is shown.
 *                                                `$show_ui` must be true. If not set, default is inherited from `$show_ui`
 *                                                (default true).
 *     @type bool          $show_in_nav_menus     Makes this taxonomy available for selection in navigation menus. If not
 *                                                set, the default is inherited from `$public` (default true).
 *     @type bool          $show_in_rest          Whether to include the taxonomy in the REST API.
 *     @type string        $rest_base             To change the base url of REST API route. Default is $taxonomy.
 *     @type string        $rest_controller_class REST API Controller class name. Default is 'WP_REST_Terms_Controller'.
 *     @type bool          $show_tagcloud         Whether to list the taxonomy in the Tag Cloud Widget controls. If not set,
 *                                                the default is inherited from `$show_ui` (default true).
 *     @type bool          $show_in_quick_edit    Whether to show the taxonomy in the quick/bulk edit panel. It not set,
 *                                                the default is inherited from `$show_ui` (default true).
 *     @type bool          $show_admin_column     Whether to display a column for the taxonomy on its post type listing
 *                                                screens. Default false.
 *     @type bool|callable $meta_box_cb           Provide a callback function for the meta box display. If not set,
 *                                                post_categories_meta_box() is used for hierarchical taxonomies, and
 *                                                post_tags_meta_box() is used for non-hierarchical. If false, no meta
 *                                                box is shown.
 *     @type array         $capabilities {
 *         Array of capabilities for this taxonomy.
 *
 *         @type string $manage_terms Default 'manage_categories'.
 *         @type string $edit_terms   Default 'manage_categories'.
 *         @type string $delete_terms Default 'manage_categories'.
 *         @type string $assign_terms Default 'edit_posts'.
 *     }
 *     @type bool|array    $rewrite {
 *         Triggers the handling of rewrites for this taxonomy. Default true, using $taxonomy as slug. To prevent
 *         rewrite, set to false. To specify rewrite rules, an array can be passed with any of these keys:
 *
 *         @type string $slug         Customize the permastruct slug. Default `$taxonomy` key.
 *         @type bool   $with_front   Should the permastruct be prepended with WP_Rewrite::$front. Default true.
 *         @type bool   $hierarchical Either hierarchical rewrite tag or not. Default false.
 *         @type int    $ep_mask      Assign an endpoint mask. Default `EP_NONE`.
 *     }
 *     @type string        $query_var             Sets the query var key for this taxonomy. Default `$taxonomy` key. If
 *                                                false, a taxonomy cannot be loaded at `?{query_var}={term_slug}`. If a
 *                                                string, the query `?{query_var}={term_slug}` will be valid.
 *     @type callable      $update_count_callback Works much like a hook, in that it will be called when the count is
 *                                                updated. Default _update_post_term_count() for taxonomies attached
 *                                                to post types, which confirms that the objects are published before
 *                                                counting them. Default _update_generic_term_count() for taxonomies
 *                                                attached to other object types, such as users.
 *     @type bool          $_builtin              This taxonomy is a "built-in" taxonomy. INTERNAL USE ONLY!
 *                                                Default false.
 * }
 * @return WP_Error|void WP_Error, if errors.
 */
function register_taxonomy($taxonomy, $object_type, $args = array())
{
    global $wp_taxonomies;
    if (!is_array($wp_taxonomies)) {
        $wp_taxonomies = array();
    }
    $args = wp_parse_args($args);
    if (empty($taxonomy) || strlen($taxonomy) > 32) {
        _doing_it_wrong(__FUNCTION__, __('Taxonomy names must be between 1 and 32 characters in length.'), '4.2.0');
        return new WP_Error('taxonomy_length_invalid', __('Taxonomy names must be between 1 and 32 characters in length.'));
    }
    $taxonomy_object = new WP_Taxonomy($taxonomy, $object_type, $args);
    $taxonomy_object->add_rewrite_rules();
    $wp_taxonomies[$taxonomy] = $taxonomy_object;
    $taxonomy_object->add_hooks();
    /**
     * Fires after a taxonomy is registered.
     *
     * @since 3.3.0
     *
     * @param string       $taxonomy    Taxonomy slug.
     * @param array|string $object_type Object type or array of object types.
     * @param array        $args        Array of taxonomy registration arguments.
     */
    do_action('registered_taxonomy', $taxonomy, $object_type, (array) $taxonomy_object);
}

WordPress Version: 4.6

/**
 * Creates or modifies a taxonomy object.
 *
 * Note: Do not use before the {@see 'init'} hook.
 *
 * A simple function for creating or modifying a taxonomy object based on the
 * parameters given. The function will accept an array (third optional
 * parameter), along with strings for the taxonomy name and another string for
 * the object type.
 *
 * @since 2.3.0
 * @since 4.2.0 Introduced `show_in_quick_edit` argument.
 * @since 4.4.0 The `show_ui` argument is now enforced on the term editing screen.
 * @since 4.4.0 The `public` argument now controls whether the taxonomy can be queried on the front end.
 * @since 4.5.0 Introduced `publicly_queryable` argument.
 *
 * @global array $wp_taxonomies Registered taxonomies.
 * @global WP    $wp            WP instance.
 *
 * @param string       $taxonomy    Taxonomy key, must not exceed 32 characters.
 * @param array|string $object_type Name of the object type for the taxonomy object.
 * @param array|string $args        {
 *     Optional. Array or query string of arguments for registering a taxonomy.
 *
 *     @type string        $label                 Name of the taxonomy shown in the menu. Usually plural. If not set,
 *                                                `$labels['name']` will be used.
 *     @type array         $labels                An array of labels for this taxonomy. By default, Tag labels are used for
 *                                                non-hierarchical taxonmies, and Category labels are used for hierarchical
 *                                                taxonomies. See accepted values in get_taxonomy_labels().
 *                                                Default empty array.
 *     @type string        $description           A short descriptive summary of what the taxonomy is for. Default empty.
 *     @type bool          $public                Whether a taxonomy is intended for use publicly either via
 *                                                the admin interface or by front-end users. The default settings
 *                                                of `$publicly_queryable`, `$show_ui`, and `$show_in_nav_menus`
 *                                                are inherited from `$public`.
 *     @type bool          $publicly_queryable    Whether the taxonomy is publicly queryable.
 *                                                If not set, the default is inherited from `$public`
 *     @type bool          $hierarchical          Whether the taxonomy is hierarchical. Default false.
 *     @type bool          $show_ui               Whether to generate and allow a UI for managing terms in this taxonomy in
 *                                                the admin. If not set, the default is inherited from `$public`
 *                                                (default true).
 *     @type bool          $show_in_menu          Whether to show the taxonomy in the admin menu. If true, the taxonomy is
 *                                                shown as a submenu of the object type menu. If false, no menu is shown.
 *                                                `$show_ui` must be true. If not set, default is inherited from `$show_ui`
 *                                                (default true).
 *     @type bool          $show_in_nav_menus     Makes this taxonomy available for selection in navigation menus. If not
 *                                                set, the default is inherited from `$public` (default true).
 *     @type bool          $show_tagcloud         Whether to list the taxonomy in the Tag Cloud Widget controls. If not set,
 *                                                the default is inherited from `$show_ui` (default true).
 *     @type bool          $show_in_quick_edit    Whether to show the taxonomy in the quick/bulk edit panel. It not set,
 *                                                the default is inherited from `$show_ui` (default true).
 *     @type bool          $show_admin_column     Whether to display a column for the taxonomy on its post type listing
 *                                                screens. Default false.
 *     @type bool|callable $meta_box_cb           Provide a callback function for the meta box display. If not set,
 *                                                post_categories_meta_box() is used for hierarchical taxonomies, and
 *                                                post_tags_meta_box() is used for non-hierarchical. If false, no meta
 *                                                box is shown.
 *     @type array         $capabilities {
 *         Array of capabilities for this taxonomy.
 *
 *         @type string $manage_terms Default 'manage_categories'.
 *         @type string $edit_terms   Default 'manage_categories'.
 *         @type string $delete_terms Default 'manage_categories'.
 *         @type string $assign_terms Default 'edit_posts'.
 *     }
 *     @type bool|array    $rewrite {
 *         Triggers the handling of rewrites for this taxonomy. Default true, using $taxonomy as slug. To prevent
 *         rewrite, set to false. To specify rewrite rules, an array can be passed with any of these keys:
 *
 *         @type string $slug         Customize the permastruct slug. Default `$taxonomy` key.
 *         @type bool   $with_front   Should the permastruct be prepended with WP_Rewrite::$front. Default true.
 *         @type bool   $hierarchical Either hierarchical rewrite tag or not. Default false.
 *         @type int    $ep_mask      Assign an endpoint mask. Default `EP_NONE`.
 *     }
 *     @type string        $query_var             Sets the query var key for this taxonomy. Default `$taxonomy` key. If
 *                                                false, a taxonomy cannot be loaded at `?{query_var}={term_slug}`. If a
 *                                                string, the query `?{query_var}={term_slug}` will be valid.
 *     @type callable      $update_count_callback Works much like a hook, in that it will be called when the count is
 *                                                updated. Default _update_post_term_count() for taxonomies attached
 *                                                to post types, which confirms that the objects are published before
 *                                                counting them. Default _update_generic_term_count() for taxonomies
 *                                                attached to other object types, such as users.
 *     @type bool          $_builtin              This taxonomy is a "built-in" taxonomy. INTERNAL USE ONLY!
 *                                                Default false.
 * }
 * @return WP_Error|void WP_Error, if errors.
 */
function register_taxonomy($taxonomy, $object_type, $args = array())
{
    global $wp_taxonomies, $wp;
    if (!is_array($wp_taxonomies)) {
        $wp_taxonomies = array();
    }
    $args = wp_parse_args($args);
    /**
     * Filters the arguments for registering a taxonomy.
     *
     * @since 4.4.0
     *
     * @param array  $args        Array of arguments for registering a taxonomy.
     * @param string $taxonomy    Taxonomy key.
     * @param array  $object_type Array of names of object types for the taxonomy.
     */
    $args = apply_filters('register_taxonomy_args', $args, $taxonomy, (array) $object_type);
    $defaults = array('labels' => array(), 'description' => '', 'public' => true, 'publicly_queryable' => null, 'hierarchical' => false, 'show_ui' => null, 'show_in_menu' => null, 'show_in_nav_menus' => null, 'show_tagcloud' => null, 'show_in_quick_edit' => null, 'show_admin_column' => false, 'meta_box_cb' => null, 'capabilities' => array(), 'rewrite' => true, 'query_var' => $taxonomy, 'update_count_callback' => '', '_builtin' => false);
    $args = array_merge($defaults, $args);
    if (empty($taxonomy) || strlen($taxonomy) > 32) {
        _doing_it_wrong(__FUNCTION__, __('Taxonomy names must be between 1 and 32 characters in length.'), '4.2.0');
        return new WP_Error('taxonomy_length_invalid', __('Taxonomy names must be between 1 and 32 characters in length.'));
    }
    // If not set, default to the setting for public.
    if (null === $args['publicly_queryable']) {
        $args['publicly_queryable'] = $args['public'];
    }
    // Non-publicly queryable taxonomies should not register query vars, except in the admin.
    if (false !== $args['query_var'] && (is_admin() || false !== $args['publicly_queryable']) && !empty($wp)) {
        if (true === $args['query_var']) {
            $args['query_var'] = $taxonomy;
        } else {
            $args['query_var'] = sanitize_title_with_dashes($args['query_var']);
        }
        $wp->add_query_var($args['query_var']);
    } else {
        // Force query_var to false for non-public taxonomies.
        $args['query_var'] = false;
    }
    if (false !== $args['rewrite'] && (is_admin() || '' != get_option('permalink_structure'))) {
        $args['rewrite'] = wp_parse_args($args['rewrite'], array('with_front' => true, 'hierarchical' => false, 'ep_mask' => EP_NONE));
        if (empty($args['rewrite']['slug'])) {
            $args['rewrite']['slug'] = sanitize_title_with_dashes($taxonomy);
        }
        if ($args['hierarchical'] && $args['rewrite']['hierarchical']) {
            $tag = '(.+?)';
        } else {
            $tag = '([^/]+)';
        }
        add_rewrite_tag("%{$taxonomy}%", $tag, $args['query_var'] ? "{$args['query_var']}=" : "taxonomy={$taxonomy}&term=");
        add_permastruct($taxonomy, "{$args['rewrite']['slug']}/%{$taxonomy}%", $args['rewrite']);
    }
    // If not set, default to the setting for public.
    if (null === $args['show_ui']) {
        $args['show_ui'] = $args['public'];
    }
    // If not set, default to the setting for show_ui.
    if (null === $args['show_in_menu'] || !$args['show_ui']) {
        $args['show_in_menu'] = $args['show_ui'];
    }
    // If not set, default to the setting for public.
    if (null === $args['show_in_nav_menus']) {
        $args['show_in_nav_menus'] = $args['public'];
    }
    // If not set, default to the setting for show_ui.
    if (null === $args['show_tagcloud']) {
        $args['show_tagcloud'] = $args['show_ui'];
    }
    // If not set, default to the setting for show_ui.
    if (null === $args['show_in_quick_edit']) {
        $args['show_in_quick_edit'] = $args['show_ui'];
    }
    $default_caps = array('manage_terms' => 'manage_categories', 'edit_terms' => 'manage_categories', 'delete_terms' => 'manage_categories', 'assign_terms' => 'edit_posts');
    $args['cap'] = (object) array_merge($default_caps, $args['capabilities']);
    unset($args['capabilities']);
    $args['name'] = $taxonomy;
    $args['object_type'] = array_unique((array) $object_type);
    $args['labels'] = get_taxonomy_labels((object) $args);
    $args['label'] = $args['labels']->name;
    // If not set, use the default meta box
    if (null === $args['meta_box_cb']) {
        if ($args['hierarchical']) {
            $args['meta_box_cb'] = 'post_categories_meta_box';
        } else {
            $args['meta_box_cb'] = 'post_tags_meta_box';
        }
    }
    $wp_taxonomies[$taxonomy] = (object) $args;
    // Register callback handling for meta box.
    add_filter('wp_ajax_add-' . $taxonomy, '_wp_ajax_add_hierarchical_term');
    /**
     * Fires after a taxonomy is registered.
     *
     * @since 3.3.0
     *
     * @param string       $taxonomy    Taxonomy slug.
     * @param array|string $object_type Object type or array of object types.
     * @param array        $args        Array of taxonomy registration arguments.
     */
    do_action('registered_taxonomy', $taxonomy, $object_type, $args);
}

WordPress Version: 4.5

/**
 * Creates or modifies a taxonomy object.
 *
 * Note: Do not use before the {@see 'init'} hook.
 *
 * A simple function for creating or modifying a taxonomy object based on the
 * parameters given. The function will accept an array (third optional
 * parameter), along with strings for the taxonomy name and another string for
 * the object type.
 *
 * @since 2.3.0
 * @since 4.2.0 Introduced `show_in_quick_edit` argument.
 * @since 4.4.0 The `show_ui` argument is now enforced on the term editing screen.
 * @since 4.4.0 The `public` argument now controls whether the taxonomy can be queried on the front end.
 * @since 4.5.0 Introduced `publicly_queryable` argument.
 *
 * @global array $wp_taxonomies Registered taxonomies.
 * @global WP    $wp            WP instance.
 *
 * @param string       $taxonomy    Taxonomy key, must not exceed 32 characters.
 * @param array|string $object_type Name of the object type for the taxonomy object.
 * @param array|string $args        {
 *     Optional. Array or query string of arguments for registering a taxonomy.
 *
 *     @type string        $label                 Name of the taxonomy shown in the menu. Usually plural. If not set,
 *                                                `$labels['name']` will be used.
 *     @type array         $labels                An array of labels for this taxonomy. By default, Tag labels are used for
 *                                                non-hierarchical taxonmies, and Category labels are used for hierarchical
 *                                                taxonomies. See accepted values in get_taxonomy_labels().
 *                                                Default empty array.
 *     @type string        $description           A short descriptive summary of what the taxonomy is for. Default empty.
 *     @type bool          $public                Whether a taxonomy is intended for use publicly either via
 *                                                the admin interface or by front-end users. The default settings
 *                                                of `$publicly_queryable`, `$show_ui`, and `$show_in_nav_menus`
 *                                                are inherited from `$public`.
 *     @type bool          $publicly_queryable    Whether the taxonomy is publicly queryable.
 *                                                If not set, the default is inherited from `$public`
 *     @type bool          $hierarchical          Whether the taxonomy is hierarchical. Default false.
 *     @type bool          $show_ui               Whether to generate and allow a UI for managing terms in this taxonomy in
 *                                                the admin. If not set, the default is inherited from `$public`
 *                                                (default true).
 *     @type bool          $show_in_menu          Whether to show the taxonomy in the admin menu. If true, the taxonomy is
 *                                                shown as a submenu of the object type menu. If false, no menu is shown.
 *                                                `$show_ui` must be true. If not set, default is inherited from `$show_ui`
 *                                                (default true).
 *     @type bool          $show_in_nav_menus     Makes this taxonomy available for selection in navigation menus. If not
 *                                                set, the default is inherited from `$public` (default true).
 *     @type bool          $show_tagcloud         Whether to list the taxonomy in the Tag Cloud Widget controls. If not set,
 *                                                the default is inherited from `$show_ui` (default true).
 *     @type bool          $show_in_quick_edit    Whether to show the taxonomy in the quick/bulk edit panel. It not set,
 *                                                the default is inherited from `$show_ui` (default true).
 *     @type bool          $show_admin_column     Whether to display a column for the taxonomy on its post type listing
 *                                                screens. Default false.
 *     @type bool|callable $meta_box_cb           Provide a callback function for the meta box display. If not set,
 *                                                post_categories_meta_box() is used for hierarchical taxonomies, and
 *                                                post_tags_meta_box() is used for non-hierarchical. If false, no meta
 *                                                box is shown.
 *     @type array         $capabilities {
 *         Array of capabilities for this taxonomy.
 *
 *         @type string $manage_terms Default 'manage_categories'.
 *         @type string $edit_terms   Default 'manage_categories'.
 *         @type string $delete_terms Default 'manage_categories'.
 *         @type string $assign_terms Default 'edit_posts'.
 *     }
 *     @type bool|array    $rewrite {
 *         Triggers the handling of rewrites for this taxonomy. Default true, using $taxonomy as slug. To prevent
 *         rewrite, set to false. To specify rewrite rules, an array can be passed with any of these keys:
 *
 *         @type string $slug         Customize the permastruct slug. Default `$taxonomy` key.
 *         @type bool   $with_front   Should the permastruct be prepended with WP_Rewrite::$front. Default true.
 *         @type bool   $hierarchical Either hierarchical rewrite tag or not. Default false.
 *         @type int    $ep_mask      Assign an endpoint mask. Default `EP_NONE`.
 *     }
 *     @type string        $query_var             Sets the query var key for this taxonomy. Default `$taxonomy` key. If
 *                                                false, a taxonomy cannot be loaded at `?{query_var}={term_slug}`. If a
 *                                                string, the query `?{query_var}={term_slug}` will be valid.
 *     @type callable      $update_count_callback Works much like a hook, in that it will be called when the count is
 *                                                updated. Default _update_post_term_count() for taxonomies attached
 *                                                to post types, which confirms that the objects are published before
 *                                                counting them. Default _update_generic_term_count() for taxonomies
 *                                                attached to other object types, such as users.
 *     @type bool          $_builtin              This taxonomy is a "built-in" taxonomy. INTERNAL USE ONLY!
 *                                                Default false.
 * }
 * @return WP_Error|void WP_Error, if errors.
 */
function register_taxonomy($taxonomy, $object_type, $args = array())
{
    global $wp_taxonomies, $wp;
    if (!is_array($wp_taxonomies)) {
        $wp_taxonomies = array();
    }
    $args = wp_parse_args($args);
    /**
     * Filter the arguments for registering a taxonomy.
     *
     * @since 4.4.0
     *
     * @param array  $args        Array of arguments for registering a taxonomy.
     * @param string $taxonomy    Taxonomy key.
     * @param array  $object_type Array of names of object types for the taxonomy.
     */
    $args = apply_filters('register_taxonomy_args', $args, $taxonomy, (array) $object_type);
    $defaults = array('labels' => array(), 'description' => '', 'public' => true, 'publicly_queryable' => null, 'hierarchical' => false, 'show_ui' => null, 'show_in_menu' => null, 'show_in_nav_menus' => null, 'show_tagcloud' => null, 'show_in_quick_edit' => null, 'show_admin_column' => false, 'meta_box_cb' => null, 'capabilities' => array(), 'rewrite' => true, 'query_var' => $taxonomy, 'update_count_callback' => '', '_builtin' => false);
    $args = array_merge($defaults, $args);
    if (empty($taxonomy) || strlen($taxonomy) > 32) {
        _doing_it_wrong(__FUNCTION__, __('Taxonomy names must be between 1 and 32 characters in length.'), '4.2');
        return new WP_Error('taxonomy_length_invalid', __('Taxonomy names must be between 1 and 32 characters in length.'));
    }
    // If not set, default to the setting for public.
    if (null === $args['publicly_queryable']) {
        $args['publicly_queryable'] = $args['public'];
    }
    // Non-publicly queryable taxonomies should not register query vars, except in the admin.
    if (false !== $args['query_var'] && (is_admin() || false !== $args['publicly_queryable']) && !empty($wp)) {
        if (true === $args['query_var']) {
            $args['query_var'] = $taxonomy;
        } else {
            $args['query_var'] = sanitize_title_with_dashes($args['query_var']);
        }
        $wp->add_query_var($args['query_var']);
    } else {
        // Force query_var to false for non-public taxonomies.
        $args['query_var'] = false;
    }
    if (false !== $args['rewrite'] && (is_admin() || '' != get_option('permalink_structure'))) {
        $args['rewrite'] = wp_parse_args($args['rewrite'], array('with_front' => true, 'hierarchical' => false, 'ep_mask' => EP_NONE));
        if (empty($args['rewrite']['slug'])) {
            $args['rewrite']['slug'] = sanitize_title_with_dashes($taxonomy);
        }
        if ($args['hierarchical'] && $args['rewrite']['hierarchical']) {
            $tag = '(.+?)';
        } else {
            $tag = '([^/]+)';
        }
        add_rewrite_tag("%{$taxonomy}%", $tag, $args['query_var'] ? "{$args['query_var']}=" : "taxonomy={$taxonomy}&term=");
        add_permastruct($taxonomy, "{$args['rewrite']['slug']}/%{$taxonomy}%", $args['rewrite']);
    }
    // If not set, default to the setting for public.
    if (null === $args['show_ui']) {
        $args['show_ui'] = $args['public'];
    }
    // If not set, default to the setting for show_ui.
    if (null === $args['show_in_menu'] || !$args['show_ui']) {
        $args['show_in_menu'] = $args['show_ui'];
    }
    // If not set, default to the setting for public.
    if (null === $args['show_in_nav_menus']) {
        $args['show_in_nav_menus'] = $args['public'];
    }
    // If not set, default to the setting for show_ui.
    if (null === $args['show_tagcloud']) {
        $args['show_tagcloud'] = $args['show_ui'];
    }
    // If not set, default to the setting for show_ui.
    if (null === $args['show_in_quick_edit']) {
        $args['show_in_quick_edit'] = $args['show_ui'];
    }
    $default_caps = array('manage_terms' => 'manage_categories', 'edit_terms' => 'manage_categories', 'delete_terms' => 'manage_categories', 'assign_terms' => 'edit_posts');
    $args['cap'] = (object) array_merge($default_caps, $args['capabilities']);
    unset($args['capabilities']);
    $args['name'] = $taxonomy;
    $args['object_type'] = array_unique((array) $object_type);
    $args['labels'] = get_taxonomy_labels((object) $args);
    $args['label'] = $args['labels']->name;
    // If not set, use the default meta box
    if (null === $args['meta_box_cb']) {
        if ($args['hierarchical']) {
            $args['meta_box_cb'] = 'post_categories_meta_box';
        } else {
            $args['meta_box_cb'] = 'post_tags_meta_box';
        }
    }
    $wp_taxonomies[$taxonomy] = (object) $args;
    // register callback handling for metabox
    add_filter('wp_ajax_add-' . $taxonomy, '_wp_ajax_add_hierarchical_term');
    /**
     * Fires after a taxonomy is registered.
     *
     * @since 3.3.0
     *
     * @param string       $taxonomy    Taxonomy slug.
     * @param array|string $object_type Object type or array of object types.
     * @param array        $args        Array of taxonomy registration arguments.
     */
    do_action('registered_taxonomy', $taxonomy, $object_type, $args);
}

WordPress Version: 4.1

/**
 * Creates or modifies a taxonomy object.
 *
 * Note: Do not use before the {@see 'init'} hook.
 *
 * A simple function for creating or modifying a taxonomy object based on the
 * parameters given. The function will accept an array (third optional
 * parameter), along with strings for the taxonomy name and another string for
 * the object type.
 *
 * @since 2.3.0
 * @since 4.2.0 Introduced `show_in_quick_edit` argument.
 * @since 4.4.0 The `show_ui` argument is now enforced on the term editing screen.
 * @since 4.4.0 The `public` argument now controls whether the taxonomy can be queried on the front-end.
 *
 * @global array $wp_taxonomies Registered taxonomies.
 * @global WP    $wp            WP instance.
 *
 * @param string       $taxonomy    Taxonomy key, must not exceed 32 characters.
 * @param array|string $object_type Name of the object type for the taxonomy object.
 * @param array|string $args        {
 *     Optional. Array or query string of arguments for registering a taxonomy.
 *
 *     @type string        $label                 Name of the taxonomy shown in the menu. Usually plural. If not set,
 *                                                `$labels['name']` will be used.
 *     @type array         $labels                An array of labels for this taxonomy. By default, Tag labels are used for
 *                                                non-hierarchical taxonmies, and Category labels are used for hierarchical
 *                                                taxonomies. See accepted values in get_taxonomy_labels().
 *                                                Default empty array.
 *     @type string        $description           A short descriptive summary of what the taxonomy is for. Default empty.
 *     @type bool          $public                Whether the taxonomy is publicly queryable. Default true.
 *     @type bool          $hierarchical          Whether the taxonomy is hierarchical. Default false.
 *     @type bool          $show_ui               Whether to generate and allow a UI for managing terms in this taxonomy in
 *                                                the admin. If not set, the default is inherited from `$public`
 *                                                (default true).
 *     @type bool          $show_in_menu          Whether to show the taxonomy in the admin menu. If true, the taxonomy is
 *                                                shown as a submenu of the object type menu. If false, no menu is shown.
 *                                                `$show_ui` must be true. If not set, default is inherited from `$show_ui`
 *                                                (default true).
 *     @type bool          $show_in_nav_menus     Makes this taxonomy available for selection in navigation menus. If not
 *                                                set, the default is inherited from `$public` (default true).
 *     @type bool          $show_tagcloud         Whether to list the taxonomy in the Tag Cloud Widget controls. If not set,
 *                                                the default is inherited from `$show_ui` (default true).
 *     @type bool          $show_in_quick_edit    Whether to show the taxonomy in the quick/bulk edit panel. It not set,
 *                                                the default is inherited from `$show_ui` (default true).
 *     @type bool          $show_admin_column     Whether to display a column for the taxonomy on its post type listing
 *                                                screens. Default false.
 *     @type bool|callable $meta_box_cb           Provide a callback function for the meta box display. If not set,
 *                                                post_categories_meta_box() is used for hierarchical taxonomies, and
 *                                                post_tags_meta_box() is used for non-hierarchical. If false, no meta
 *                                                box is shown.
 *     @type array         $capabilities {
 *         Array of capabilities for this taxonomy.
 *
 *         @type string $manage_terms Default 'manage_categories'.
 *         @type string $edit_terms   Default 'manage_categories'.
 *         @type string $delete_terms Default 'manage_categories'.
 *         @type string $assign_terms Default 'edit_posts'.
 *     }
 *     @type bool|array    $rewrite {
 *         Triggers the handling of rewrites for this taxonomy. Default true, using $taxonomy as slug. To prevent
 *         rewrite, set to false. To specify rewrite rules, an array can be passed with any of these keys:
 *
 *         @type string $slug         Customize the permastruct slug. Default `$taxonomy` key.
 *         @type bool   $with_front   Should the permastruct be prepended with WP_Rewrite::$front. Default true.
 *         @type bool   $hierarchical Either hierarchical rewrite tag or not. Default false.
 *         @type int    $ep_mask      Assign an endpoint mask. Default `EP_NONE`.
 *     }
 *     @type string        $query_var             Sets the query var key for this taxonomy. Default `$taxonomy` key. If
 *                                                false, a taxonomy cannot be loaded at `?{query_var}={term_slug}`. If a
 *                                                string, the query `?{query_var}={term_slug}` will be valid.
 *     @type callable      $update_count_callback Works much like a hook, in that it will be called when the count is
 *                                                updated. Default _update_post_term_count() for taxonomies attached
 *                                                to post types, which confirms that the objects are published before
 *                                                counting them. Default _update_generic_term_count() for taxonomies
 *                                                attached to other object types, such as users.
 *     @type bool          $_builtin              This taxonomy is a "built-in" taxonomy. INTERNAL USE ONLY!
 *                                                Default false.
 * }
 * @return WP_Error|void WP_Error, if errors.
 */
function register_taxonomy($taxonomy, $object_type, $args = array())
{
    global $wp_taxonomies, $wp;
    if (!is_array($wp_taxonomies)) {
        $wp_taxonomies = array();
    }
    $args = wp_parse_args($args);
    /**
     * Filter the arguments for registering a taxonomy.
     *
     * @since 4.4.0
     *
     * @param array  $args        Array of arguments for registering a taxonomy.
     * @param array  $object_type Array of names of object types for the taxonomy.
     * @param string $taxonomy    Taxonomy key.
     */
    $args = apply_filters('register_taxonomy_args', $args, $taxonomy, (array) $object_type);
    $defaults = array('labels' => array(), 'description' => '', 'public' => true, 'hierarchical' => false, 'show_ui' => null, 'show_in_menu' => null, 'show_in_nav_menus' => null, 'show_tagcloud' => null, 'show_in_quick_edit' => null, 'show_admin_column' => false, 'meta_box_cb' => null, 'capabilities' => array(), 'rewrite' => true, 'query_var' => $taxonomy, 'update_count_callback' => '', '_builtin' => false);
    $args = array_merge($defaults, $args);
    if (empty($taxonomy) || strlen($taxonomy) > 32) {
        _doing_it_wrong(__FUNCTION__, __('Taxonomy names must be between 1 and 32 characters in length.'), '4.2');
        return new WP_Error('taxonomy_length_invalid', __('Taxonomy names must be between 1 and 32 characters in length.'));
    }
    // Non-public taxonomies should not register query vars, except in the admin.
    if (false !== $args['query_var'] && (is_admin() || false !== $args['public']) && !empty($wp)) {
        if (true === $args['query_var']) {
            $args['query_var'] = $taxonomy;
        } else {
            $args['query_var'] = sanitize_title_with_dashes($args['query_var']);
        }
        $wp->add_query_var($args['query_var']);
    } else {
        // Force query_var to false for non-public taxonomies.
        $args['query_var'] = false;
    }
    if (false !== $args['rewrite'] && (is_admin() || '' != get_option('permalink_structure'))) {
        $args['rewrite'] = wp_parse_args($args['rewrite'], array('with_front' => true, 'hierarchical' => false, 'ep_mask' => EP_NONE));
        if (empty($args['rewrite']['slug'])) {
            $args['rewrite']['slug'] = sanitize_title_with_dashes($taxonomy);
        }
        if ($args['hierarchical'] && $args['rewrite']['hierarchical']) {
            $tag = '(.+?)';
        } else {
            $tag = '([^/]+)';
        }
        add_rewrite_tag("%{$taxonomy}%", $tag, $args['query_var'] ? "{$args['query_var']}=" : "taxonomy={$taxonomy}&term=");
        add_permastruct($taxonomy, "{$args['rewrite']['slug']}/%{$taxonomy}%", $args['rewrite']);
    }
    // If not set, default to the setting for public.
    if (null === $args['show_ui']) {
        $args['show_ui'] = $args['public'];
    }
    // If not set, default to the setting for show_ui.
    if (null === $args['show_in_menu'] || !$args['show_ui']) {
        $args['show_in_menu'] = $args['show_ui'];
    }
    // If not set, default to the setting for public.
    if (null === $args['show_in_nav_menus']) {
        $args['show_in_nav_menus'] = $args['public'];
    }
    // If not set, default to the setting for show_ui.
    if (null === $args['show_tagcloud']) {
        $args['show_tagcloud'] = $args['show_ui'];
    }
    // If not set, default to the setting for show_ui.
    if (null === $args['show_in_quick_edit']) {
        $args['show_in_quick_edit'] = $args['show_ui'];
    }
    $default_caps = array('manage_terms' => 'manage_categories', 'edit_terms' => 'manage_categories', 'delete_terms' => 'manage_categories', 'assign_terms' => 'edit_posts');
    $args['cap'] = (object) array_merge($default_caps, $args['capabilities']);
    unset($args['capabilities']);
    $args['name'] = $taxonomy;
    $args['object_type'] = array_unique((array) $object_type);
    $args['labels'] = get_taxonomy_labels((object) $args);
    $args['label'] = $args['labels']->name;
    // If not set, use the default meta box
    if (null === $args['meta_box_cb']) {
        if ($args['hierarchical']) {
            $args['meta_box_cb'] = 'post_categories_meta_box';
        } else {
            $args['meta_box_cb'] = 'post_tags_meta_box';
        }
    }
    $wp_taxonomies[$taxonomy] = (object) $args;
    // register callback handling for metabox
    add_filter('wp_ajax_add-' . $taxonomy, '_wp_ajax_add_hierarchical_term');
    /**
     * Fires after a taxonomy is registered.
     *
     * @since 3.3.0
     *
     * @param string       $taxonomy    Taxonomy slug.
     * @param array|string $object_type Object type or array of object types.
     * @param array        $args        Array of taxonomy registration arguments.
     */
    do_action('registered_taxonomy', $taxonomy, $object_type, $args);
}

WordPress Version: 4.4

/**
 * Creates or modifies a taxonomy object.
 *
 * Note: Do not use before the {@see 'init'} hook.
 *
 * A simple function for creating or modifying a taxonomy object based on the
 * parameters given. The function will accept an array (third optional
 * parameter), along with strings for the taxonomy name and another string for
 * the object type.
 *
 * @since 2.3.0
 * @since 4.2.0 Introduced `show_in_quick_edit` argument.
 * @since 4.4.0 The `show_ui` argument is now enforced on the term editing screen.
 * @since 4.4.0 The `public` argument now controls whether the taxonomy can be queried on the front-end.
 *
 * @global array $wp_taxonomies Registered taxonomies.
 * @global WP    $wp            WP instance.
 *
 * @param string       $taxonomy    Taxonomy key, must not exceed 32 characters.
 * @param array|string $object_type Name of the object type for the taxonomy object.
 * @param array|string $args        {
 *     Optional. Array or query string of arguments for registering a taxonomy.
 *
 *     @type string        $label                 Name of the taxonomy shown in the menu. Usually plural. If not set,
 *                                                `$labels['name']` will be used.
 *     @type array         $labels                An array of labels for this taxonomy. By default, Tag labels are used for
 *                                                non-hierarchical taxonmies, and Category labels are used for hierarchical
 *                                                taxonomies. See accepted values in get_taxonomy_labels().
 *                                                Default empty array.
 *     @type string        $description           A short descriptive summary of what the taxonomy is for. Default empty.
 *     @type bool          $public                Whether the taxonomy is publicly queryable. Default true.
 *     @type bool          $hierarchical          Whether the taxonomy is hierarchical. Default false.
 *     @type bool          $show_ui               Whether to generate and allow a UI for managing terms in this taxonomy in
 *                                                the admin. If not set, the default is inherited from `$public`
 *                                                (default true).
 *     @type bool          $show_in_menu          Whether to show the taxonomy in the admin menu. If true, the taxonomy is
 *                                                shown as a submenu of the object type menu. If false, no menu is shown.
 *                                                `$show_ui` must be true. If not set, default is inherited from `$show_ui`
 *                                                (default true).
 *     @type bool          $show_in_nav_menus     Makes this taxonomy available for selection in navigation menus. If not
 *                                                set, the default is inherited from `$public` (default true).
 *     @type bool          $show_tagcloud         Whether to list the taxonomy in the Tag Cloud Widget controls. If not set,
 *                                                the default is inherited from `$show_ui` (default true).
 *     @type bool          $show_in_quick_edit    Whether to show the taxonomy in the quick/bulk edit panel. It not set,
 *                                                the default is inherited from `$show_ui` (default true).
 *     @type bool          $show_admin_column     Whether to display a column for the taxonomy on its post type listing
 *                                                screens. Default false.
 *     @type bool|callable $meta_box_cb           Provide a callback function for the meta box display. If not set,
 *                                                post_categories_meta_box() is used for hierarchical taxonomies, and
 *                                                post_tags_meta_box() is used for non-hierarchical. If false, no meta
 *                                                box is shown.
 *     @type array         $capabilities {
 *         Array of capabilities for this taxonomy.
 *
 *         @type string $manage_terms Default 'manage_categories'.
 *         @type string $edit_terms   Default 'manage_categories'.
 *         @type string $delete_terms Default 'manage_categories'.
 *         @type string $assign_terms Default 'edit_posts'.
 *     }
 *     @type bool|array    $rewrite {
 *         Triggers the handling of rewrites for this taxonomy. Default true, using $taxonomy as slug. To prevent
 *         rewrite, set to false. To specify rewrite rules, an array can be passed with any of these keys:
 *
 *         @type string $slug         Customize the permastruct slug. Default `$taxonomy` key.
 *         @type bool   $with_front   Should the permastruct be prepended with WP_Rewrite::$front. Default true.
 *         @type bool   $hierarchical Either hierarchical rewrite tag or not. Default false.
 *         @type int    $ep_mask      Assign an endpoint mask. Default `EP_NONE`.
 *     }
 *     @type string        $query_var             Sets the query var key for this taxonomy. Default `$taxonomy` key. If
 *                                                false, a taxonomy cannot be loaded at `?{query_var}={term_slug}`. If a
 *                                                string, the query `?{query_var}={term_slug}` will be valid.
 *     @type callable      $update_count_callback Works much like a hook, in that it will be called when the count is
 *                                                updated. Default _update_post_term_count() for taxonomies attached
 *                                                to post types, which confirms that the objects are published before
 *                                                counting them. Default _update_generic_term_count() for taxonomies
 *                                                attached to other object types, such as users.
 *     @type bool          $_builtin              This taxonomy is a "built-in" taxonomy. INTERNAL USE ONLY!
 *                                                Default false.
 * }
 * @return WP_Error|void WP_Error, if errors.
 */
function register_taxonomy($taxonomy, $object_type, $args = array())
{
    global $wp_taxonomies, $wp;
    if (!is_array($wp_taxonomies)) {
        $wp_taxonomies = array();
    }
    $args = wp_parse_args($args);
    /**
     * Filter the arguments for registering a taxonomy.
     *
     * @since 4.4.0
     *
     * @param array  $args        Array of arguments for registering a taxonomy.
     * @param array  $object_type Array of names of object types for the taxonomy.
     * @param string $taxonomy    Taxonomy key.
     */
    $args = apply_filters('register_taxonomy_args', $args, $taxonomy, (array) $object_type);
    $defaults = array('labels' => array(), 'description' => '', 'public' => true, 'hierarchical' => false, 'show_ui' => null, 'show_in_menu' => null, 'show_in_nav_menus' => null, 'show_tagcloud' => null, 'show_in_quick_edit' => null, 'show_admin_column' => false, 'meta_box_cb' => null, 'capabilities' => array(), 'rewrite' => true, 'query_var' => $taxonomy, 'update_count_callback' => '', '_builtin' => false);
    $args = array_merge($defaults, $args);
    if (empty($taxonomy) || strlen($taxonomy) > 32) {
        _doing_it_wrong(__FUNCTION__, __('Taxonomy names must be between 1 and 32 characters in length.'), '4.2');
        return new WP_Error('taxonomy_length_invalid', __('Taxonomy names must be between 1 and 32 characters in length.'));
    }
    // Non-public taxonomies should not register query vars, except in the admin.
    if (false !== $args['query_var'] && (is_admin() || false !== $args['public']) && !empty($wp)) {
        if (true === $args['query_var']) {
            $args['query_var'] = $taxonomy;
        } else {
            $args['query_var'] = sanitize_title_with_dashes($args['query_var']);
        }
        $wp->add_query_var($args['query_var']);
    }
    if (false !== $args['rewrite'] && (is_admin() || '' != get_option('permalink_structure'))) {
        $args['rewrite'] = wp_parse_args($args['rewrite'], array('with_front' => true, 'hierarchical' => false, 'ep_mask' => EP_NONE));
        if (empty($args['rewrite']['slug'])) {
            $args['rewrite']['slug'] = sanitize_title_with_dashes($taxonomy);
        }
        if ($args['hierarchical'] && $args['rewrite']['hierarchical']) {
            $tag = '(.+?)';
        } else {
            $tag = '([^/]+)';
        }
        add_rewrite_tag("%{$taxonomy}%", $tag, $args['query_var'] ? "{$args['query_var']}=" : "taxonomy={$taxonomy}&term=");
        add_permastruct($taxonomy, "{$args['rewrite']['slug']}/%{$taxonomy}%", $args['rewrite']);
    }
    // If not set, default to the setting for public.
    if (null === $args['show_ui']) {
        $args['show_ui'] = $args['public'];
    }
    // If not set, default to the setting for show_ui.
    if (null === $args['show_in_menu'] || !$args['show_ui']) {
        $args['show_in_menu'] = $args['show_ui'];
    }
    // If not set, default to the setting for public.
    if (null === $args['show_in_nav_menus']) {
        $args['show_in_nav_menus'] = $args['public'];
    }
    // If not set, default to the setting for show_ui.
    if (null === $args['show_tagcloud']) {
        $args['show_tagcloud'] = $args['show_ui'];
    }
    // If not set, default to the setting for show_ui.
    if (null === $args['show_in_quick_edit']) {
        $args['show_in_quick_edit'] = $args['show_ui'];
    }
    $default_caps = array('manage_terms' => 'manage_categories', 'edit_terms' => 'manage_categories', 'delete_terms' => 'manage_categories', 'assign_terms' => 'edit_posts');
    $args['cap'] = (object) array_merge($default_caps, $args['capabilities']);
    unset($args['capabilities']);
    $args['name'] = $taxonomy;
    $args['object_type'] = array_unique((array) $object_type);
    $args['labels'] = get_taxonomy_labels((object) $args);
    $args['label'] = $args['labels']->name;
    // If not set, use the default meta box
    if (null === $args['meta_box_cb']) {
        if ($args['hierarchical']) {
            $args['meta_box_cb'] = 'post_categories_meta_box';
        } else {
            $args['meta_box_cb'] = 'post_tags_meta_box';
        }
    }
    $wp_taxonomies[$taxonomy] = (object) $args;
    // register callback handling for metabox
    add_filter('wp_ajax_add-' . $taxonomy, '_wp_ajax_add_hierarchical_term');
    /**
     * Fires after a taxonomy is registered.
     *
     * @since 3.3.0
     *
     * @param string       $taxonomy    Taxonomy slug.
     * @param array|string $object_type Object type or array of object types.
     * @param array        $args        Array of taxonomy registration arguments.
     */
    do_action('registered_taxonomy', $taxonomy, $object_type, $args);
}

WordPress Version: 4.3

/**
 * Create or modify a taxonomy object. Do not use before init.
 *
 * A simple function for creating or modifying a taxonomy object based on the
 * parameters given. The function will accept an array (third optional
 * parameter), along with strings for the taxonomy name and another string for
 * the object type.
 *
 * Nothing is returned, so expect error maybe or use taxonomy_exists() to check
 * whether taxonomy exists.
 *
 * Optional $args contents:
 *
 * - label - Name of the taxonomy shown in the menu. Usually plural. If not set, labels['name'] will be used.
 * - labels - An array of labels for this taxonomy.
 *     * By default tag labels are used for non-hierarchical types and category labels for hierarchical ones.
 *     * You can see accepted values in {@link get_taxonomy_labels()}.
 * - description - A short descriptive summary of what the taxonomy is for. Defaults to blank.
 * - public - If the taxonomy should be publicly queryable; //@TODO not implemented.
 *     * Defaults to true.
 * - hierarchical - Whether the taxonomy is hierarchical (e.g. category). Defaults to false.
 * - show_ui - Whether to generate a default UI for managing this taxonomy in the admin.
 *     * If not set, the default is inherited from public.
 * - show_in_menu - Whether to show the taxonomy in the admin menu.
 *     * If true, the taxonomy is shown as a submenu of the object type menu.
 *     * If false, no menu is shown.
 *     * show_ui must be true.
 *     * If not set, the default is inherited from show_ui.
 * - show_in_nav_menus - Makes this taxonomy available for selection in navigation menus.
 *     * If not set, the default is inherited from public.
 * - show_tagcloud - Whether to list the taxonomy in the Tag Cloud Widget.
 *     * If not set, the default is inherited from show_ui.
 * - show_in_quick_edit - Whether to show the taxonomy in the quick/bulk edit panel.
 *     * It not set, the default is inherited from show_ui.
 * - show_admin_column - Whether to display a column for the taxonomy on its post type listing screens.
 *     * Defaults to false.
 * - meta_box_cb - Provide a callback function for the meta box display.
 *     * If not set, defaults to post_categories_meta_box for hierarchical taxonomies
 *     and post_tags_meta_box for non-hierarchical.
 *     * If false, no meta box is shown.
 * - capabilities - Array of capabilities for this taxonomy.
 *     * You can see accepted values in this function.
 * - rewrite - Triggers the handling of rewrites for this taxonomy. Defaults to true, using $taxonomy as slug.
 *     * To prevent rewrite, set to false.
 *     * To specify rewrite rules, an array can be passed with any of these keys
 *         * 'slug' => string Customize the permastruct slug. Defaults to $taxonomy key
 *         * 'with_front' => bool Should the permastruct be prepended with WP_Rewrite::$front. Defaults to true.
 *         * 'hierarchical' => bool Either hierarchical rewrite tag or not. Defaults to false.
 *         * 'ep_mask' => const Assign an endpoint mask.
 *             * If not specified, defaults to EP_NONE.
 * - query_var - Sets the query_var key for this taxonomy. Defaults to $taxonomy key
 *     * If false, a taxonomy cannot be loaded at ?{query_var}={term_slug}
 *     * If specified as a string, the query ?{query_var_string}={term_slug} will be valid.
 * - update_count_callback - Works much like a hook, in that it will be called when the count is updated.
 *     * Defaults to _update_post_term_count() for taxonomies attached to post types, which then confirms
 *       that the objects are published before counting them.
 *     * Defaults to _update_generic_term_count() for taxonomies attached to other object types, such as links.
 * - _builtin - true if this taxonomy is a native or "built-in" taxonomy. THIS IS FOR INTERNAL USE ONLY!
 *
 * @todo Document $args as a hash notation.
 *
 * @since 2.3.0
 * @since 4.2.0 Introduced `show_in_quick_edit` argument.
 *
 * @global array $wp_taxonomies Registered taxonomies.
 * @global WP    $wp            WP instance.
 *
 * @param string       $taxonomy    Taxonomy key, must not exceed 32 characters.
 * @param array|string $object_type Name of the object type for the taxonomy object.
 * @param array|string $args        See optional args description above.
 * @return WP_Error|void WP_Error, if errors.
 */
function register_taxonomy($taxonomy, $object_type, $args = array())
{
    global $wp_taxonomies, $wp;
    if (!is_array($wp_taxonomies)) {
        $wp_taxonomies = array();
    }
    $defaults = array('labels' => array(), 'description' => '', 'public' => true, 'hierarchical' => false, 'show_ui' => null, 'show_in_menu' => null, 'show_in_nav_menus' => null, 'show_tagcloud' => null, 'show_in_quick_edit' => null, 'show_admin_column' => false, 'meta_box_cb' => null, 'capabilities' => array(), 'rewrite' => true, 'query_var' => $taxonomy, 'update_count_callback' => '', '_builtin' => false);
    $args = wp_parse_args($args, $defaults);
    if (empty($taxonomy) || strlen($taxonomy) > 32) {
        _doing_it_wrong(__FUNCTION__, __('Taxonomy names must be between 1 and 32 characters in length.'), '4.2');
        return new WP_Error('taxonomy_length_invalid', __('Taxonomy names must be between 1 and 32 characters in length.'));
    }
    if (false !== $args['query_var'] && !empty($wp)) {
        if (true === $args['query_var']) {
            $args['query_var'] = $taxonomy;
        } else {
            $args['query_var'] = sanitize_title_with_dashes($args['query_var']);
        }
        $wp->add_query_var($args['query_var']);
    }
    if (false !== $args['rewrite'] && (is_admin() || '' != get_option('permalink_structure'))) {
        $args['rewrite'] = wp_parse_args($args['rewrite'], array('with_front' => true, 'hierarchical' => false, 'ep_mask' => EP_NONE));
        if (empty($args['rewrite']['slug'])) {
            $args['rewrite']['slug'] = sanitize_title_with_dashes($taxonomy);
        }
        if ($args['hierarchical'] && $args['rewrite']['hierarchical']) {
            $tag = '(.+?)';
        } else {
            $tag = '([^/]+)';
        }
        add_rewrite_tag("%{$taxonomy}%", $tag, $args['query_var'] ? "{$args['query_var']}=" : "taxonomy={$taxonomy}&term=");
        add_permastruct($taxonomy, "{$args['rewrite']['slug']}/%{$taxonomy}%", $args['rewrite']);
    }
    // If not set, default to the setting for public.
    if (null === $args['show_ui']) {
        $args['show_ui'] = $args['public'];
    }
    // If not set, default to the setting for show_ui.
    if (null === $args['show_in_menu'] || !$args['show_ui']) {
        $args['show_in_menu'] = $args['show_ui'];
    }
    // If not set, default to the setting for public.
    if (null === $args['show_in_nav_menus']) {
        $args['show_in_nav_menus'] = $args['public'];
    }
    // If not set, default to the setting for show_ui.
    if (null === $args['show_tagcloud']) {
        $args['show_tagcloud'] = $args['show_ui'];
    }
    // If not set, default to the setting for show_ui.
    if (null === $args['show_in_quick_edit']) {
        $args['show_in_quick_edit'] = $args['show_ui'];
    }
    $default_caps = array('manage_terms' => 'manage_categories', 'edit_terms' => 'manage_categories', 'delete_terms' => 'manage_categories', 'assign_terms' => 'edit_posts');
    $args['cap'] = (object) array_merge($default_caps, $args['capabilities']);
    unset($args['capabilities']);
    $args['name'] = $taxonomy;
    $args['object_type'] = array_unique((array) $object_type);
    $args['labels'] = get_taxonomy_labels((object) $args);
    $args['label'] = $args['labels']->name;
    // If not set, use the default meta box
    if (null === $args['meta_box_cb']) {
        if ($args['hierarchical']) {
            $args['meta_box_cb'] = 'post_categories_meta_box';
        } else {
            $args['meta_box_cb'] = 'post_tags_meta_box';
        }
    }
    $wp_taxonomies[$taxonomy] = (object) $args;
    // register callback handling for metabox
    add_filter('wp_ajax_add-' . $taxonomy, '_wp_ajax_add_hierarchical_term');
    /**
     * Fires after a taxonomy is registered.
     *
     * @since 3.3.0
     *
     * @param string       $taxonomy    Taxonomy slug.
     * @param array|string $object_type Object type or array of object types.
     * @param array        $args        Array of taxonomy registration arguments.
     */
    do_action('registered_taxonomy', $taxonomy, $object_type, $args);
}

WordPress Version: 4.2

/**
 * Create or modify a taxonomy object. Do not use before init.
 *
 * A simple function for creating or modifying a taxonomy object based on the
 * parameters given. The function will accept an array (third optional
 * parameter), along with strings for the taxonomy name and another string for
 * the object type.
 *
 * Nothing is returned, so expect error maybe or use taxonomy_exists() to check
 * whether taxonomy exists.
 *
 * Optional $args contents:
 *
 * - label - Name of the taxonomy shown in the menu. Usually plural. If not set, labels['name'] will be used.
 * - labels - An array of labels for this taxonomy.
 *     * By default tag labels are used for non-hierarchical types and category labels for hierarchical ones.
 *     * You can see accepted values in {@link get_taxonomy_labels()}.
 * - description - A short descriptive summary of what the taxonomy is for. Defaults to blank.
 * - public - If the taxonomy should be publicly queryable; //@TODO not implemented.
 *     * Defaults to true.
 * - hierarchical - Whether the taxonomy is hierarchical (e.g. category). Defaults to false.
 * - show_ui - Whether to generate a default UI for managing this taxonomy in the admin.
 *     * If not set, the default is inherited from public.
 * - show_in_menu - Whether to show the taxonomy in the admin menu.
 *     * If true, the taxonomy is shown as a submenu of the object type menu.
 *     * If false, no menu is shown.
 *     * show_ui must be true.
 *     * If not set, the default is inherited from show_ui.
 * - show_in_nav_menus - Makes this taxonomy available for selection in navigation menus.
 *     * If not set, the default is inherited from public.
 * - show_tagcloud - Whether to list the taxonomy in the Tag Cloud Widget.
 *     * If not set, the default is inherited from show_ui.
 * - show_in_quick_edit - Whether to show the taxonomy in the quick/bulk edit panel.
 *     * It not set, the default is inherited from show_ui.
 * - show_admin_column - Whether to display a column for the taxonomy on its post type listing screens.
 *     * Defaults to false.
 * - meta_box_cb - Provide a callback function for the meta box display.
 *     * If not set, defaults to post_categories_meta_box for hierarchical taxonomies
 *     and post_tags_meta_box for non-hierarchical.
 *     * If false, no meta box is shown.
 * - capabilities - Array of capabilities for this taxonomy.
 *     * You can see accepted values in this function.
 * - rewrite - Triggers the handling of rewrites for this taxonomy. Defaults to true, using $taxonomy as slug.
 *     * To prevent rewrite, set to false.
 *     * To specify rewrite rules, an array can be passed with any of these keys
 *         * 'slug' => string Customize the permastruct slug. Defaults to $taxonomy key
 *         * 'with_front' => bool Should the permastruct be prepended with WP_Rewrite::$front. Defaults to true.
 *         * 'hierarchical' => bool Either hierarchical rewrite tag or not. Defaults to false.
 *         * 'ep_mask' => const Assign an endpoint mask.
 *             * If not specified, defaults to EP_NONE.
 * - query_var - Sets the query_var key for this taxonomy. Defaults to $taxonomy key
 *     * If false, a taxonomy cannot be loaded at ?{query_var}={term_slug}
 *     * If specified as a string, the query ?{query_var_string}={term_slug} will be valid.
 * - update_count_callback - Works much like a hook, in that it will be called when the count is updated.
 *     * Defaults to _update_post_term_count() for taxonomies attached to post types, which then confirms
 *       that the objects are published before counting them.
 *     * Defaults to _update_generic_term_count() for taxonomies attached to other object types, such as links.
 * - _builtin - true if this taxonomy is a native or "built-in" taxonomy. THIS IS FOR INTERNAL USE ONLY!
 *
 * @since 2.3.0
 * @since 4.2.0 Introduced `show_in_quick_edit` argument.
 *
 * @global array $wp_taxonomies Registered taxonomies.
 * @global WP    $wp            WP instance.
 *
 * @param string $taxonomy Taxonomy key, must not exceed 32 characters.
 * @param array|string $object_type Name of the object type for the taxonomy object.
 * @param array|string $args See optional args description above.
 * @return null|WP_Error WP_Error if errors, otherwise null.
 */
function register_taxonomy($taxonomy, $object_type, $args = array())
{
    global $wp_taxonomies, $wp;
    if (!is_array($wp_taxonomies)) {
        $wp_taxonomies = array();
    }
    $defaults = array('labels' => array(), 'description' => '', 'public' => true, 'hierarchical' => false, 'show_ui' => null, 'show_in_menu' => null, 'show_in_nav_menus' => null, 'show_tagcloud' => null, 'show_in_quick_edit' => null, 'show_admin_column' => false, 'meta_box_cb' => null, 'capabilities' => array(), 'rewrite' => true, 'query_var' => $taxonomy, 'update_count_callback' => '', '_builtin' => false);
    $args = wp_parse_args($args, $defaults);
    if (empty($taxonomy) || strlen($taxonomy) > 32) {
        _doing_it_wrong(__FUNCTION__, __('Taxonomy names must be between 1 and 32 characters in length.'), '4.2');
        return new WP_Error('taxonomy_length_invalid', __('Taxonomy names must be between 1 and 32 characters in length.'));
    }
    if (false !== $args['query_var'] && !empty($wp)) {
        if (true === $args['query_var']) {
            $args['query_var'] = $taxonomy;
        } else {
            $args['query_var'] = sanitize_title_with_dashes($args['query_var']);
        }
        $wp->add_query_var($args['query_var']);
    }
    if (false !== $args['rewrite'] && (is_admin() || '' != get_option('permalink_structure'))) {
        $args['rewrite'] = wp_parse_args($args['rewrite'], array('with_front' => true, 'hierarchical' => false, 'ep_mask' => EP_NONE));
        if (empty($args['rewrite']['slug'])) {
            $args['rewrite']['slug'] = sanitize_title_with_dashes($taxonomy);
        }
        if ($args['hierarchical'] && $args['rewrite']['hierarchical']) {
            $tag = '(.+?)';
        } else {
            $tag = '([^/]+)';
        }
        add_rewrite_tag("%{$taxonomy}%", $tag, $args['query_var'] ? "{$args['query_var']}=" : "taxonomy={$taxonomy}&term=");
        add_permastruct($taxonomy, "{$args['rewrite']['slug']}/%{$taxonomy}%", $args['rewrite']);
    }
    // If not set, default to the setting for public.
    if (null === $args['show_ui']) {
        $args['show_ui'] = $args['public'];
    }
    // If not set, default to the setting for show_ui.
    if (null === $args['show_in_menu'] || !$args['show_ui']) {
        $args['show_in_menu'] = $args['show_ui'];
    }
    // If not set, default to the setting for public.
    if (null === $args['show_in_nav_menus']) {
        $args['show_in_nav_menus'] = $args['public'];
    }
    // If not set, default to the setting for show_ui.
    if (null === $args['show_tagcloud']) {
        $args['show_tagcloud'] = $args['show_ui'];
    }
    // If not set, default to the setting for show_ui.
    if (null === $args['show_in_quick_edit']) {
        $args['show_in_quick_edit'] = $args['show_ui'];
    }
    $default_caps = array('manage_terms' => 'manage_categories', 'edit_terms' => 'manage_categories', 'delete_terms' => 'manage_categories', 'assign_terms' => 'edit_posts');
    $args['cap'] = (object) array_merge($default_caps, $args['capabilities']);
    unset($args['capabilities']);
    $args['name'] = $taxonomy;
    $args['object_type'] = array_unique((array) $object_type);
    $args['labels'] = get_taxonomy_labels((object) $args);
    $args['label'] = $args['labels']->name;
    // If not set, use the default meta box
    if (null === $args['meta_box_cb']) {
        if ($args['hierarchical']) {
            $args['meta_box_cb'] = 'post_categories_meta_box';
        } else {
            $args['meta_box_cb'] = 'post_tags_meta_box';
        }
    }
    $wp_taxonomies[$taxonomy] = (object) $args;
    // register callback handling for metabox
    add_filter('wp_ajax_add-' . $taxonomy, '_wp_ajax_add_hierarchical_term');
    /**
     * Fires after a taxonomy is registered.
     *
     * @since 3.3.0
     *
     * @param string       $taxonomy    Taxonomy slug.
     * @param array|string $object_type Object type or array of object types.
     * @param array        $args        Array of taxonomy registration arguments.
     */
    do_action('registered_taxonomy', $taxonomy, $object_type, $args);
}

WordPress Version: 4.0

/**
 * Create or modify a taxonomy object. Do not use before init.
 *
 * A simple function for creating or modifying a taxonomy object based on the
 * parameters given. The function will accept an array (third optional
 * parameter), along with strings for the taxonomy name and another string for
 * the object type.
 *
 * Nothing is returned, so expect error maybe or use taxonomy_exists() to check
 * whether taxonomy exists.
 *
 * Optional $args contents:
 *
 * - label - Name of the taxonomy shown in the menu. Usually plural. If not set, labels['name'] will be used.
 * - labels - An array of labels for this taxonomy.
 *     * By default tag labels are used for non-hierarchical types and category labels for hierarchical ones.
 *     * You can see accepted values in {@link get_taxonomy_labels()}.
 * - description - A short descriptive summary of what the taxonomy is for. Defaults to blank.
 * - public - If the taxonomy should be publicly queryable; //@TODO not implemented.
 *     * Defaults to true.
 * - hierarchical - Whether the taxonomy is hierarchical (e.g. category). Defaults to false.
 * - show_ui - Whether to generate a default UI for managing this taxonomy in the admin.
 *     * If not set, the default is inherited from public.
 * - show_in_menu - Whether to show the taxonomy in the admin menu.
 *     * If true, the taxonomy is shown as a submenu of the object type menu.
 *     * If false, no menu is shown.
 *     * show_ui must be true.
 *     * If not set, the default is inherited from show_ui.
 * - show_in_nav_menus - Makes this taxonomy available for selection in navigation menus.
 *     * If not set, the default is inherited from public.
 * - show_tagcloud - Whether to list the taxonomy in the Tag Cloud Widget.
 *     * If not set, the default is inherited from show_ui.
 * - show_admin_column - Whether to display a column for the taxonomy on its post type listing screens.
 *     * Defaults to false.
 * - meta_box_cb - Provide a callback function for the meta box display.
 *     * If not set, defaults to post_categories_meta_box for hierarchical taxonomies
 *     and post_tags_meta_box for non-hierarchical.
 *     * If false, no meta box is shown.
 * - capabilities - Array of capabilities for this taxonomy.
 *     * You can see accepted values in this function.
 * - rewrite - Triggers the handling of rewrites for this taxonomy. Defaults to true, using $taxonomy as slug.
 *     * To prevent rewrite, set to false.
 *     * To specify rewrite rules, an array can be passed with any of these keys
 *         * 'slug' => string Customize the permastruct slug. Defaults to $taxonomy key
 *         * 'with_front' => bool Should the permastruct be prepended with WP_Rewrite::$front. Defaults to true.
 *         * 'hierarchical' => bool Either hierarchical rewrite tag or not. Defaults to false.
 *         * 'ep_mask' => const Assign an endpoint mask.
 *             * If not specified, defaults to EP_NONE.
 * - query_var - Sets the query_var key for this taxonomy. Defaults to $taxonomy key
 *     * If false, a taxonomy cannot be loaded at ?{query_var}={term_slug}
 *     * If specified as a string, the query ?{query_var_string}={term_slug} will be valid.
 * - update_count_callback - Works much like a hook, in that it will be called when the count is updated.
 *     * Defaults to _update_post_term_count() for taxonomies attached to post types, which then confirms
 *       that the objects are published before counting them.
 *     * Defaults to _update_generic_term_count() for taxonomies attached to other object types, such as links.
 * - _builtin - true if this taxonomy is a native or "built-in" taxonomy. THIS IS FOR INTERNAL USE ONLY!
 *
 * @since 2.3.0
 * @uses $wp_taxonomies Inserts new taxonomy object into the list
 * @uses $wp Adds query vars
 *
 * @param string $taxonomy Taxonomy key, must not exceed 32 characters.
 * @param array|string $object_type Name of the object type for the taxonomy object.
 * @param array|string $args See optional args description above.
 * @return null|WP_Error WP_Error if errors, otherwise null.
 */
function register_taxonomy($taxonomy, $object_type, $args = array())
{
    global $wp_taxonomies, $wp;
    if (!is_array($wp_taxonomies)) {
        $wp_taxonomies = array();
    }
    $defaults = array('labels' => array(), 'description' => '', 'public' => true, 'hierarchical' => false, 'show_ui' => null, 'show_in_menu' => null, 'show_in_nav_menus' => null, 'show_tagcloud' => null, 'show_admin_column' => false, 'meta_box_cb' => null, 'capabilities' => array(), 'rewrite' => true, 'query_var' => $taxonomy, 'update_count_callback' => '', '_builtin' => false);
    $args = wp_parse_args($args, $defaults);
    if (strlen($taxonomy) > 32) {
        _doing_it_wrong(__FUNCTION__, __('Taxonomies cannot exceed 32 characters in length'), '4.0');
        return new WP_Error('taxonomy_too_long', __('Taxonomies cannot exceed 32 characters in length'));
    }
    if (false !== $args['query_var'] && !empty($wp)) {
        if (true === $args['query_var']) {
            $args['query_var'] = $taxonomy;
        } else {
            $args['query_var'] = sanitize_title_with_dashes($args['query_var']);
        }
        $wp->add_query_var($args['query_var']);
    }
    if (false !== $args['rewrite'] && (is_admin() || '' != get_option('permalink_structure'))) {
        $args['rewrite'] = wp_parse_args($args['rewrite'], array('with_front' => true, 'hierarchical' => false, 'ep_mask' => EP_NONE));
        if (empty($args['rewrite']['slug'])) {
            $args['rewrite']['slug'] = sanitize_title_with_dashes($taxonomy);
        }
        if ($args['hierarchical'] && $args['rewrite']['hierarchical']) {
            $tag = '(.+?)';
        } else {
            $tag = '([^/]+)';
        }
        add_rewrite_tag("%{$taxonomy}%", $tag, $args['query_var'] ? "{$args['query_var']}=" : "taxonomy={$taxonomy}&term=");
        add_permastruct($taxonomy, "{$args['rewrite']['slug']}/%{$taxonomy}%", $args['rewrite']);
    }
    // If not set, default to the setting for public.
    if (null === $args['show_ui']) {
        $args['show_ui'] = $args['public'];
    }
    // If not set, default to the setting for show_ui.
    if (null === $args['show_in_menu'] || !$args['show_ui']) {
        $args['show_in_menu'] = $args['show_ui'];
    }
    // If not set, default to the setting for public.
    if (null === $args['show_in_nav_menus']) {
        $args['show_in_nav_menus'] = $args['public'];
    }
    // If not set, default to the setting for show_ui.
    if (null === $args['show_tagcloud']) {
        $args['show_tagcloud'] = $args['show_ui'];
    }
    $default_caps = array('manage_terms' => 'manage_categories', 'edit_terms' => 'manage_categories', 'delete_terms' => 'manage_categories', 'assign_terms' => 'edit_posts');
    $args['cap'] = (object) array_merge($default_caps, $args['capabilities']);
    unset($args['capabilities']);
    $args['name'] = $taxonomy;
    $args['object_type'] = array_unique((array) $object_type);
    $args['labels'] = get_taxonomy_labels((object) $args);
    $args['label'] = $args['labels']->name;
    // If not set, use the default meta box
    if (null === $args['meta_box_cb']) {
        if ($args['hierarchical']) {
            $args['meta_box_cb'] = 'post_categories_meta_box';
        } else {
            $args['meta_box_cb'] = 'post_tags_meta_box';
        }
    }
    $wp_taxonomies[$taxonomy] = (object) $args;
    // register callback handling for metabox
    add_filter('wp_ajax_add-' . $taxonomy, '_wp_ajax_add_hierarchical_term');
    /**
     * Fires after a taxonomy is registered.
     *
     * @since 3.3.0
     *
     * @param string       $taxonomy    Taxonomy slug.
     * @param array|string $object_type Object type or array of object types.
     * @param array        $args        Array of taxonomy registration arguments.
     */
    do_action('registered_taxonomy', $taxonomy, $object_type, $args);
}

WordPress Version: 3.9

/**
 * Create or modify a taxonomy object. Do not use before init.
 *
 * A simple function for creating or modifying a taxonomy object based on the
 * parameters given. The function will accept an array (third optional
 * parameter), along with strings for the taxonomy name and another string for
 * the object type.
 *
 * Nothing is returned, so expect error maybe or use taxonomy_exists() to check
 * whether taxonomy exists.
 *
 * Optional $args contents:
 *
 * - label - Name of the taxonomy shown in the menu. Usually plural. If not set, labels['name'] will be used.
 * - labels - An array of labels for this taxonomy.
 *     * By default tag labels are used for non-hierarchical types and category labels for hierarchical ones.
 *     * You can see accepted values in {@link get_taxonomy_labels()}.
 * - description - A short descriptive summary of what the taxonomy is for. Defaults to blank.
 * - public - If the taxonomy should be publicly queryable; //@TODO not implemented.
 *     * Defaults to true.
 * - hierarchical - Whether the taxonomy is hierarchical (e.g. category). Defaults to false.
 * - show_ui -Whether to generate a default UI for managing this taxonomy in the admin.
 *     * If not set, the default is inherited from public.
 * - show_in_menu - Where to show the taxonomy in the admin menu.
 *     * If true, the taxonomy is shown as a submenu of the object type menu.
 *     * If false, no menu is shown.
 *     * show_ui must be true.
 *     * If not set, the default is inherited from show_ui.
 * - show_in_nav_menus - Makes this taxonomy available for selection in navigation menus.
 *     * If not set, the default is inherited from public.
 * - show_tagcloud - Whether to list the taxonomy in the Tag Cloud Widget.
 *     * If not set, the default is inherited from show_ui.
 * - show_admin_column - Whether to display a column for the taxonomy on its post type listing screens.
 *     * Defaults to false.
 * - meta_box_cb - Provide a callback function for the meta box display.
 *     * If not set, defaults to post_categories_meta_box for hierarchical taxonomies
 *     and post_tags_meta_box for non-hierarchical.
 *     * If false, no meta box is shown.
 * - capabilities - Array of capabilities for this taxonomy.
 *     * You can see accepted values in this function.
 * - rewrite - Triggers the handling of rewrites for this taxonomy. Defaults to true, using $taxonomy as slug.
 *     * To prevent rewrite, set to false.
 *     * To specify rewrite rules, an array can be passed with any of these keys
 *         * 'slug' => string Customize the permastruct slug. Defaults to $taxonomy key
 *         * 'with_front' => bool Should the permastruct be prepended with WP_Rewrite::$front. Defaults to true.
 *         * 'hierarchical' => bool Either hierarchical rewrite tag or not. Defaults to false.
 *         * 'ep_mask' => const Assign an endpoint mask.
 *             * If not specified, defaults to EP_NONE.
 * - query_var - Sets the query_var key for this taxonomy. Defaults to $taxonomy key
 *     * If false, a taxonomy cannot be loaded at ?{query_var}={term_slug}
 *     * If specified as a string, the query ?{query_var_string}={term_slug} will be valid.
 * - update_count_callback - Works much like a hook, in that it will be called when the count is updated.
 *     * Defaults to _update_post_term_count() for taxonomies attached to post types, which then confirms
 *       that the objects are published before counting them.
 *     * Defaults to _update_generic_term_count() for taxonomies attached to other object types, such as links.
 * - _builtin - true if this taxonomy is a native or "built-in" taxonomy. THIS IS FOR INTERNAL USE ONLY!
 *
 * @since 2.3.0
 * @uses $wp_taxonomies Inserts new taxonomy object into the list
 * @uses $wp Adds query vars
 *
 * @param string $taxonomy Taxonomy key, must not exceed 32 characters.
 * @param array|string $object_type Name of the object type for the taxonomy object.
 * @param array|string $args See optional args description above.
 * @return null|WP_Error WP_Error if errors, otherwise null.
 */
function register_taxonomy($taxonomy, $object_type, $args = array())
{
    global $wp_taxonomies, $wp;
    if (!is_array($wp_taxonomies)) {
        $wp_taxonomies = array();
    }
    $defaults = array('labels' => array(), 'description' => '', 'public' => true, 'hierarchical' => false, 'show_ui' => null, 'show_in_menu' => null, 'show_in_nav_menus' => null, 'show_tagcloud' => null, 'show_admin_column' => false, 'meta_box_cb' => null, 'capabilities' => array(), 'rewrite' => true, 'query_var' => $taxonomy, 'update_count_callback' => '', '_builtin' => false);
    $args = wp_parse_args($args, $defaults);
    if (strlen($taxonomy) > 32) {
        return new WP_Error('taxonomy_too_long', __('Taxonomies cannot exceed 32 characters in length'));
    }
    if (false !== $args['query_var'] && !empty($wp)) {
        if (true === $args['query_var']) {
            $args['query_var'] = $taxonomy;
        } else {
            $args['query_var'] = sanitize_title_with_dashes($args['query_var']);
        }
        $wp->add_query_var($args['query_var']);
    }
    if (false !== $args['rewrite'] && (is_admin() || '' != get_option('permalink_structure'))) {
        $args['rewrite'] = wp_parse_args($args['rewrite'], array('with_front' => true, 'hierarchical' => false, 'ep_mask' => EP_NONE));
        if (empty($args['rewrite']['slug'])) {
            $args['rewrite']['slug'] = sanitize_title_with_dashes($taxonomy);
        }
        if ($args['hierarchical'] && $args['rewrite']['hierarchical']) {
            $tag = '(.+?)';
        } else {
            $tag = '([^/]+)';
        }
        add_rewrite_tag("%{$taxonomy}%", $tag, $args['query_var'] ? "{$args['query_var']}=" : "taxonomy={$taxonomy}&term=");
        add_permastruct($taxonomy, "{$args['rewrite']['slug']}/%{$taxonomy}%", $args['rewrite']);
    }
    // If not set, default to the setting for public.
    if (null === $args['show_ui']) {
        $args['show_ui'] = $args['public'];
    }
    // If not set, default to the setting for show_ui.
    if (null === $args['show_in_menu'] || !$args['show_ui']) {
        $args['show_in_menu'] = $args['show_ui'];
    }
    // If not set, default to the setting for public.
    if (null === $args['show_in_nav_menus']) {
        $args['show_in_nav_menus'] = $args['public'];
    }
    // If not set, default to the setting for show_ui.
    if (null === $args['show_tagcloud']) {
        $args['show_tagcloud'] = $args['show_ui'];
    }
    $default_caps = array('manage_terms' => 'manage_categories', 'edit_terms' => 'manage_categories', 'delete_terms' => 'manage_categories', 'assign_terms' => 'edit_posts');
    $args['cap'] = (object) array_merge($default_caps, $args['capabilities']);
    unset($args['capabilities']);
    $args['name'] = $taxonomy;
    $args['object_type'] = array_unique((array) $object_type);
    $args['labels'] = get_taxonomy_labels((object) $args);
    $args['label'] = $args['labels']->name;
    // If not set, use the default meta box
    if (null === $args['meta_box_cb']) {
        if ($args['hierarchical']) {
            $args['meta_box_cb'] = 'post_categories_meta_box';
        } else {
            $args['meta_box_cb'] = 'post_tags_meta_box';
        }
    }
    $wp_taxonomies[$taxonomy] = (object) $args;
    // register callback handling for metabox
    add_filter('wp_ajax_add-' . $taxonomy, '_wp_ajax_add_hierarchical_term');
    /**
     * Fires after a taxonomy is registered.
     *
     * @since 3.3.0
     *
     * @param string       $taxonomy    Taxonomy slug.
     * @param array|string $object_type Object type or array of object types.
     * @param array|string $args        Array or string of taxonomy registration arguments.
     */
    do_action('registered_taxonomy', $taxonomy, $object_type, $args);
}

WordPress Version: 3.8

/**
 * Create or modify a taxonomy object. Do not use before init.
 *
 * A simple function for creating or modifying a taxonomy object based on the
 * parameters given. The function will accept an array (third optional
 * parameter), along with strings for the taxonomy name and another string for
 * the object type.
 *
 * Nothing is returned, so expect error maybe or use taxonomy_exists() to check
 * whether taxonomy exists.
 *
 * Optional $args contents:
 *
 * - label - Name of the taxonomy shown in the menu. Usually plural. If not set, labels['name'] will be used.
 * - labels - An array of labels for this taxonomy.
 *     * By default tag labels are used for non-hierarchical types and category labels for hierarchical ones.
 *     * You can see accepted values in {@link get_taxonomy_labels()}.
 * - description - A short descriptive summary of what the taxonomy is for. Defaults to blank.
 * - public - If the taxonomy should be publicly queryable; //@TODO not implemented.
 *     * Defaults to true.
 * - hierarchical - Whether the taxonomy is hierarchical (e.g. category). Defaults to false.
 * - show_ui -Whether to generate a default UI for managing this taxonomy in the admin.
 *     * If not set, the default is inherited from public.
 * - show_in_menu - Where to show the taxonomy in the admin menu.
 *     * If true, the taxonomy is shown as a submenu of the object type menu.
 *     * If false, no menu is shown.
 *     * show_ui must be true.
 *     * If not set, the default is inherited from show_ui.
 * - show_in_nav_menus - Makes this taxonomy available for selection in navigation menus.
 *     * If not set, the default is inherited from public.
 * - show_tagcloud - Whether to list the taxonomy in the Tag Cloud Widget.
 *     * If not set, the default is inherited from show_ui.
 * - meta_box_cb - Provide a callback function for the meta box display.
 *     * If not set, defaults to post_categories_meta_box for hierarchical taxonomies
 *     and post_tags_meta_box for non-hierarchical.
 *     * If false, no meta box is shown.
 * - capabilities - Array of capabilities for this taxonomy.
 *     * You can see accepted values in this function.
 * - rewrite - Triggers the handling of rewrites for this taxonomy. Defaults to true, using $taxonomy as slug.
 *     * To prevent rewrite, set to false.
 *     * To specify rewrite rules, an array can be passed with any of these keys
 *         * 'slug' => string Customize the permastruct slug. Defaults to $taxonomy key
 *         * 'with_front' => bool Should the permastruct be prepended with WP_Rewrite::$front. Defaults to true.
 *         * 'hierarchical' => bool Either hierarchical rewrite tag or not. Defaults to false.
 *         * 'ep_mask' => const Assign an endpoint mask.
 *             * If not specified, defaults to EP_NONE.
 * - query_var - Sets the query_var key for this taxonomy. Defaults to $taxonomy key
 *     * If false, a taxonomy cannot be loaded at ?{query_var}={term_slug}
 *     * If specified as a string, the query ?{query_var_string}={term_slug} will be valid.
 * - update_count_callback - Works much like a hook, in that it will be called when the count is updated.
 *     * Defaults to _update_post_term_count() for taxonomies attached to post types, which then confirms
 *       that the objects are published before counting them.
 *     * Defaults to _update_generic_term_count() for taxonomies attached to other object types, such as links.
 * - _builtin - true if this taxonomy is a native or "built-in" taxonomy. THIS IS FOR INTERNAL USE ONLY!
 *
 * @since 2.3.0
 * @uses $wp_taxonomies Inserts new taxonomy object into the list
 * @uses $wp Adds query vars
 *
 * @param string $taxonomy Taxonomy key, must not exceed 32 characters.
 * @param array|string $object_type Name of the object type for the taxonomy object.
 * @param array|string $args See optional args description above.
 * @return null|WP_Error WP_Error if errors, otherwise null.
 */
function register_taxonomy($taxonomy, $object_type, $args = array())
{
    global $wp_taxonomies, $wp;
    if (!is_array($wp_taxonomies)) {
        $wp_taxonomies = array();
    }
    $defaults = array('labels' => array(), 'description' => '', 'public' => true, 'hierarchical' => false, 'show_ui' => null, 'show_in_menu' => null, 'show_in_nav_menus' => null, 'show_tagcloud' => null, 'meta_box_cb' => null, 'capabilities' => array(), 'rewrite' => true, 'query_var' => $taxonomy, 'update_count_callback' => '', '_builtin' => false);
    $args = wp_parse_args($args, $defaults);
    if (strlen($taxonomy) > 32) {
        return new WP_Error('taxonomy_too_long', __('Taxonomies cannot exceed 32 characters in length'));
    }
    if (false !== $args['query_var'] && !empty($wp)) {
        if (true === $args['query_var']) {
            $args['query_var'] = $taxonomy;
        } else {
            $args['query_var'] = sanitize_title_with_dashes($args['query_var']);
        }
        $wp->add_query_var($args['query_var']);
    }
    if (false !== $args['rewrite'] && (is_admin() || '' != get_option('permalink_structure'))) {
        $args['rewrite'] = wp_parse_args($args['rewrite'], array('with_front' => true, 'hierarchical' => false, 'ep_mask' => EP_NONE));
        if (empty($args['rewrite']['slug'])) {
            $args['rewrite']['slug'] = sanitize_title_with_dashes($taxonomy);
        }
        if ($args['hierarchical'] && $args['rewrite']['hierarchical']) {
            $tag = '(.+?)';
        } else {
            $tag = '([^/]+)';
        }
        add_rewrite_tag("%{$taxonomy}%", $tag, $args['query_var'] ? "{$args['query_var']}=" : "taxonomy={$taxonomy}&term=");
        add_permastruct($taxonomy, "{$args['rewrite']['slug']}/%{$taxonomy}%", $args['rewrite']);
    }
    // If not set, default to the setting for public.
    if (null === $args['show_ui']) {
        $args['show_ui'] = $args['public'];
    }
    // If not set, default to the setting for show_ui.
    if (null === $args['show_in_menu'] || !$args['show_ui']) {
        $args['show_in_menu'] = $args['show_ui'];
    }
    // If not set, default to the setting for public.
    if (null === $args['show_in_nav_menus']) {
        $args['show_in_nav_menus'] = $args['public'];
    }
    // If not set, default to the setting for show_ui.
    if (null === $args['show_tagcloud']) {
        $args['show_tagcloud'] = $args['show_ui'];
    }
    $default_caps = array('manage_terms' => 'manage_categories', 'edit_terms' => 'manage_categories', 'delete_terms' => 'manage_categories', 'assign_terms' => 'edit_posts');
    $args['cap'] = (object) array_merge($default_caps, $args['capabilities']);
    unset($args['capabilities']);
    $args['name'] = $taxonomy;
    $args['object_type'] = array_unique((array) $object_type);
    $args['labels'] = get_taxonomy_labels((object) $args);
    $args['label'] = $args['labels']->name;
    // If not set, use the default meta box
    if (null === $args['meta_box_cb']) {
        if ($args['hierarchical']) {
            $args['meta_box_cb'] = 'post_categories_meta_box';
        } else {
            $args['meta_box_cb'] = 'post_tags_meta_box';
        }
    }
    $wp_taxonomies[$taxonomy] = (object) $args;
    // register callback handling for metabox
    add_filter('wp_ajax_add-' . $taxonomy, '_wp_ajax_add_hierarchical_term');
    do_action('registered_taxonomy', $taxonomy, $object_type, $args);
}

WordPress Version: 3.7

/**
 * Create or modify a taxonomy object. Do not use before init.
 *
 * A simple function for creating or modifying a taxonomy object based on the
 * parameters given. The function will accept an array (third optional
 * parameter), along with strings for the taxonomy name and another string for
 * the object type.
 *
 * Nothing is returned, so expect error maybe or use taxonomy_exists() to check
 * whether taxonomy exists.
 *
 * Optional $args contents:
 *
 * - label - Name of the taxonomy shown in the menu. Usually plural. If not set, labels['name'] will be used.
 * - labels - An array of labels for this taxonomy.
 *     * By default tag labels are used for non-hierarchical types and category labels for hierarchical ones.
 *     * You can see accepted values in {@link get_taxonomy_labels()}.
 * - description - A short descriptive summary of what the taxonomy is for. Defaults to blank.
 * - public - If the taxonomy should be publicly queryable; //@TODO not implemented.
 *     * Defaults to true.
 * - hierarchical - Whether the taxonomy is hierarchical (e.g. category). Defaults to false.
 * - show_ui -Whether to generate a default UI for managing this taxonomy in the admin.
 *     * If not set, the default is inherited from public.
 * - show_in_menu - Where to show the taxonomy in the admin menu.
 *     * If true, the taxonomy is shown as a submenu of the object type menu.
 *     * If false, no menu is shown.
 *     * show_ui must be true.
 *     * If not set, the default is inherited from show_ui.
 * - show_in_nav_menus - Makes this taxonomy available for selection in navigation menus.
 *     * If not set, the default is inherited from public.
 * - show_tagcloud - Whether to list the taxonomy in the Tag Cloud Widget.
 *     * If not set, the default is inherited from show_ui.
 * - meta_box_cb - Provide a callback function for the meta box display. Defaults to
 *     post_categories_meta_box for hierarchical taxonomies and post_tags_meta_box for non-hierarchical.
 * - capabilities - Array of capabilities for this taxonomy.
 *     * You can see accepted values in this function.
 * - rewrite - Triggers the handling of rewrites for this taxonomy. Defaults to true, using $taxonomy as slug.
 *     * To prevent rewrite, set to false.
 *     * To specify rewrite rules, an array can be passed with any of these keys
 *         * 'slug' => string Customize the permastruct slug. Defaults to $taxonomy key
 *         * 'with_front' => bool Should the permastruct be prepended with WP_Rewrite::$front. Defaults to true.
 *         * 'hierarchical' => bool Either hierarchical rewrite tag or not. Defaults to false.
 *         * 'ep_mask' => const Assign an endpoint mask.
 *             * If not specified, defaults to EP_NONE.
 * - query_var - Sets the query_var key for this taxonomy. Defaults to $taxonomy key
 *     * If false, a taxonomy cannot be loaded at ?{query_var}={term_slug}
 *     * If specified as a string, the query ?{query_var_string}={term_slug} will be valid.
 * - update_count_callback - Works much like a hook, in that it will be called when the count is updated.
 *     * Defaults to _update_post_term_count() for taxonomies attached to post types, which then confirms
 *       that the objects are published before counting them.
 *     * Defaults to _update_generic_term_count() for taxonomies attached to other object types, such as links.
 * - _builtin - true if this taxonomy is a native or "built-in" taxonomy. THIS IS FOR INTERNAL USE ONLY!
 *
 * @since 2.3.0
 * @uses $wp_taxonomies Inserts new taxonomy object into the list
 * @uses $wp Adds query vars
 *
 * @param string $taxonomy Taxonomy key, must not exceed 32 characters.
 * @param array|string $object_type Name of the object type for the taxonomy object.
 * @param array|string $args See optional args description above.
 * @return null|WP_Error WP_Error if errors, otherwise null.
 */
function register_taxonomy($taxonomy, $object_type, $args = array())
{
    global $wp_taxonomies, $wp;
    if (!is_array($wp_taxonomies)) {
        $wp_taxonomies = array();
    }
    $defaults = array('labels' => array(), 'description' => '', 'public' => true, 'hierarchical' => false, 'show_ui' => null, 'show_in_menu' => null, 'show_in_nav_menus' => null, 'show_tagcloud' => null, 'meta_box_cb' => null, 'capabilities' => array(), 'rewrite' => true, 'query_var' => $taxonomy, 'update_count_callback' => '', '_builtin' => false);
    $args = wp_parse_args($args, $defaults);
    if (strlen($taxonomy) > 32) {
        return new WP_Error('taxonomy_too_long', __('Taxonomies cannot exceed 32 characters in length'));
    }
    if (false !== $args['query_var'] && !empty($wp)) {
        if (true === $args['query_var']) {
            $args['query_var'] = $taxonomy;
        } else {
            $args['query_var'] = sanitize_title_with_dashes($args['query_var']);
        }
        $wp->add_query_var($args['query_var']);
    }
    if (false !== $args['rewrite'] && (is_admin() || '' != get_option('permalink_structure'))) {
        $args['rewrite'] = wp_parse_args($args['rewrite'], array('with_front' => true, 'hierarchical' => false, 'ep_mask' => EP_NONE));
        if (empty($args['rewrite']['slug'])) {
            $args['rewrite']['slug'] = sanitize_title_with_dashes($taxonomy);
        }
        if ($args['hierarchical'] && $args['rewrite']['hierarchical']) {
            $tag = '(.+?)';
        } else {
            $tag = '([^/]+)';
        }
        add_rewrite_tag("%{$taxonomy}%", $tag, $args['query_var'] ? "{$args['query_var']}=" : "taxonomy={$taxonomy}&term=");
        add_permastruct($taxonomy, "{$args['rewrite']['slug']}/%{$taxonomy}%", $args['rewrite']);
    }
    // If not set, default to the setting for public.
    if (null === $args['show_ui']) {
        $args['show_ui'] = $args['public'];
    }
    // If not set, default to the setting for show_ui.
    if (null === $args['show_in_menu'] || !$args['show_ui']) {
        $args['show_in_menu'] = $args['show_ui'];
    }
    // If not set, default to the setting for public.
    if (null === $args['show_in_nav_menus']) {
        $args['show_in_nav_menus'] = $args['public'];
    }
    // If not set, default to the setting for show_ui.
    if (null === $args['show_tagcloud']) {
        $args['show_tagcloud'] = $args['show_ui'];
    }
    $default_caps = array('manage_terms' => 'manage_categories', 'edit_terms' => 'manage_categories', 'delete_terms' => 'manage_categories', 'assign_terms' => 'edit_posts');
    $args['cap'] = (object) array_merge($default_caps, $args['capabilities']);
    unset($args['capabilities']);
    $args['name'] = $taxonomy;
    $args['object_type'] = array_unique((array) $object_type);
    $args['labels'] = get_taxonomy_labels((object) $args);
    $args['label'] = $args['labels']->name;
    // If not set, use the default meta box
    if (null === $args['meta_box_cb']) {
        if ($args['hierarchical']) {
            $args['meta_box_cb'] = 'post_categories_meta_box';
        } else {
            $args['meta_box_cb'] = 'post_tags_meta_box';
        }
    }
    $wp_taxonomies[$taxonomy] = (object) $args;
    // register callback handling for metabox
    add_filter('wp_ajax_add-' . $taxonomy, '_wp_ajax_add_hierarchical_term');
    do_action('registered_taxonomy', $taxonomy, $object_type, $args);
}