A third-party plugin adds the capability 'edit_booked_appointments'. I'd like to assign this capability to the already existing user role 'editor'. I created the following function in my child theme:
function add_booking_role_to_editor() {
$role = get_role( 'editor' );
$role->add_cap( 'edit_booked_appointments', true );
}
add_action( 'init', 'add_booking_role_to_editor');
As far as I understand the whole topic, user roles get written to the database so there is no need to hook this function into the 'init' action. What would be the correct way to do this? Is there a way to fire this once, after the corresponding plugin has been activated? I tried it with the action 'plugins_loaded' but that did not work at all.