add_filter('frm_where_filter', 'my_unique_name_filter_custom_display', 10, 2);
function my_unique_name_filter_custom_display($where, $args){
	$view_id = bsn_get_post_id_from_slug('slug-of-view'); // replace 'slug-of-view' with your view slug
	$field_id = bsn_get_field_id_from_key('field-key'); // replace 'field-key' with your field's key
	if ( $args['display']->ID == $view_id && $args['where_opt'] == $field_id){ 
		$user_id = $_GET['trainer']; // change trainer to the name of the parameter in your URL
		if ( !is_numeric($user_id) ) {
			// if the username was in the url, get the ID
			$user_id = FrmProAppHelper::get_user_id_param($user_id);
		}
		if ( is_numeric($user_id) ) {
			$where = ("meta_value = ". $user_id ." and fi.id='". $args['where_opt'] ."'");
		} else {
			// no matching user ID was found
			$where = ("meta_value = 1 and meta_value = 0 and fi.id='". $args['where_opt'] ."'");
		}
	}
	return $where;
}

if (!function_exists('bsn_get_post_id_from_slug')) {
	function bsn_get_post_id_from_slug($slug) {
		global $wpdb;
		$id = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_name = '$slug'");
		return $id;
	}
}

if (!function_exists('bsn_get_field_id_from_key')) {
	function bsn_get_field_id_from_key($field_key) {
		global $frmdb, $wpdb;
		$field_id = $wpdb->get_var("SELECT id FROM $frmdb->fields WHERE field_key LIKE '".$field_key."'");
		return $field_id;
	}
}

[vc_row][vc_column][vc_column_text]Use this code to change a user’s role after he/she submits an entry in a specific form.

/**
* 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 == 24){ //change 24 to the form id of the form to copy
	$new_role = 'member'; //change this to the role users should be granted upon completing form

	$user = wp_get_current_user(); //get logged in user
	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);
	}
}

[/vc_column_text][/vc_column][/vc_row]

Subscribe To Our Newsletter

Join our mailing list to receive the latest news and updates from our team.

Email sending image

You have Successfully Subscribed!