Last active
April 3, 2021 03:12
-
-
Save kimcoleman/01433b5420be66d801e68d7eec755f0f to your computer and use it in GitHub Desktop.
Hide the WordPress Toolbar for custom roles pmpro_role_1 or pmpro_role_2.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Hide the WordPress Toolbar for custom roles pmpro_role_1 and pmpro_role_2. | |
| * | |
| * You can add this recipe to your site by creating a custom plugin | |
| * or using the Code Snippets plugin available for free in the WordPress repository. | |
| * Read this companion article for step-by-step directions on either method. | |
| * https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
| * | |
| */ | |
| function hide_toolbar_for_custom_role( $hide ) { | |
| global $current_user; | |
| //Update this line with your custom roles | |
| $roles_to_hide = array( 'pmpro_role_1', 'pmpro_role_2' ); | |
| if ( ! empty( array_intersect( $roles_to_hide, $current_user->roles ) ) ) { | |
| $hide = true; | |
| } | |
| return $hide; | |
| } | |
| add_filter( 'pmpro_hide_toolbar', 'hide_toolbar_for_custom_role' ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This recipe is included in the blog post on "Hide the WordPress Toolbar for Additional User Roles" at Paid Memberships Pro here: https://www.paidmembershipspro.com/hide-the-wordpress-toolbar-for-additional-user-roles/