WordPress bulk category select when publishing post

The default function that renders the categories meta box is post_categories_meta_box – it doesn’t have any internal hooks we can use to inject our own HTML, so let’s create our own meta box handler and just use the function internally:

function wpse_406861_post_categories_meta_box( $post, $args ) {
    post_categories_meta_box( $post, $args );

    echo <<<HTML
<label>
    <input type="checkbox" onchange="this.parentElement.parentElement.querySelectorAll('.categorychecklist input[type=checkbox]').forEach(checkbox => checkbox.checked = this.checked);" />
    Select all
</label>
HTML;
}

This just adds a simple checkbox at the bottom of the default meta box, with a bit of JS that toggles all the term checkboxes inside it.

And to set this as the default meta box handler for all hierarchical taxonomies, we can use the hook register_taxonomy_args to override the arguments passed to any register_taxonomy call:

add_filter( 'register_taxonomy_args', function ( $args ) {
    if ( ! empty( $args['hierarchical'] ) && empty( $args['meta_box_cb'] ) ) {
        $args['meta_box_cb'] = 'wpse_406861_post_categories_meta_box';
    }

    return $args;
});