Display and change UserID in a dropdown on the front-end for other than admin

Est. Reading: 1 minute
By: juliushg
Created: 01/09/2018
Category:
Difficulty: Intermediate

Display and change UserID in a dropdown on the front-end for other than admin

×Warning: This tutorial was created 2470 days ago. Some of the information may be out of date with more recent versions of Formidable. Please proceed with caution and always perform a backup before adding custom code.

The way is to add the filter that was listed in frm_setup_new_fields_vars, to display the UserID in the dropdown for admins. One can add another filter with the following alteration to the code, in this case for the Editor role:

add_filter('frm_setup_new_fields_vars', 'show_user_dropdown_editor', 15, 2);
add_filter('frm_setup_edit_fields_vars', 'show_user_dropdown_editor', 15, 3);
function show_user_dropdown_editor($values, $field, $entry_id=false){
  if ( $values['type'] == 'user_id' && !is_admin() && current_user_can('editor') ){
       $values['type'] = 'select';
       $values['options'] = FrmProFieldsHelper::get_user_options();
       $values['use_key'] = true;
       $values['custom_html'] = FrmFieldsHelper::get_default_html('select');
  }
return $values;
}

And of course, the original code is for the admin:

add_filter('frm_setup_new_fields_vars', 'show_user_dropdown', 15, 2);
add_filter('frm_setup_edit_fields_vars', 'show_user_dropdown', 15, 3);
function show_user_dropdown($values, $field, $entry_id=false){
  if ( $values['type'] == 'user_id' && !is_admin() && current_user_can('administrator') ){
       $values['type'] = 'select';
       $values['options'] = FrmProFieldsHelper::get_user_options();
       $values['use_key'] = true;
       $values['custom_html'] = FrmFieldsHelper::get_default_html('select');
  }
return $values;
}

With both codes the Administrator and Editor roles will see the dropdown to change the UserID for any entry, on the front-end. This must work for other roles as well.

Leave a Reply

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crosschevron-leftchevron-rightarrow-right