Allow non-Admin roles access to settings page

Support MB Settings Page Allow non-Admin roles access to settings pageResolved

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #12504
    tomtom
    Participant

    Using the default generated code to register the settings page does not allow access for any non-admin roles. Wrapping the default generated code in a current_user_can() function does not work either to give access to non-admins. Is there a way to give non-admin roles access to the settings page?
    Thanks

    #12521
    FarheenFarheen
    Participant

    Hello Tom,

    Can you please share your code here so we can take a look.

    Thanks

    #12522
    tomtom
    Participant

    For example, the default generated will show up for admins but not for non-admins.

    add_filter( 'mb_settings_pages', 'prefix_options_page' );
    function prefix_options_page( $settings_pages ) {
    
            $settings_pages[] = array(
                'id'          => 'customize',
                'option_name' => 'customize',
                'menu_title'  => 'customize',
                'icon_url'    => 'dashicons-admin-generic',
                'style'       => 'boxes',
                'columns'     => 1,
    
                'position'    => 168,
            );
    
            return $settings_pages;
    }

    I tried wrapping it like so, but still a no-show for non-admins:

    add_filter( 'mb_settings_pages', 'prefix_options_page' );
    function prefix_options_page( $settings_pages ) {
    
            $settings_pages[] = array(
                'id'          => 'customize',
                'option_name' => 'customize',
                'menu_title'  => 'customize',
                'icon_url'    => 'dashicons-admin-generic',
                'style'       => 'boxes',
                'columns'     => 1,
    
                'position'    => 168,
            );
    
    if( current_user_can('editor') || current_user_can('administrator') ) {
                return $settings_pages;
    }
    }
    #12523
    tomtom
    Participant

    Disregard the => formatting, of course.

    #12526
    FarheenFarheen
    Participant

    Hello Tom,

    Try adding
    'capability' => 'edit_others_pages',

    in the array. You can define the users via the capability.

    Let me know if it works.

    #12537
    tomtom
    Participant

    It works, thank you!

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.