Taxonomy: Introduce unregister_taxonomy().

This new function can be used to completely unregister non built-in taxonomies.

Fixes #35227.
Built from https://develop.svn.wordpress.org/trunk@36243


git-svn-id: http://core.svn.wordpress.org/trunk@36210 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Pascal Birchler 2016-01-09 14:58:26 +00:00
parent d591f26ce7
commit 710501dc53
2 changed files with 57 additions and 1 deletions

View File

@ -475,6 +475,62 @@ function register_taxonomy( $taxonomy, $object_type, $args = array() ) {
do_action( 'registered_taxonomy', $taxonomy, $object_type, $args );
}
/**
* Unregister a taxonomy.
*
* Can not be used to unregister built-in taxonomies.
*
* @since 4.5.0
*
* @global WP $wp Current WordPress environment instance.
* @global array $wp_taxonomies List of taxonomies.
*
* @param string $taxonomy Taxonomy name.
* @return bool|WP_Error True on success, WP_Error on failure.
*/
function unregister_taxonomy( $taxonomy ) {
if ( ! taxonomy_exists( $taxonomy ) ) {
return new WP_Error( 'invalid_taxonomy', __( 'Invalid Taxonomy' ) );
}
$taxonomy_args = get_taxonomy( $taxonomy );
// Do not allow unregistering internal taxonomies.
if ( $taxonomy_args->_builtin ) {
return new WP_Error( 'invalid_taxonomy', __( 'Unregistering a built-in taxonomy is not allowed' ) );
}
global $wp, $wp_taxonomies;
// Remove query var.
if ( false !== $taxonomy_args->query_var ) {
$wp->remove_query_var( $taxonomy_args->query_var );
}
// Remove rewrite tags and permastructs.
if ( false !== $taxonomy_args->rewrite ) {
remove_rewrite_tag( "%$taxonomy%" );
remove_permastruct( $taxonomy );
}
// Unregister callback handling for metabox.
remove_filter( 'wp_ajax_add-' . $taxonomy, '_wp_ajax_add_hierarchical_term' );
// 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;
}
/**
* Builds an object with all taxonomy labels out of a taxonomy object
*

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.5-alpha-36242';
$wp_version = '4.5-alpha-36243';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.