Last active
April 3, 2021 03:10
-
-
Save kimcoleman/216beebdcb3b46b6206b2825997e1fc1 to your computer and use it in GitHub Desktop.
Block dashboard access for custom roles pmpro_role_1 and pmpro_role_2.
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 | |
/** | |
* Block dashboard access 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 block_dashboard_for_custom_role( $block ) { | |
global $current_user; | |
//Update this line with your custom roles | |
$roles_to_block = array( 'pmpro_role_1', 'pmpro_role_2' ); | |
if ( ! current_user_can( 'manage_options' ) | |
&& ! wp_doing_ajax() | |
&& ! empty( array_intersect( $roles_to_block, $current_user->roles ) ) ) { | |
$block = true; | |
} | |
return $block; | |
} | |
add_filter( 'pmpro_block_dashboard', 'block_dashboard_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 "Block Dashboard Access for Additional User Roles" at Paid Memberships Pro here:https://www.paidmembershipspro.com/block-dashboard-access-for-additional-user-roles/