Remove Plugin’s Toolbar Items for a Certain User

You can disable the Toolbar Extra items on the Toolbar globally for a certain user.

The use case could be that there is another administrator user on the site who shouldn’t see the items of Toolbar Extras. You only need to know the ID of that user:

This code snippet goes into a core functionality plugin, or into Code Snippets.

/**
 * Plugin: Toolbar Extras:
 *    Remove Items for user ID 2 (admin role)
 */
if ( 2 === get_current_user_id() ) {
  define( 'TBEX_DISPLAY', FALSE );
}

Make sure you get the correct user ID, in the example above it is 2, and make sure this an administrator actually.

You can also do this for more than one user, like so:

This code snippet goes into a core functionality plugin, or into Code Snippets.

/**
 * Plugin: Toolbar Extras:
 *    Remove Items for user IDs 2, 7 and 10 (admin roles)
 */
if ( in_array( get_current_user_id(), array( 2, 7, 10 ) ) ) {
  define( 'TBEX_DISPLAY', FALSE );
}

Just replace the numbers in the above example with the actual user IDs – and add more IDs, separated by comma.

Published on: // Last updated on: // All information without guarantee. Changes and errors excepted.