Skip to content

Instantly share code, notes, and snippets.

@ipokkel
Last active April 19, 2024 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ipokkel/9046b64fef3330398531751146ace076 to your computer and use it in GitHub Desktop.
Save ipokkel/9046b64fef3330398531751146ace076 to your computer and use it in GitHub Desktop.
<?php
/**
* Show the WordPress Toolbar for custom roles.
*
* This is helpful if users have multiple roles.
*
* For example, if you have a role "subscriber" and a role "pmpro_memberships_manager"
* or "pmpro_approver" and you want to show the toolbar for the those roles.
*
* 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/
*
*/
// hook into pmpro_hide_toolbar and show the toolbar for if the user has role
function my_pmpro_show_toolbar_for_roles( $hide ) {
global $current_user;
// set the roles you want to show the toolbar for
$roles_to_show = array( 'pmpro_memberships_manager', 'pmpro_approver' );
function my_pmpro_show_toolbar_for_roles( $hide ) {
global $current_user;
// set the roles you want to show the toolbar for
$roles_to_show = array( 'pmpro_memberships_manager', 'pmpro_approver' );
// if the user has one of the roles and can access the administrative dashboard, show the toolbar
if ( array_intersect( $roles_to_show, $current_user->roles ) && current_user_can( 'read' ) ) {
$hide = false;
}
return $hide;
}
add_filter( 'pmpro_hide_toolbar', 'my_pmpro_show_toolbar' );
return $hide;
}
add_filter( 'pmpro_hide_toolbar', 'my_pmpro_show_toolbar' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment