How to programmatically set role based permissions on a field?
Ok, worked this one out...

I created my own function to do this, which I have called in the MY_MODULE.install file, as I'm creating the fields there, and as I understand, you can't set permissions in the install file.

Note, this is just a custom function name, not a hook - you could call it anything.

function MY_MODULE_assign_field_permissions($role_name, $permission, $field_name) {
    $permissions = array($permission.' '.$field_name)
    $role = user_role_load_by_name($role_name);
    user_role_grant_permissions($role-&gt;rid, $permissions);
}


$role_name is the name of your role, $permission is the natural language permission, like 'view own', 'create', 'edit', etc. and finally $field_name is the name you gave your field.

Here's how I would call it in my MY_MODULE.install file to allow the role type my_role view their own entries for field_my_field:

MY_MODULE_assign_field_permissions('my_role', 'view own', 'field_my_field');