I would like to give permission to editor to save the option field I have created (working fine with administrator).

I read on several forums that the add_filter( 'option_page_capability_ is the solution, but doesn't work for my 5.5.1 version Wordpress.

Could you help me with my code, I'm turning crazy ;)

add_action('admin_menu', 'create_menu');

function create_menu() {

    //create new top-level menu
    add_menu_page('Option du thème', 'Options thème', 'edit_posts', __FILE__, 'my_cool_plugin_settings_page' );

    //call register settings function
    add_action( 'admin_init', 'register_my_cool_plugin_settings' );

function register_my_cool_plugin_settings() {
    //register our settings
    register_setting( 'options-settings-group', 'new_option_name' );
    register_setting( 'options-settings-group', 'some_other_option' );
    register_setting( 'options-settings-group', 'option_etc' );

add_filter( 'option_page_capability_options-settings-group', 'sewp_114719_map_options_capability' );
function sewp_114719_map_options_capability( $cap ) {
    return 'edit_posts';

function my_cool_plugin_settings_page() {
<div class="wrap">
<h1>Your Plugin Name</h1>

<form method="post" action="options.php">
    <?php settings_fields( 'options-settings-group' ); ?>
    <?php do_settings_sections( 'options-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 esc_attr( get_option('new_option_name') ); ?>" /></td>
        <tr valign="top">
        <th scope="row">Some Other Option</th>
        <td><input type="text" name="some_other_option" value="<?php echo esc_attr( get_option('some_other_option') ); ?>" /></td>
        <tr valign="top">
        <th scope="row">Options, Etc.</th>
        <td><input type="text" name="option_etc" value="<?php echo esc_attr( get_option('option_etc') ); ?>" /></td>
    <?php submit_button(); ?>

<?php } 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.