For one of my plugins I need to add a multiselect to my plugin options, but the options in the multiselect are dynamic (autogenerated from the given site’s user roles).
$this->settings['manageraccess'] = array(
'section' => 'manager',
'title' => __('Manager Mode Access'),
'desc' => __(''),
'type' => 'manageraccess',
'std' => '',
'dflt' => '',
'helplink'=> 'yes',
'submit' => 'yes'
);
Normally I would add:
'choices' => array(
'op1' => 'Option 1',
'op2' => 'Option 2',
),
to the above array, but I need to generate them dynamically, like I do in my select box. My field case looks like this:
case 'manageraccess':
global $wp_roles;
$all_roles = $wp_roles->roles;
$editable_roles = apply_filters('editable_roles', $all_roles);
echo '<select multiple="multiple" class="select chozed-select' . $field_class . '" name="myplugin_options[' . $id . '][]" data-placeholder=" ">';
foreach($editable_roles as $role=>$theroles){
echo '<option value="' . esc_attr($role) . '" '.selected($options[$id], $role, false) . '>'.$wp_roles->role_names[$role].'</option>';
}
echo '</select>' . $helplink;
if ($desc != '')
echo '<br /><div class="ssfa-description">' . $desc . '</div>';
if ($submit != null)
echo '<br /><br /><br />'.$submit;
break;
Well I figured it out.