options - Editor role not saving settings page for custom post type

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 basi

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() {
    add_submenu_page(
        'edit.php?post_type=programmes',
        'content',
        'Archive content',
        'edit_pages',
        basename(__FILE__),
        'archiveContent'
    );
}
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">
        <?php
        settings_fields( 'programme_content' ); 
        do_settings_sections( 'programme_content' );

        wp_editor(
            get_option( 'programme_content' ),
            '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(); ?>   
    </form>     
</div>
<?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?

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() {
    add_submenu_page(
        'edit.php?post_type=programmes',
        'content',
        'Archive content',
        'edit_pages',
        basename(__FILE__),
        'archiveContent'
    );
}
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">
        <?php
        settings_fields( 'programme_content' ); 
        do_settings_sections( 'programme_content' );

        wp_editor(
            get_option( 'programme_content' ),
            '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(); ?>   
    </form>     
</div>
<?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?

Share Improve this question edited Apr 17, 2019 at 4:55 norman.lol 3,2413 gold badges30 silver badges35 bronze badges asked May 25, 2017 at 15:58 rikardo85rikardo85 1373 silver badges18 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 4

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';
}

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745581383a4634274.html

相关推荐

  • options - Editor role not saving settings page for custom post type

    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 basi

    21小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信