Editor role not saving settings page for custom post type

The question:

I currently have a custom post type with a sub menu page via add_submenu_page. On this page I have a form with some basic settings such as a text editor and some radio buttons.

function programme_enable_pages() {
        'Archive content',
add_action( 'admin_menu', 'programme_enable_pages' );

function register_programme_settings() {
    register_setting( 'programme_content', 'programme_content' );
    register_setting( 'programme_content', 'programme_branding' );
add_action( 'admin_init', 'register_programme_settings' );

function archiveContent() { ?>
<div class="wrap">

    <form method="post" action="options.php">
        settings_fields( 'programme_content' ); 
        do_settings_sections( 'programme_content' );

            get_option( 'programme_content' ),
            $settings = array(
                'textarea_name' => 'programme_content'
        ); ?>

        <label><b>Branding options</b></label><br>
        <input type="radio" name="programme_branding" id="branding_blue" value="blueBranding" <?php checked('blueBranding', get_option('programme_branding'), true); ?> checked="checked">Blue Branding<br>
        <input type="radio" name="programme_branding" id="branding_red" value="redBranding" <?php checked('redBranding', get_option('programme_branding'), true); ?>/>Red Branding<br>
        <input type="radio" name="programme_branding" id="branding_orange" value="orangeBranding" <?php checked('orangeBranding', get_option('programme_branding'), true); ?>/>Orange Branding

        <?php submit_button(); ?>   
<?php }

When a user with a role of administrator edits any of the content and saves the changes, the content saves with no issues. But when a user with a role of editor saves the changes, they are directed to a page which states:

Sorry, you are not allowed to manage these options.

Can anyone please point me in the right direction on how I can make anyone with a user role of editor save these options?

The Solutions:

Below are the methods you can try. The first solution is probably the best. Try others if the first one doesn’t work. Senior developers aren’t just copying/pasting – they read the methods carefully & apply them wisely to each case.

Method 1

In the wp-admin/options.php file you find filter with name created from your settings group to control permissions:

$capability = apply_filters( "option_page_capability_{$option_page}", $capability );

to fix issue, add filter with your desired permission level like:

add_filter( 'option_page_capability_programme_content', 'my_settings_permissions', 10, 1 );
function my_settings_permissions( $capability ) {
    return 'edit_pages';

Method 2

To save options the user needs to have the manage_options capability, which editors lack.

Your use of edit_pages capability for the menu, lets the admin page be accessible to editors, but setting submit goes to the option handler code which is not taking into account the context of the admin page.

How to fix? I would say that no one except for an admin should be able to change site wide setting, so your approach is just wrong… more constructive options are not to use the settings API and handle the form submission yourself, or use a role manager type of plugin to give the user the manage_option capability.

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Comment