Custom Fields
Re-Envisioned
Support MB Settings Page Allow non-Admin roles access to settings page

This topic contains 5 replies, has 2 voices, and was last updated by  tom 1 week, 2 days ago.

  • Creator
    Topic
  • #12504
    Resolved
    tom
    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

Viewing 5 replies - 1 through 5 (of 5 total)
  • Author
    Replies
  • #12521

    Farheen
    Moderator

    Hello Tom,

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

    Thanks

    #12522

    tom
    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

    tom
    Participant

    Disregard the => formatting, of course.

    #12526

    Farheen
    Moderator

    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

    tom
    Participant

    It works, thank you!

Viewing 5 replies - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.