Copy permissions between roles

Public

Get raw version
php
  1. /**
  2.  * Custom function for copying one role's perms to another
  3.  */
  4. function MY_MODULE_copy_permissions($from, $to) {
  5. $from_role = user_role_load_by_name($from);
  6. $to_role = user_role_load_by_name($to);
  7. if ($from_role && $to_role) {
  8. $permissions_from = user_role_permissions(array($from_role->rid => $from));
  9. $permissions_array = array();
  10. foreach ($permissions_from as $rid => $permission) {
  11. foreach ($permission as $name => $value) {
  12. $permissions_array[] = $name;
  13. }
  14. }
  15. user_role_grant_permissions($to_role->rid, $permissions_array);
  16. }
  17. }