User Roles - app

You can hide or show menu items or page content based on user roles that are assigned to your WordPress user.

The examples below describe how it's possible to use two roles: administrator or member.

Hide or Show Menu Items

To show or hide menu items in either the side menu or the tab menu add "role-{user-role}" to the menu item's extra classes field.

Continuing with our example of two roles named "member" or "administrator" in the menus, when a user who is assigned the "member" role, they will see the "Member only" menu, but they will not see the "Admins only" menu.

Hide or Show Content in a Custom Page

Here is an example to show or hide content in a custom page based on user role.

<div *ngIf="user?.hasRole('bbp_keymaster')">You are a keymaster</div>

<div *ngIf="user?.roles">
   <h3>Your Roles</h3>
   <div *ngFor="let role of user.roles">{{ role }}</div>

Tip: If you use the *ngFor loop in a custom page you will see what user roles exist for your logged in user. For example, in WordPress, the admin user's role is Administrator in wp-admin; however, the role that gets assigned is administrator in lower case. Be sure to use that role.

Programmer's tip: using a '?' in the above statement is a shortcut to test if the variable exists. It's the same as if you used *ngIf="user && user.hasRole('bbp_keymaster')".

Setting Custom Roles

If you wish to add your own roles, use the " apppresser_user_roles" filter in WordPress. Refer to the AppPresser plugin for its usage.