title: How to restrict a user to use only one plugin in WordPress
body: <p>I want to restrict a specific user to use only one plugin. I don't want him to see any other pages on the WordPress admin dashboard like the Plugins page, Posts, or other pages. I want to show him just one link in the admin dashboard and let him to use just that page.</p>
  <p>I want to do it programmatically and don't want to use a plugin for it.</p>
  <p>I implemented the same functionality to restrict users by the code below but I want to know is there any better solution for it or not. It redirect user to '/wp-admin/edit.php?post_type=product' if he doesn't visit the valid pages that I declared in $pages array.
  I'm using WooCommerce, the post_type=product is for that.</p>
  <p>Could you help me to achieve this, please? Thank you.</p>
  <p>The code I wrote in functions.php file before to achieve this, the issue if I have to set all pages and plugins ID manually:</p>
  <pre><code>add_action('current_screen', 'checkUserPermissionsInThisScreen');
  
  function checkUserPermissionsInThisScreen(){
  
      if (is_admin()){
  
        $a = get_current_screen();
        $currentUserName = wp_get_current_user()-&gt;user_login;
  
        if ($currentUserName === &quot;testuser&quot;) {
  
           $pages = array(
            'dashboard',
            'toplevel_page_wpcf7',
            'contact_page_wpcf7-new',
            'contact_page_wpcf7-integration',
            'edit-shop_order',
            'edit-shop_coupon',
            'woocommerce_page_dgwt_wcas_settings',
            'woocommerce_page_wc-reports',
            'woocommerce_page_wc-settings',
            'woocommerce_page_wc-status',
            'woocommerce_page_wc-addons', 
            'woocommerce_page_alg-wc-renumerate-orders-tools',
            'themes',
            'customize',
            'users',
            'tools',
            'import',
            'export',
            'site-health',
            'export-personal-data',
            'erase-personal-data',
            'tools_page_action-scheduler',
            'options-general',
            'options-writing',
            'options-reading',
            'options-discussion',
            'options-media',
            'options-permalink',
            'options-privacy',
            'toplevel_page_agilewc',
            'toplevel_page_smush',
            'shop_order'
          );
  
  
          remove_menu_page( 'themes.php' ); 
          remove_menu_page( 'woocommerce' );
          remove_menu_page( 'wpcf7' );
          remove_menu_page( 'index.php' );
          remove_menu_page( 'edit-comments.php' );
          remove_menu_page( 'users.php' );
          remove_menu_page( 'tools.php' );
          remove_menu_page( 'options-general.php' );
          remove_menu_page( 'smush' );
  
          //Remove the &quot;WooCommerce Recent Reviews&quot; widget.
          remove_meta_box('woocommerce_dashboard_recent_reviews', 'dashboard', 'normal');
          //Remove the &quot;WooCommerce Status&quot; widget.
          remove_meta_box('woocommerce_dashboard_status', 'dashboard', 'normal');
          //Hide the &quot;Coupon data&quot; meta box.
          remove_meta_box('woocommerce-coupon-data', $a-&gt;id, 'normal');
          //Hide the &quot;Order data&quot; meta box.
          remove_meta_box('woocommerce-order-data', $a-&gt;id, 'normal');
          //Hide the &quot;Items&quot; meta box.
          remove_meta_box('woocommerce-order-items', $a-&gt;id, 'normal');
          //Hide the &quot;Downloadable product permissions&quot; meta box.
          remove_meta_box('woocommerce-order-downloads', $a-&gt;id, 'normal');
          //Hide the &quot;Order actions&quot; meta box.
          remove_meta_box('woocommerce-order-actions', $a-&gt;id, 'side');
          //Hide the &quot;Order notes&quot; meta box.
          remove_meta_box('woocommerce-order-notes', $a-&gt;id, 'side');
  
        } 
  
          global $pagenow;
  
          if ( ( ! in_array($a-&gt;id, $pages) || $pagenow === 'post-new.php' ) ) {
            wp_redirect(get_site_url() . &quot;/wp-admin/edit.php?post_type=product&quot;);
            die;
          } 
          
        }
  
  
      }
  }
  </code></pre>