Here’s a workaround specific for the post tags meta box.
We can register a custom metabox callback for the post_tag
taxonomy with:
add_filter( 'register_taxonomy_args', function( $args, $taxonomy )
{
// Replace the original (post_tag) metabox callback with our wrapper
if( 'post_tag' === $taxonomy )
$args['meta_box_cb'] = 'wpse_post_tags_meta_box';
return $args;
}, 10, 2 );
where our custom callback is e.g.:
function wpse_post_tags_meta_box( $post, $box )
{
// Custom action
do_action( 'wpse_before_post_tags_meta_box', $post, $box );
// Original callback. Note it will echo the stuff, not return it
post_tags_meta_box( $post, $box );
}
Now we can hook into the custom wpse_before_post_tags_meta_box
hook when needed.
If we need to inject something inside the post_tags_meta_box()
function, then we might try using output buffering to work with it as a string. It’s also possible to duplicate that function, but that function could easily change in the future! So I would avoid that if possible.