• Resolved sbelaud

    (@sbelaud)


    Hi,

    I have to cleanup admin interface for my customer, who is not familiar with wordpress. To achieve this, I am using Admin Menu Editor plugin to hide some menu items for Editor accounts.

    I can see FEUP admin menu is only available for administrators, but the customer needs access to these configurations.

    How can I give access to admin menu for account with editor capabilities?

    EDIT: I just found this option: EWD_FEUP_Access_Role. How can I set it to allow administrators and editors?

    • This topic was modified 5 years, 2 months ago by sbelaud.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter sbelaud

    (@sbelaud)

    this works for displaying menu, but not to access:

    function FEUP_Editor_Access() {
        $role = 'editor';
        add_menu_page('Front End User Plugin', 'F-E Users', $role, 'EWD-FEUP-options', 'EWD_FEUP_Output_Options', 'dashicons-admin-users' , '50.6');
        add_submenu_page('EWD-FEUP-options', 'FEUP Users', 'Users', $role, 'EWD-FEUP-options&DisplayPage=Users', 'EWD_FEUP_Output_Options');
        add_submenu_page('EWD-FEUP-options', 'FEUP Fields', 'Fields', $role, 'EWD-FEUP-options&DisplayPage=Field', 'EWD_FEUP_Output_Options');
        add_submenu_page('EWD-FEUP-options', 'FEUP Statistics', 'Statistics', $role, 'EWD-FEUP-options&DisplayPage=Statistics', 'EWD_FEUP_Output_Options');
        add_submenu_page('EWD-FEUP-options', 'FEUP Levels', 'Levels', $role, 'EWD-FEUP-options&DisplayPage=Levels', 'EWD_FEUP_Output_Options');
        add_submenu_page('EWD-FEUP-options', 'FEUP Options', 'Options', $role, 'EWD-FEUP-options&DisplayPage=Options', 'EWD_FEUP_Output_Options');
        add_submenu_page('EWD-FEUP-options', 'FEUP Emails', 'Emails', $role, 'EWD-FEUP-options&DisplayPage=Emails', 'EWD_FEUP_Output_Options');
        add_submenu_page('EWD-FEUP-options', 'FEUP Payments', 'Payments', $role, 'EWD-FEUP-options&DisplayPage=Payment', 'EWD_FEUP_Output_Options');
    }
    add_action('admin_menu', 'FEUP_Editor_Access');
    • This reply was modified 5 years, 2 months ago by sbelaud.
    • This reply was modified 5 years, 2 months ago by sbelaud.
    Plugin Support jaysupport

    (@jaysupport)

    Hi sbelaud,

    If you first remove our menu pages using that hook, and then add your custom ones in like that, it may work.

    Alternatively, you can modify the line in our plugin code that sets this restriction. It’s found on line 69 of the Main.php file. That line of code is:

    if ($Access_Role == "") {$Access_Role = "administrator";}

    For your purpose, you could change it to:

    if ($Access_Role == "") {$Access_Role = "editor";}

    This will allow access to the FE-Users admin menu for the Editor role and higher, and they will be able to update the settings.

    Please note that this change will be overwritten if/when you update the plugin.

    Please also note that there are other features/places in the code that require administrator level access, such as for the importing. There is and will be no way to alter all of these instances with one code change. If ever you came across another access you needed to grant, you’d need to make a similar change as above.

    Thread Starter sbelaud

    (@sbelaud)

    Thanks, it seems to work with this code:

    function wporg_simple_role_caps() {
        $editor = get_role( 'editor' );
        $editor->add_cap( 'manage_feup', true );
    
        $admin = get_role( 'administrator' );
        $admin->add_cap( 'manage_feup', true );
    }
    
    add_action( 'init', 'wporg_simple_role_caps', 11 );
    
    function FEUP_Editor_Access() {
        $pages = [
            'Users',
            'Field',
            'Statistics',
            'Levels',
            'Options',
            'Emails',
            'Payment'
        ];
        $cap = 'manage_feup';
        remove_menu_page('EWD-FEUP-options');
        foreach ($pages as $page) {
            remove_submenu_page('EWD-FEUP-options','EWD-FEUP-options&DisplayPage='.$page);
        }
        add_menu_page('Front End User Plugin', 'F-E Users', $cap, 'EWD-FEUP-options', 'EWD_FEUP_Output_Options', 'dashicons-admin-users' , '50.6');
        foreach ($pages as $page) {
            add_submenu_page('EWD-FEUP-options', 'FEUP '.$page, $page, $cap, 'EWD-FEUP-options&DisplayPage='.$page, 'EWD_FEUP_Output_Options');
        }
    }
    add_action('admin_menu', 'FEUP_Editor_Access');
Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Access admin menu with Editor account’ is closed to new replies.