Skip to content

Instantly share code, notes, and snippets.

@kimcoleman
Last active April 3, 2021 03:12
Show Gist options
  • Select an option

  • Save kimcoleman/01433b5420be66d801e68d7eec755f0f to your computer and use it in GitHub Desktop.

Select an option

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.
<?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' );
@laurenhagan0306
Copy link

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/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment