I created a simple wordpress plugin today which is essentially an options page. It is based on the instructions at this link: http://codex.wordpress.org/Creating_Options_Pages (there is example code at the bottom of that page which I used as the backbone for my plugin).
Basically, I want authors/contributors to be able to see a new tab in their admin menu, which when clicked, would take the user to a page where he/she can write some text and hit "save changes" (which would then save that text to a database). I want to later be able to call this text via something like get_option('some_option').
However, authors/contributors cannot "manage_options" & this prevented them from editing the options on the new menu tab I created. I installed a plugin called "User Role Editor" to allow authors/contributors to manage_options, but this brings the "Settings" tab in their admin menu and allows them to manage all options.
How can I allow authors/contributors to only manage_options for the plugin I created and nothing else? Can I lift permission restrictions for the plugin I created? Any guidance would be appreciated! (The plugin development went smooth but now I'm stuck).
My code is pretty much analogous to the example found in the link given above:
<?php
add_action('admin_menu', 'baw_create_menu');
function baw_create_menu() {
//create new top-level menu
add_menu_page('BAW Plugin Settings', 'BAW Settings', 'edit_posts', 'my-plugin', 'baw_settings_page');
//call register settings function
add_action( 'admin_init', 'register_mysettings' ); }
function register_mysettings() {
//register our settings
register_setting( 'baw-settings-group', 'new_option_name' );
register_setting( 'baw-settings-group', 'some_other_option' );
register_setting( 'baw-settings-group', 'option_etc' ); }
function baw_settings_page() { ?> <div class="wrap"> <h2>Plugin Name</h2>
<form method="post" action="options.php">
<?php settings_fields( 'baw-settings-group' ); ?>
<?php do_settings( 'baw-settings-group' ); ?>
<table class="form-table">
<tr valign="top">
<th scope="row">New Option Name</th>
<td><input type="text" name="new_option_name" value="<?php echo get_option('new_option_name'); ?>" /></td>
</tr>
<tr valign="top">
<th scope="row">Some Other Option</th>
<td><input type="text" name="some_other_option" value="<?php echo get_option('some_other_option'); ?>" /></td>
</tr>
<tr valign="top">
<th scope="row">Options, Etc.</th>
<td><input type="text" name="option_etc" value="<?php echo get_option('option_etc'); ?>" /></td>
</tr>
</table>
<?php submit_button(); ?>
</form> </div> <?php } ?>
do_settings
, butdo_settings_fields
. 2) You are developing withoutWP_DEBUG
enabled, otherwise you'd see thatdo_settings_fields( 'baw-settings-group' );
dumps an error because there's an argument missing. 3) If you are doing theadd_menu_page
withedit_posts
capabilities, it shows up for the desired roles without need of modifying the role. Are you sure you are getting Roles and Capabilities right? – brasofilo