members icon indicating copy to clipboard operation
members copied to clipboard

Enhancement - import/export roles

Open danbalbo opened this issue 9 years ago • 9 comments

Hi Justin,

Question / Enhancement - Is it possible to add a functionality to export/import roles?

danbalbo avatar Mar 02 '15 11:03 danbalbo

I've never really looked into it. I think it'd be a cool idea. Patches are welcome!

justintadlock avatar Mar 02 '15 20:03 justintadlock

And sync roles between sites in Multisite install :+1:

korobochkin avatar Jun 18 '15 13:06 korobochkin

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.

AaronHolbrook avatar Jun 22 '17 20:06 AaronHolbrook

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?

justintadlock avatar Jun 29 '17 19:06 justintadlock

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.

AaronHolbrook avatar Jun 29 '17 19:06 AaronHolbrook

There wouldn't be anything hardcoded. We're talking about importing roles into the DB.

justintadlock avatar Jun 29 '17 19:06 justintadlock

Just a question: is the configuration for roles currently not saved in the database? If no, where is it being saved?

warudin avatar Dec 15 '17 13:12 warudin

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?

theo-ct avatar Jan 24 '19 19:01 theo-ct

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.

justintadlock avatar Jan 28 '19 21:01 justintadlock