members
members copied to clipboard
Enhancement - import/export roles
Hi Justin,
Question / Enhancement - Is it possible to add a functionality to export/import roles?
I've never really looked into it. I think it'd be a cool idea. Patches are welcome!
And sync roles between sites in Multisite install :+1:
Would love to see a way to export the code required for adding to the codebase, i.e. Advanced Custom Fields Pro or WP Forms.
Just thinking this through a bit in my head. One question that popped up was with what to do with duplicates.
For example, let's say you already have an administrator role on the site. Then, you import a set of roles that also has the administrator role. How is this scenario best handled?
- Imported role overwrites that on the site.
- Existing site role takes precedence.
- Merge the two role's capabilities (also a question of which caps take precedence in cases of granted and denied caps).
- Provide a checkbox for one or the other to win.
Any other ideas?
I would rather see the hardcoded / code based code would take higher precedence.
That's the way ACF handles it, and then if the hardcoded role disappears the DB based one takes over.
There wouldn't be anything hardcoded. We're talking about importing roles into the DB.
Just a question: is the configuration for roles currently not saved in the database? If no, where is it being saved?
Will have a think. Am wondering if would be best to potentially give a warning though - so any differences asking the user if they want to overwrite?
A warning is definitely in order regardless of how it's handled.
I've taken a small look at some of the under-the-hood code for this. A complete overwrite is easiest from a code perspective (delete all existing roles and replace with imported roles).
I'd probably lean toward something like the following as a set of rules:
- Imported roles that don't exist, get created.
- Imported roles that already exist overwrite the existing roles.
- Existing roles not in the import are left untouched.
How realistic that is will likely take diving into the code.