Hello there. I am using Gravity forms and I am trying to add a custom capability to a user whenever the form is submitted. I’ve manage to achieve this with a Code snippet, added to the function.php, which works really well for a single form.
add_action("gform_user_registered", "add_custom_user_meta", 10, 3);
function add_custom_user_meta($user_id, $config, $entry) {
if($entry['form_id'] != 6)
return;
wp_set_current_user( $user_id );
$user = wp_get_current_user();
$user->add_cap ("access_s2member_ccap_test");
}
Now the problem I am having is making this code work for more than one form, and more than one custom cap. The code uses !=6 where 6 is the form ID, which means any form other than number 6 will be returned.I tried to change the code, but whatever I do it just does not work. I’m sure i am missing something,
Here is my attempt at a rewrite.
add_action("gform_user_registered", "add_custom_user_meta", 10, 3);
function add_custom_user_meta($user_id, $config, $entry)
{
if($entry['form_id'] == 1)
{return wp_set_current_user( $user_id );
$user = wp_get_current_user();
$user->add_cap ("access_s2member_ccap_test1");}
else if($entry['form_id'] == 2)
{wp_set_current_user( $user_id );
$user = wp_get_current_user();
$user->add_cap ("access_s2member_ccap_test2");}
else
{return;}
}
if anyone know how I might get it to work on more than 1 form for more than 1 ccap then I’m all ears.
Thanks for your help