Skip to content

Instantly share code, notes, and snippets.

@arjenblokzijl
Last active May 30, 2016 07:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arjenblokzijl/5ee880474f59391a640f975d8fa300b4 to your computer and use it in GitHub Desktop.
Save arjenblokzijl/5ee880474f59391a640f975d8fa300b4 to your computer and use it in GitHub Desktop.
ProcessWire duplicate role with permissions and field access
<?php namespace ProcessWire;
include('index.php');
$contractingRole = wire('roles')->get('contracting-user');
$managerRole = wire('roles')->get('manager');
$managerRole->of(false);
$managerRole->permissions = $contractingRole->permissions;
$managerRole->save();
foreach (wire('fields') as $f) {
if (in_array($contractingRole->id, $f->viewRoles)) {
$array = $f->viewRoles;
$array[] = $managerRole->id;
$f->viewRoles = $array;
$f->save();
}
echo $f->name;
echo "<hr>";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment