Last active
November 16, 2019 10:46
-
-
Save kish2011/c7a2e6559a8f64c813c532403cbdb824 to your computer and use it in GitHub Desktop.
Add user dropdown in formidableforms
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// call it in your theme or plugin function file. | |
wp_frm_populate_user_dropdown( 485, 'subscriber' ); // you can change field_id & role as per your need. | |
function wp_frm_populate_user_dropdown($field_id, $role = 'subscriber') { | |
$user_info = array ( 'field_id' => $field_id, 'role' => $role ); | |
add_filter('frm_setup_new_fields_vars', function ( $values, $field ) use ($user_info) { | |
$values = frm_populate_user_dropdown($values, $field, $user_info); | |
return $values; | |
}, 20, 2); | |
add_filter('frm_setup_edit_fields_vars', function ( $values, $field ) use ($user_info) { | |
$values = frm_populate_user_dropdown($values, $field, $user_info); | |
return $values; | |
}, 20, 2); | |
} | |
function frm_populate_user_dropdown($values, $field, $user_info) { | |
/** | |
* Detect plugin. For use on Front End only. | |
*/ | |
include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); | |
if ( $field->id == $user_info['field_id'] ) { | |
$role = $user_info['role']; | |
$users = get_users( array( 'role' => $role ) ); | |
$values['options'] = array( ); | |
foreach ( $users as $user ) { | |
$values['options'][] = array( | |
'label' => $user->display_name, | |
'value' => $user->ID | |
); | |
} | |
} | |
return $values; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment