wp_dropdown_roles() to replace option value = code
Question
I’m trying to replace a hardcoded dropdown list of roles in a plugin. Currently this is the code:
echo '<select name="xf_user_role_' . $id . '" id="xf_user_role_' . $id . '">';
?>
<option value='subscriber'
<?php echo ($xf_options['xf_user_role'][$id] == 'subscriber') ? "selected='yes'" : ''; ?> >Subscriber</option>
<option value='contributor'
<?php echo ($xf_options['xf_user_role'][$id] == 'contributor') ? "selected='yes'" : ''; ?> >Contributor</option>
<option value='author'
<?php echo ($xf_options['xf_user_role'][$id] == 'author') ? "selected='yes'" : ''; ?> >Author</option>
<option value='editor'
<?php echo ($xf_options['xf_user_role'][$id] == 'editor') ? "selected='yes'" : ''; ?> >Editor</option>
<option value='administrator'
<?php echo ($xf_options['xf_user_role'][$id] == 'administrator') ? "selected='yes'" : ''; ?> >Administrator</option>
</select>
This code is changed to :
echo '<select name="xf_user_role_' . $id . '" id="xf_user_role_' . $id . '">';
wp_dropdown_roles( );
?>
</select>
The dropdown list shows but selecting doesn’t give the $xf_options …
The wp_dropdown_roles isn’t well documented in the Codex page. I’ve tried a few different ways to add information into the () but am not getting it right.
What is the proper information for within the ()?
0
plugin-development, user-roles
4 years
2020-02-07T08:40:07-05:00
2020-02-07T08:40:07-05:00 0 Answers
92 views
0
Leave an answer