Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
add_action('frm_after_update_entry', 'update_user_role', 10, 2);
function update_user_role($entry_id, $form_id){
if ( $form_id == 4 ) {
$userid = $_POST['item_meta'][15];// ID of the userID field
$role = $_POST['item_meta'][19];// ID of the role field
if ( $userid && $role ) {
$user = get_userdata( $userid );
if ( $user && ! $user->has_cap('administrator') ) {
$user->set_role( $role );
}
}
}
}
<?php
add_action('frm_after_update_field', 'frm_trigger_entry_update');
function frm_trigger_entry_update($atts){
$userid_field= '15';
$entry = FrmEntry::getOne( $atts['entry_id'], true );
$userid = FrmEntryMeta::get_meta_value( $entry, $userid_field );
$role = $atts['value'];
if ( $userid && $role ) {
update_wordpress_user_role( $userid, $role );
}
$form = FrmForm::getOne( $entry->form_id );
FrmFormActionsController::trigger_actions('update', $form, $entry, 'email');
}
<?php
add_action('frm_after_update_entry', 'update_user_role', 10, 2);
function update_user_role($entry_id, $form_id){
if ( $form_id == 4 ) {
$userid = $_POST['item_meta'][15];// ID of the userID field
$role = $_POST['item_meta'][19];// ID of the role field
if ( $userid && $role ) {
update_wordpress_user_role( $userid, $role );
}
}
}
<?php
function update_wordpress_user_role( $userid, $role ) {
$user = get_userdata( $userid );
if ( $user && ! $user->has_cap('administrator') ) {
$user->set_role( $role );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment