Hi
I decided to use formidable to avoid writing codes, yet still need to write a few. Anyway, I created a snippet to set the user role during registration based on the drop-down, but nothing happens, still the role selected in form settings applies.
Do I need to copy the short code from PHP to the page where my form is?
I followed this KB - https://formidableforms.com/knowledgebase/user-registration/#kb-set-the-user-role
And created the below snippet
add_filter('frmreg_new_role', 'frmreg_new_role', 10, 2);
function frmreg_new_role($role, $atts){
if ( $atts['form']->id == 46 && isset( $atts['entry'] ) ) {
$field_val = FrmProEntriesController::get_field_value_shortcode( array( 'field_id' => 604, 'entry_id' => $atts['entry']->id, 'show' => 'value' ) );
if ( $field_val == 'Author' ) {
$role = 'author';
} else if ( $field_val == 'editor' ) {
$role = 'editor';
}
}
return $role;
}
I was wondering why you referred to a shortcode. You can't so this via a shortcode and, no offense, I'm not sure you understand how shortcode work. To solve your issue, just use frm_after_create_entry - https://formidableforms.com/knowledgebase/frm_after_create_entry/#sts=Change%20user%20role%20after%20entry%20submission
Hello again
I create a new snippet using your code and changed the $form_id to 46 and $new_role to my drop-down id still nothing happened, I then changed $new_role to editor still nothing happened!
Is there anything else besides a form and a PHP snippet for implementing this code?
That code does exactly that you want it to do so you'll need to debug it. By putting in debug output, you'll be able to make sure that the function is being called, that all the values are what you think they are and that wp_update_user returns the user id you're updating.
Got it working! The PHP location was set to nothing. Thanks a ton for your help - it made all the difference!
Please login or Register to submit your answer