Skip to content

Instantly share code, notes, and snippets.

@NichlasB
Created July 5, 2017 08:44
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 NichlasB/ef17e375c708145f17896a425f62811c to your computer and use it in GitHub Desktop.
Save NichlasB/ef17e375c708145f17896a425f62811c to your computer and use it in GitHub Desktop.
Block Admin Access for Specified User Roles
<?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/**
* block-role-admin-access.php
*/
function cf_block_role_admin_access() {
$redirect = home_url( '/' );
if ( current_user_can( 'student' ) && ! current_user_can( 'administrator' ) )
exit( wp_redirect( $redirect ) );
}
add_action( 'admin_init', 'cf_block_role_admin_access', 100 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment