Created
April 24, 2023 09:54
-
-
Save ipokkel/f6d2ec9ea0b52c21184a97cf56cabad2 to your computer and use it in GitHub Desktop.
This file contains 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 | |
/** | |
* 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