Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ipokkel/f6d2ec9ea0b52c21184a97cf56cabad2 to your computer and use it in GitHub Desktop.
Save ipokkel/f6d2ec9ea0b52c21184a97cf56cabad2 to your computer and use it in GitHub Desktop.
<?php
/**
* Allow users with set custom roles access to the WordPress dashboard when users
* that also has a "Subscriber" role is being blocked if the Restrict Dashboard Access
* has been set on the Memberships > Settings > Advanced page.
*
* This should be helpful if users have multiple 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/
*/
function my_pmpro_unblock_dashboard_access_for_roles( $block ) {
global $current_user;
$unblock_roles = array( 'pmpro_membership_manager', 'pmpro_approver', 'custom_role_name' );
// Unblock user if they have a role.
if ( $current_user && array_intersect( $unblock_roles, $current_user->roles ) ) {
$block = false;
}
return $block;
}
add_filter( 'pmpro_block_dashboard', 'my_pmpro_unblock_dashboard_access_for_roles' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment