Refactoring set_user_permissions custom function according to the changes in the core