Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Block Dashboard Access for Additional User Roles #245

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
/**
* Block dashboard access for custom roles pmpro_role_1 and pmpro_role_2.
*
* title: Block Dashboard Access for Additional User Roles
* layout: snippet
* collection: add-ons, pmpro-roles
* category: capabilities
* link: https://www.paidmembershipspro.com/block-dashboard-access-for-additional-user-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 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' );