WordPress 5.1 will feature a new parameter for register_taxonomy()
, 'meta_box_sanitize_cb'
, which increases flexibility when using core UI for custom taxonomies.
Custom taxonomies can specify which metabox UI they’d like to use in the Classic Editor by providing a meta_box_cb
parameter when registering their taxonomies. This meant, for example, that a hierarchical taxonomy can choose to use the post_tags_meta_box()
UI instead of post_categories_meta_box()
, which is the default. Prior to 5.1, this customization wasn’t fully functional; while the UI could be swapped out in this way, the data submitted when saving posts was always processed according to whether the taxonomy was registered as hierarchical. This led to scenarios where custom taxonomy values weren’t properly parsed when saving a post.
In 5.1, this behavior is changed in the following ways:
- The POST controller logic that was previously hardcoded in
edit_post()
has been abstracted into the new taxonomy_meta_box_sanitize_cb_checkboxes()
and taxonomy_meta_box_sanitize_cb_input()
functions.
- WP will try to select an appropriate
_sanitize_
callback based on the meta_box_cb
associated with the taxonomy. This will fix the underlying bug for existing taxonomies.
- Developers who need more control over the processing of their metabox data can provide a custom
meta_box_sanitize_cb
when registering their taxonomies.
For more information, see #36514 and [42211].
#5-1, #dev-notes, #taxonomy