Hi Stephanie..
Its been a while since i have had to impose on you for help. Generally things have been going smoothly and the new updates have been great improvements. Thanks as always.
I am attempting to assign a new role when users update their profile using formidable form using the following code.
add_filter(‘frm_after_update_entry’, ‘after_vendor_entry_updated’, 20, 2);
function after_vendor_entry_updated($entry_id, $form_id){
global $wpdb, $frmdb;
if($form_id == 12){ // change ID to the ID of reg. form on each site in multisite
$useremail = $_POST['item_meta'][235];
$userid = get_user_id_from_string($useremail);
$theuser = new WP_User( $userid );
$theuser->set_role(‘vendor’);
$theuserrole = $theuser->roles[0];
}
}
I user a similar function when an existing email address is entered during registration that works fine.
add_filter(‘frm_validate_field_entry’, ‘check_email_error’, 25, 3);
function check_email_error($errors, $field, $value){
global $wpdb, $frmdb;
if($field->id == 235){ //change 25 to the ID of your email field
if(isset($errors['field'.$field->id]) and $errors['field'.$field->id] == ‘This email address is already registered.’){
$errors['field'.$field->id] = $_POST['item_meta'][235];
$useremail = $_POST['item_meta'][235];
$userid = get_user_id_from_string($useremail);
$theuser = new WP_User( $userid );
$theuser->set_role(‘vendor’);
$errors['field'.$field->id] = ‘ This email address is already registered<br>Please use the form on the right to login</a>’;
}
}
return $errors;
}
I cannot for the life of me figure out why the first does not work and the second does. the form ID is in fact 12… the user email field is 235. Any thoughts at all.. ? It almost seems as if the function is not firing..
If I have other calls to frm_after_update_entry hook.. would this interfere with this one? I am doing a redirect after the data is saved, could this impact the firing of this function?
Any help greatly appreciated.
Rob




February 14, 2012 at 11:00 am
If you are redirecting on the same hook, then you may be redirecting before that other function is reached. Also, that should be add_action instead of add_filter for the frm_after_update_entry hook. Please refer to the codex for instructions on changing the priority hooks are fired in.
http://codex.wordpress.org/Function_Reference/add_action
February 14, 2012 at 1:11 pm
Hi Stephanie..
Thanks for the catch in the function.. duh.. right, add-action. I have made adjustments and played around with the priority from 1 through 60 to no avail. I just cant seem to get this function to fire (I think).
I have tried temporarily disabling the $form_id == 12 test thereby hoping to make it fire on ANY form update. again.. to no avail
I went into the form settings and changed the "redirect to URL" to a simple "Display a message", still cannot seem to get the set_role code to fire
function after_vendorupdate($entry_id, $form_id){
global $wpdb, $frmdb;
if($form_id == 12){
$useremail = $_POST['item_meta'][235];
$userid = get_user_id_from_string($useremail);
$theuser = new WP_User( $userid );
$theuser->set_role('vendor');
}
}
add_action('frm_after_update_entry','after_vendorupdate',35,2);
I am going to go try this on another site in the network, but in the meantime, have you ever came across a situation where formidable frm_after_update_entry hook runs into problems?
February 14, 2012 at 2:00 pm
That hook will always fire when an entry is updated. There is nothing there to possibly stop it from firing, unless you have other custom code that causes an error. Maybe try turning on debug mode.
July 17, 2012 at 5:41 am
try 'frm_after_create_entry' instead of the 'frm_after_update_entry' hook
Since you might be setting a new entry instead of updating an existing one ....
Topic closed.