#35227 closed defect (bug) (fixed)
Add unregister_taxonomy()
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 4.5 | Priority: | normal |
| Severity: | normal | Version: | 2.3 |
| Component: | Taxonomy | Keywords: | has-unit-tests has-patch commit |
| Focuses: | Cc: |
Description
This is a follow-up to #11058.
While working on #14761 I stumbled upon the former ticket suggesting adding a unregister_taxonomy() function. It ended up with the addition of a new register_taxonomy_for_object_type() function.
Since _unregister_taxonomy() is used across all unit tests, I think we should add a real function for this for developers.
From Nacin's comment from three years ago:
An
unregister_taxonomy()function needs to un-roll quite a bit:
- Remove the query var from the
WPclass, if one was registered.- Remove any rewrite tags and permastructs.
- Remove the callback for handling the meta box.
An
unregister_taxonomy()function should disallow the unregistration of 'post_tag' and 'category' until core does not assume they exist in many, many locations. The same block might also need to be in place inunregister_taxonomy_for_object_type()for the 'post' object type until core no longer breaks under any existing assumptions as well.
I'm gonna work on this together with #14761.
Attachments (3)
Change History (12)
#1
@
10 years ago
- Keywords has-patch has-unit-tests dev-feedback added; needs-patch needs-unit-tests removed
#3
follow-up:
↓ 4
@
10 years ago
- Keywords needs-patch added; early has-patch dev-feedback removed
@swissspidy A few thoughts, in no particular order:
- Docblock description for
WP_Rewrite::remove_rewrite_tag()is copied fromadd_rewrite_tag()and needs to be updated. - After unsetting array values in
remove_rewrite_tag(), we could have gaps in the numerical array keys (ie: 0, 1, 3, 4). Does this matter? Worth resetting indexes usingarray_values()afterunset()ing? - Personal preference, but I'd say that with a new function (and no backward compatibility concerns) we should be returning descriptive
WP_Errorobjects on various failures inunregister_taxonomy(). - Between this ticket and #14761, it's probably worth adding a
WP::remove_query_arg()helper. - Similarly, I'd prefer a
remove_permastruct()method to reaching into$wp_rewrite's public properties. register_taxonomy()adds a specific callback to'wp_ajax_add-' . $taxonomy, but when unregistering, youremove_all_actions(). Perhaps it's wiser to be conservative here and only undo the specificadd_action()fromregister_taxonomy().- In the test suite, don't remove
_unregister_taxonomy(). Just make it a wrapper. Plugins are using it.
Looks like you have pretty well covered the various pieces of register_taxonomy() aside from these issues.
#4
in reply to:
↑ 3
@
10 years ago
- Keywords has-patch added; needs-patch removed
Replying to boonebgorges:
Thanks for your feedback so far! I incorporated it in the latest patch.
I created new tickets for adding the individual helper methods:
35227.2.diff relies on these patches, making this one much more readable.
After unsetting array values in
remove_rewrite_tag(), we could have gaps in the numerical array keys (ie: 0, 1, 3, 4). Does this matter? Worth resetting indexes usingarray_values()afterunset()ing?
I see no harm in not re-indexing the arrays.
#5
@
10 years ago
35227.2.diff is looking good - so much lovelier with the new functions :) Once those other tickets are landed, I think this one is good to go.
#6
@
10 years ago
- Keywords commit added
After the other tickets landed, I slightly updated the unit tests in 35227.3.diff to make them easier to read. Adds a new test_unregister_taxonomy_removes_permastruct() test.
35227.diff adds the same
remove_rewrite_tag()function as the patch in #14761 and does the following:$wp_taxonomiesglobal