Allows you to "share" or "synchronize" terms and term-relations between different taxonomies.
❗ This is still a work in progress!
When you create a taxonomy with register_taxonomy
you can assign (meta-)capabilities
. If you want to manage_terms
you need to be able to publish_posts
.
When you create a shared relation these capabilites
become actions
which can be synced. The default ones are: manage_terms
( 💖 when you create a term ), edit_terms
( 💘 when you update an existing term ), delete_terms
( 💔 when you delete a term) and assign_terms
(💞 when you assign an object_id
like a post or user to a term_taxonomy_id
). Sorry for the hearts, do you have better emojis?
(One/two way) Sync terms of different taxonomies.
- Example one way: You have two taxonomies:
animals
andpets
. Now you set up:pets
->💖💘💔->animals
. Whenever you add a pet (like "dog") it is also added to animals (we assume: "every pet is an animal"). - Example two way: You have users in different teams. You create taxonomies:
User-Team
(to assign users to teams) andPost-Team
(to assign posts to teams).UT
|PT
->💖💘💔->UT
|PT
. Whenever you create/edit/delete a team now (either in the taxPT
orUT
), the same change also applies to the other. (The extra mile) Write a filter: When a user in a shared taxonomy writes a post, the users's term is also assigned to the post. Only show posts, where users have the shared taxonomy and you have (nested) subgroups!
- ❗ Make a backup before you use this plugin! Use at your own risk.
- We (miss-)use a field in
wp_terms
calledterm_group
. It is meant for creating aliases in the same taxonomy. This plugin uses the field to identifyshared_terms
(wp_terms[slug]
is the fallback).- ❗ You might have collisions with plugins which also use the
term_group
(I never saw one). - ❗ The plugin might break, as there are plans to get rid of
wp_terms
- ❗ You might have collisions with plugins which also use the
- When you create a relation A[1,2,3]->B[1,2,4] and delete 1 from A it is also deleted in B. 4 will still exist in B.
-
Add a backend interface to add relations (it's currently only a class)
-
Write some tests, there is lots of edge-cases...
-
Hm, I guess we don't do this: (One/two way) Sync term-relations of different taxonomies. (‼ This is work in progress!)
Example: You have a big organisation where users are assigned to nested user-affiliations (which are taxonomies). You have three shared taxonomies:AAR
Automatically added roles (by your identity management)UAR
User-added roles (by the user herself)MR
Merged roles.
You setup the relation
AAR
|UAR
->💖💘💔💞->MR
Let the user write toUAR
and read fromMR
. This way all affiliations are preserved (and can also be removed), when changes inAAR
orUAR
occur.
- Sharing Taxonomies across multiple blogs.
- Think about handling terms with the same slug...
// These are slugs of taxonomies which have been registered with register_taxonomy
$taxonomies = array( 'post-affiliation', 'user-affiliation', 'blog-affiliation' );
$relation = new Shared_Taxonomies\Shared_Taxonomy_Relation(
$taxonomies, // source taxonomies.
$taxonomies, // destinatinon taxonomies.
array( 'manage_terms', 'edit_terms', 'delete_terms', 'assign_terms' ) // synced actions.
);
$manager = new Shared_Taxonomies\Shared_Taxonomy_Manager();
$manager->add( $relation ); // add all relations to the manager.
// manually sync all relations (just one in this example).
$manager->sync_all_shared_taxonomies( false );
Great that you ask. I tried that. This could be a PR for WordPress.
Imagine a drawer cabinet.
Original drawer desgin by upklyak / Freepik
One drawer is labeled "category". Another is "tag". Both are "taxonomies". So it is a type of "category". Those can be created in PHP with register_taxonomy.
The folders you put in your files are the terms. They are created in the WordPress backend.
The drawers contain posts by default. But you can put in anything with an ID (users, blogs, ...).