WordPress at a glance

unregister_taxonomy() WP 1.0

Unregisters a taxonomy.

Can not be used to unregister built-in taxonomies.

  • Global. WP. $wp Current WordPress environment instance.
  • Global. Array. $wp_taxonomies List of taxonomies.
✈ 1 time = 0.000039s = very fast | 50000 times = 0.89s = very fast PHP 7.0.5, WP 4.5

No Hooks.

Return

true/false/WP_Error. True on success, WP_Error on failure or if the taxonomy doesn't exist.

Usage

unregister_taxonomy( $taxonomy );
$taxonomy(string) (required)
Taxonomy name.

Code of unregister_taxonomy: wp-includes/taxonomy.php VER 5.0.1

<?php
function unregister_taxonomy( $taxonomy ) {
	if ( ! taxonomy_exists( $taxonomy ) ) {
		return new WP_Error( 'invalid_taxonomy', __( 'Invalid taxonomy.' ) );
	}

	$taxonomy_object = get_taxonomy( $taxonomy );

	// Do not allow unregistering internal taxonomies.
	if ( $taxonomy_object->_builtin ) {
		return new WP_Error( 'invalid_taxonomy', __( 'Unregistering a built-in taxonomy is not allowed.' ) );
	}

	global $wp_taxonomies;

	$taxonomy_object->remove_rewrite_rules();
	$taxonomy_object->remove_hooks();

	// Remove the taxonomy.
	unset( $wp_taxonomies[ $taxonomy ] );

	/**
	 * Fires after a taxonomy is unregistered.
	 *
	 * @since 4.5.0
	 *
	 * @param string $taxonomy Taxonomy name.
	 */
	do_action( 'unregistered_taxonomy', $taxonomy );

	return true;
}

Related Functions

From category: Any taxonomy

No comments
    Hello, !     Log In . Register