Forum Replies Created

Viewing 6 replies - 1 through 6 (of 6 total)
  • 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’ );

    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)

    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,

    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);
    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

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