WordPress taxonomies gotcha.

The power and the responsibilities of the WordPress taxonomy system.

Taxonomies for users

Programmatically adding taxonomy terms to a post can be done using the function

wp_set_object_terms( $object_id, $terms, $taxonomy, $append = false );

The parameters are obvious and a look at the codex will explain that the object_id parameter might be, for example, the post ID.
No mention is made, probably on purpose, that the reason that parameter is not named post_id is that any “object” that has a unique ID in the WordPress environment can have a taxonomy assigned to it.

Taxonomies for users and other objects

Users do have a unique ID and the Users Group plugin is using a taxonomy to relate users to groups (terms of the user-group taxonomy).
Since the taxonomy system is agnostic of the object type and only cares for the object ID taxonomy terms can be similarly assigned to, say, comments, or any other object that is distinguishable from its siblings thanks to a unique ID; the possibility seems to be open to object stored and managed with custom tables too.
Taxonomies will probably have a role in WP_Query runs and there are only so many built-in queryable objects in the WordPress world so the usefulness limit might lay there.

Unique IDs

IDs will be unique on a specified table context: no two posts with the same ID, no two users with the same ID and so on.
IDs will not be unique across tables so I might have a taxonomy registered for posts and users

register_taxonomy('my_taxonomy', array('user','post'));

and assign both posts and users terms from that taxonomy

wp_set_object_terms(get_post_id(), array('term_one', 'term_two'), 'my_taxonomy');
wp_set_object_terms(get_current_user_id(), array('term_three','term_four') , 'my_taxonomy');

but the function taking charge of this assignment is the same.
This means that if, in the example above, the current post has an ID of 3 and the current user has an ID of 3 then calling the function

wp_get_object_terms('3', 'my_taxonomy', array('fields' => 'slugs'));

will yield the array

['term_one', 'term_two', 'term_three', 'term_four']

The gotcha

Given the example above while developing the User Gropus Content Restriction plugin, an extension to the content restriction framework WordPress plugin, I’ve run into some weird results while using the same taxonomy to assign terms to posts and users.
While figuring out the issue took some time I feel like having this possibility will be something I will leverage in the future; of course taking the responsibility of what I will assign taxonomy terms too.