WordPress.org

Ready to get started?Download WordPress

Forums

Change user permission to edit general settings (3 posts)

  1. whoaloic
    Member
    Posted 2 years ago #

    Hello,
    I try to change user permission in order that an editor could edit the "General Settings".
    I have given the editor the capability "manage_options" but in this case all the pages (writing, reading, etc.) are enabled for the editor.
    I then tried to edit the options-general.php file :
    at the beginnig, we have that : "if ( ! current_user_can( 'manage_options' ))".
    I tried to change as "if ( ! current_user_can( 'level_7' ) )" or "if ( ! current_user_can( 'administrator' ) || ! current_user_can( 'editor' ) )"

    But the editor can't get the "General Settings" page.
    Please I need help on it!

  2. ChristiNi
    Member
    Posted 2 years ago #

    Hi whoaloic,

    You can add that capability in your functions.php file:

    <?php
       // get the the role object
       $editor = get_role('editor');
       // add $cap capability to this role object
       $editor->add_cap('manage_options');
    ?>

    Alternatively, you can use a plugin like this (one of many) to help you manage your users and their roles and capabilities:

    http://wordpress.org/extend/plugins/members/

    Hope this helps

  3. whoaloic
    Member
    Posted 2 years ago #

    Hello,
    thank you for this answer.
    Yes I use "members" plugin and if I add "mange_options" to the editor role, the editor has access to all the submenus of Settings section.
    What I wanted to do is that only "General" submenu would be enable for the Editor. Particurlarly because I want the editor able to edit the site's description.

    So I have edited the wp-admin/menu.php file around line 80:

    $menu[80] = array( __('Settings'), 8, 'options-general.php', '', 'menu-top menu-icon-settings', 'menu-settings', 'div' );
    	$submenu['options-general.php'][10] = array(_x('General', 'settings screen'), 8, 'options-general.php');
    	$submenu['options-general.php'][15] = array(__('Writing'), 'manage_options', 'options-writing.php');

    I have change the capablity "manage_options" to capability related to level 8 (ediwhich match to my editor level).

    Then the editor got access to the General settings page but I met another issue: when I save the changes, I get the message : "Cheatin' Uh?"
    So I found that on wp-admin/options.php file there is that piece of code (line 27):

    $capability = 'manage_options';
    
    if ( empty($option_page) ) // This is for back compat and will eventually be removed.
    	$option_page = 'options';
    else
    	$capability = apply_filters( "option_page_capability_{$option_page}", $capability );
    
    if ( !current_user_can( $capability ) )
    	wp_die(__('Cheatin’ uh?'));

    I've just edit like that and what I wanted is working fine.

    $capability = 'manage_options';
    $level = 'level_8';
    
    if ( empty($option_page) ) // This is for back compat and will eventually be removed.
    	$option_page = 'options';
    else
    	$capability = apply_filters( "option_page_capability_{$option_page}", $capability );
    
    if ( !current_user_can( $level ) )
    	wp_die(__('Cheatin’ uh?'));

Topic Closed

This topic has been closed to new replies.

About this Topic