WordPress.org

Make WordPress Core

Ticket #11058: unregister_taxonomy_for_object_type.patch

File unregister_taxonomy_for_object_type.patch, 1.1 KB (added by leewillis77, 8 years ago)

I added a proposed implementation for unregister_taxonomy_for_object_type on #14482 (Which has been closed as a dupe of this bug). There was an issue with the patch I provided on that bug, so revised patch is attached here.

  • wp-includes/taxonomy.php

    diff -ru orig/wp-includes/taxonomy.php new/wp-includes/taxonomy.php
    old new  
    397397        return true;
    398398}
    399399
     400/**
     401 * Remvoe an already registered taxonomy from an object type.
     402 *
     403 * @package WordPress
     404 * @subpackage Taxonomy
     405 * @since 3.0.2
     406 * @uses $wp_taxonomies Modifies taxonomy object
     407 *
     408 * @param string $taxonomy Name of taxonomy object
     409 * @param string $object_type Name of the object type
     410 * @return bool True if successful, false if not
     411 */
     412function unregister_taxonomy_from_object_type($taxonomy, $object_type) {
     413
     414        global $wp_taxonomies;
     415
     416        if ( !isset($wp_taxonomies[$taxonomy]) )
     417                return false;
     418
     419        if ( ! get_post_type_object($object_type) )
     420                return false;
     421
     422        foreach (array_keys($wp_taxonomies['category']->object_type) as $array_key) {
     423                if ($wp_taxonomies['category']->object_type[$array_key] == $object_type) {
     424                        unset ($wp_taxonomies['category']->object_type[$array_key]);
     425                        return true;
     426                }
     427        }
     428        return false;
     429
     430}
    400431//
    401432// Term API
    402433//