• Resolved mrdexters1

    (@mrdexters1)


    Hello, at first I want to thank you so much for the great plugin!!!

    and I will be very grateful for your help:

    I am trying to remove some of the admin features for a user with the custom role. What i mean by remove some of the admin features is disable them from seeing certain admin menu items, such as comments, tools, media ect. I have managed to remove the items I want from the admin menu, using this code:

    add_action( 'admin_menu', 'members_remove_menu_pages' );
    function members_remove_menu_pages() {
      $user = wp_get_current_user();
      if ( in_array('editor', $user->roles) ) {
        

    remove_menu_page( ‘tools.php’);
    remove_menu_page(‘edit.php?post_type=plugins’);
    remove_menu_page(‘edit-comments.php’);
    remove_menu_page(‘edit.php?post_type=elementor_library’);
    remove_menu_page(‘edit.php?post_type=elementor_cf_db’);`
    }
    }`

    It works a treat. The problem I am facing is that I can just manually add the query string to the url, eg /wp-admin/tools.php and that will take me to the tools screen. Does anyone know a way to restrict these pages from being accessed altogether, as well as hiding them from the admin menu?

    Thank you!

    • This topic was modified 2 years, 7 months ago by mrdexters1.
    • This topic was modified 2 years, 7 months ago by mrdexters1.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Caseproof

    (@caseproof)

    Hi @mrdexters1

    You can try to use this code snippet and adjust it as you wish:

    add_action('admin_init', function() {
      global $pagenow;
      if ( ! current_user_can( 'manage_options' ) && ('/wp-admin/admin-ajax.php' != $_SERVER['PHP_SELF']) ) {
        $user = wp_get_current_user();
        if ( in_array('editor', $user->roles) && 
          (
          $pagenow == 'tools.php'
          || ($pagenow == 'edit.php' && isset($_GET['post_type']) && $_GET['post_type'] == 'plugins')
          ) 
        ) {
          wp_redirect( home_url() );
          exit;
        }
      }
    });

    Hopefully, that helps.

    Thread Starter mrdexters1

    (@mrdexters1)

    Hello @caseproof thank you so much! It’s good solution.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Remove ability to access certain admin menus’ is closed to new replies.