option_page_capability_ add_filter is not working

Question

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>
         
        <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>
        
        <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>
        </tr>
    </table>
    
    <?php submit_button(); ?>

</form>
</div>
<?php } 
0
Julie Chaumard 4 days 0 Answers 6 views 0

Leave an answer