Thanks Chris. I am just trying to put a little logic in the functions.php file. I am using gravity forms for user registration to a membership site plus purchasing a software product. Before, I only had 1 form to deal with when adding the custom capability. Now, I have multiple forms to deal with. Now that I think about it, my code design won't work the way I had envisioned it. Form 11 is used for purchasing a product, registering a user, and setting a custom capability in the user meta. Form 12 is purchasing the same product and setting the custom capability, but the user is already registered, so no registration is needed.
I currently use this code to set the custom capability when a user is registered:
add_action("gform_user_registered", "add_custom_user_meta", 10, 3);
function add_custom_user_meta($user_id, $config, $entry) {
if($entry['form_id'] != 11)
return;
wp_set_current_user( $user_id );
$user = wp_get_current_user();
$user->add_cap("access_s2member_ccap_creditexpertpro");
}
This works perfectly as long as the user is using form 11. So how would I fire the code when form 12 is complete? The user will be logged in when this form is used. It should happen after the paypal transaction is complete. I am thinking this should work:
add_action("gform_paypal_fulfillment", "process_order", 10, 4);
function process_order($entry, $config, $transaction_id, $amount) {
if($entry['form_id'] != 12)
return;
$user = wp_get_current_user();
$user->add_cap("access_s2member_ccap_creditexpertpro");
}
Last question. Lets say I need to add different capabilities based on the form id after a successful registration. How would I use the else - if statement to accomplish this (which my original thought when making this post). I tried to use the if elseif statement but obvisouly didn't format it correctly. I was going to add the the if statement into the function to it would always check during user registration. During registration, if one of the form numbers is use, it would set the custom capability as needed.
Hope this makes sense. Thanks for all your help.
Posted 13 years ago on Monday September 5, 2011 |
Permalink