hello
i have 3 roles in my site
subscrirer
contributor
valide
i need to update role when my user update/create entry
i have a field (id 19 radio Oui/Non) inside this form and role is depend to this
i add this code in function
/**
* This will change an inactive user to a member after they complete their member profile.
*/
add_action('frm_after_create_entry', 'inactive_to_member', 20, 2);
function inactive_to_member($entry_id, $form_id){
if($form_id == 4){ //my form id
$new_role = ''; //change this to the role users should be granted upon completing form
$handicap = $_POST['item_meta'][19];
if ($handicap == 'Oui') {
$new_role = "contributor";
} elseif ($handicap == 'Non'){
$new_role = "valide";
}
$user = wp_get_current_user(); //get logged in user
error_log( $user );
error_log( $new_role );
if(!$user) {
return; //don't continue if user doesn't exist
}
$updated_user = (array)$user;
// Get the highest/primary role for this user
$user_roles = $user->roles;
$user_role = array_shift($user_roles);
if ( $user_role == 'administrator' )
return; //make sure we don't downgrade any admins
$updated_user['role'] = $new_role;
wp_update_user($updated_user);
}
}
But nothing was happend and i don't understand why i have anything in error_log
thanks for any help ?
regards
Based on the code above, ff there's nothing in your WP Debugging log file, either WP Debugging isn't turned on correctly or the ID of the form you're interested in isn't 4. You'll have to dig deeper to find the root of the current issue.
hello thanks for your return
i found
need to add create and update
add_action('frm_after_create_entry', 'inactive_to_member', 20, 2);
add_action('frm_after_update_entry', 'inactive_to_member', 20, 2);
frm_after_create_entry should fire with a priority of 30, not 20. You may be firing it too early in the process. See this: https://formidableforms.com/knowledgebase/frm_after_create_entry/
I would also add some additional logging or debugging messages to your code.
Please login or Register to submit your answer