Scenario:
Form ID = 24
Checkbox in form: Do you own a studio? Option: YES
Action needed:
If the user has selected YES that they own a studio, I'd like to then add the role STUDIO to their WP profile. Conversely, if YES is unchecked, I'd like to remove the STUDIO role if it exists for that user.
I found the code below as a start, but I am not sure where to go from here. I am new to PHP as I have not worked with it much in my development career. Playing catch up here.
Also, how would I invoke the snippet upon form update submission??
add_action( 'frm_after_create_entry', 'inactive_to_member', 20, 2 );
function inactive_to_member($entry_id, $form_id) {
if ( $form_id == 24 ) { // form id of the form to copy
$user = wp_get_current_user(); //get logged in user
if ( !$user ) {
return; //don't continue if user doesn't exist
}
// Get user roles
$user_roles = $user->roles;
NEED CONDITIONAL LOGIC HERE
//If studio checkbox is checked, ensure studio role is present
//if ( !in_array( 'studio', $user_roles ) ) {
// Add Role Studio
$user->set_role( 'studio' );
}
//If studio checkbox is unchecked, ensure studio role is not present
//if ( in_array( 'studio', $user_roles ) ) {
// Add Role Studio
$user->remove_role( 'studio' );
}
}
}
For updating use frm_after_update_entry, which is analogous to frm_after_create_entry:
add_action( 'frm_after_create_entry', 'inactive_to_member', 20, 2 );
add_action( 'frm_after_update_entry', 'inactive_to_member', 20, 2 );
function inactive_to_member($entry_id, $form_id) {
...
For the conditional logic: you want to get the field value from the entry and use that for comparison, e.g., $checkbox_value = FrmEntryMeta::get_entry_meta_by_field($entry_id, );
For general PHP issues, I suggest reaching out to a developer, as this is a Formidable support forum
https://formidable-masterminds.com/developers-directory/
You can find someone to mentor you on your journey
Please login or Register to submit your answer