Proper way to update the slug of a taxonomy using register_taxonomy? [duplicate]

register_taxonomy triggers the action registered_taxonomy immediately after it’s registered, which gives you the arguments it was registered with. As long as the taxonomy key doesn’t change, you can hook that action, modify the arguments, then re-register it.

function wpd_update_taxonomy_args( $taxonomy, $object_type, $args ){
    if( 'plugin_tax' == $taxonomy ){

        // remove this action so we don't create an infinite loop!
        remove_action( current_action(), __FUNCTION__ );

        // change arguments
        $args['rewrite'] = array( 'slug' => 'foobar' );

        // re-register
        register_taxonomy( $taxonomy, $object_type, $args );
    }
}
add_action( 'registered_taxonomy', 'wpd_update_taxonomy_args', 10, 3 );