• Resolved trishc82

    (@trishc82)


    I want to allow a volunteer access to the WordPress Dashboard to do some agreed upon work. However I do not want them to have access to the Members plugin. To this point I have only been able to limit their access t Roles, they still see the Members menu with all options except roles. How do I keep them from seeing the Members menu at all or at least how do I keep them from seeing the settings option?

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Support Omar ElHawary

    (@omarelhawary)

    Hi @trishc82,

    Thanks for reaching out Members Support Team!

    To keep your volunteer from seeing the Members menu or its settings, you’ll need to deny all the role-related capabilities for their user role. Please go to Users → Edit Capabilities for that role and set options like Create Roles, Edit Roles, Delete Roles, and List Roles to Deny.

    As an alternative, if you’d prefer to hide the menu completely, you can also add the following code snippet to your theme’s functions.php file or a custom plugin:

    add_action('admin_menu', function() {
    if (current_user_can('volunteer')) {
    remove_menu_page('members'); // Members menu slug
    }
    }, 999);

    With this approach, users assigned to the “volunteer” role won’t see the Members menu at all.

    Best regards,

    Thread Starter trishc82

    (@trishc82)

    Thanks @omarelhawary I had already marked the User setting to Deny so Roles is not displayed. I tried the code snippet you provided and replaced ('volunteer') with the name of the Role where I don’t want the Members menu to display in the dashboard but it did not hide the menu. Below is screenshot of my functions.php file I added the snippet at the end. Please advise on what I should do to hide the menu. TIA

    Thread Starter trishc82

    (@trishc82)

    Well it looks like my screenshot did not come through so I am posting the code here:

    <?php
    /**

    • Overlay Child functions and definitions
      */
      define( ‘OVERLAYHCHILD_LIFESTYLE_THEME_VERSION’ , ‘1.0.5’ );

    /**

    • Enqueue parent theme style
      */
      function overlaychild_lifestyle_enqueue_styles() {
      $customizer_library = Customizer_Library::Instance();
      $customizer_library->options[‘overlay-body-font’][‘default’] = ‘Poppins’;
      $customizer_library->options[‘overlay-primary-color’][‘default’] = ‘#7bbee8’;
      $customizer_library->options[‘overlay-header-nav-style’][‘default’] = ‘overlay-nav-solid’; wp_enqueue_style( ‘overlay-style’, get_template_directory_uri() . ‘/style.css’, array(), OVERLAYHCHILD_LIFESTYLE_THEME_VERSION ); wp_enqueue_style( ‘overlaychild-lifestyle-style’, get_stylesheet_uri(), array( ‘overlay-style’ ), OVERLAYHCHILD_LIFESTYLE_THEME_VERSION );
      wp_enqueue_style( ‘overlaychild-lifestyle-header-style’, get_stylesheet_directory_uri() . ‘/templates/header/header-style.css’, array( ‘overlay-style’, ‘overlay-header-style’ ), OVERLAYHCHILD_LIFESTYLE_THEME_VERSION ); // Load Responsive Stylesheets
      if ( !get_theme_mod( ‘overlay-responsive-disable’, customizer_library_get_default( ‘overlay-responsive-disable’ ) ) ) :
      $overlaychild_resp_mobile = get_theme_mod( ‘overlay-mobile-breakat’, customizer_library_get_default( ‘overlay-mobile-breakat’ ) );
      wp_enqueue_style( ‘overlaychild-lifestyle-resp-mobile’, get_stylesheet_directory_uri().”/inc/css/overlaychild-lifestyle-mobile.css”, array( ‘overlay-header-style’ ), OVERLAYHCHILD_LIFESTYLE_THEME_VERSION, ‘(max-width: ‘.esc_attr( $overlaychild_resp_mobile ).’px)’ );
      endif;
      }
      add_action( ‘wp_enqueue_scripts’, ‘overlaychild_lifestyle_enqueue_styles’ );

    /**

    • Enqueue Child Theme custom customizer styling.
      */
      function overlaychild_lifestyle_load_customizer_script() {
      wp_enqueue_script( ‘overlaychild-lifestyle-customizer-js’, get_stylesheet_directory_uri() . “/inc/js/customizer-custom.js”, array( ‘jquery’, ‘overlay-customizer-js’ ), OVERLAYHCHILD_LIFESTYLE_THEME_VERSION, true );
      wp_enqueue_style( ‘overlaychild-lifestyle-customizer-css’, get_stylesheet_directory_uri() . “/inc/css/customizer.css”, array( ‘overlay-customizer-css’ ), OVERLAYHCHILD_LIFESTYLE_THEME_VERSION );
      }
      add_action( ‘customize_controls_enqueue_scripts’, ‘overlaychild_lifestyle_load_customizer_script’ );

    /**

    • Enqueue Child Theme custom customizer styling.
      */
      function overlaychild_lifestyle_load_customizer_settings() {
      global $wp_customize;
      $wp_customize->get_setting( ‘overlay-body-font’ )->default = ‘Poppins’;
      $wp_customize->get_setting( ‘overlay-primary-color’ )->default = ‘#7bbee8’;
      $wp_customize->get_setting( ‘overlay-header-nav-style’ )->default = ‘overlay-nav-solid’;
      }
      add_action( ‘customize_controls_init’, ‘overlaychild_lifestyle_load_customizer_settings’ );
      add_action( ‘customize_preview_init’, ‘overlaychild_lifestyle_load_customizer_settings’ );
      add_action(‘admin_menu’, function() {
      if (current_user_can(‘Administrator No GiveWP’)) {
      remove_menu_page(‘members’); // Members menu slug
      }
      }, 999);
    Plugin Support Omar ElHawary

    (@omarelhawary)

    Hi @trishc82,

    You should use role slug, so for your role it should be administrator_no_givewp. Please check and let me know if it helps.

    Regards,

    Thread Starter trishc82

    (@trishc82)

    Hi @omarelhawary I did use the role slug administrator_no_givewp but it does not remove Members menu for users in that role.

    add_action(‘admin_menu’, function() {
    if (current_user_can(‘Administrator No GiveWP’)) {
    remove_menu_page(‘members’); // Members menu slug
    }
    }, 999);

    Regards,

    Plugin Support Omar ElHawary

    (@omarelhawary)

    Hi @trishc82,

    Please share screenshot for that role from WP Dashboard > Members > Roles and Edit the role.

    Regards,

    Thread Starter trishc82

    (@trishc82)

    Plugin Support Omar ElHawary

    (@omarelhawary)

    Hi @trishc82,

    Please make sure to use the below code:

    add_action(‘admin_menu’, function() {
    if (current_user_can(‘administrator_no_givewp’)) {
    remove_menu_page(‘members’); // Members menu slug
    }
    }, 999);

    Regards,

    Thread Starter trishc82

    (@trishc82)

    Hi @omarelhawary
    I replaced the spaces in the role name with _ as shown in your latest post, however it did not remove the Members menu from the dashboard for people assigned that role. 

    add_action(‘admin_menu’, function() {
    if (current_user_can(‘Administrator_No_GiveWP’)) {
    remove_menu_page(‘members’); // Members menu slug
    }
    }, 999);

    FYI
    I previously also tried renaming the Role adding the _ in place of the spaces in the role name and in the functions.php file without any success.​

    Thanks for your persistence in helping me to get this resolved.

    Thread Starter trishc82

    (@trishc82)

    I was able to resolve this problem using the following code in my themes Functions.php file:

    function custom_remove_members_menu_for_role() {
    // Replace ‘administrator_no_givewp’ with the actual slug of your custom role
    $target_role = ‘administrator_no_givewp’;
    $current_user = wp_get_current_user();

    // Check if the current user has the target role
    if ( in_array( $target_role, (array) $current_user->roles ) ) {
        // Remove the main Members menu
        remove_menu_page( 'members' );
    }

    }
    add_action( ‘admin_menu’, ‘custom_remove_members_menu_for_role’ );

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

The topic ‘How do I limit access to the Members plugin’ is closed to new replies.