How to hide it completely? And how to have it show for only one role, ie. Administrator only? Thanks!

    Matt L

    By default, CUI is only loaded for users that have the publish_posts capability (author, editor, admin). Nobody else can see/use it.

    Is that sufficient for your use case? Or do you need to further lock it down?

    I'd like to restrict all usage of the plugin, including admin bar visibility, to Admin only. So an author or editor couldn't access it even if they accidentally typed the keyboard shortcut.

      Matt L

      Gotcha. You can drop this into your favorite code snippet plugin (or child theme):

      /**
       * Disable CommandUI for all users, unless they have the manage_options capability.
       */
      add_filter('commandui/load-js', fn() => current_user_can('manage_options'));
      5 months later

      The below code snippet can be used to only load CommandUI for a specific user ID (1 here).

      /**
       * Disable CommandUI for all users, unless they have a specific user ID.
       */
      
      add_filter('commandui/load-js', function ()  {
         // CHANGE HERE
          return get_current_user_id() === 1; // <-- Change this to the user ID you want to allow
      });