Skip to content

Instantly share code, notes, and snippets.

@asharirfan
Created August 3, 2016 10:47
Show Gist options
  • Save asharirfan/05265478e0aac8d0c096090268b1a0da to your computer and use it in GitHub Desktop.
Save asharirfan/05265478e0aac8d0c096090268b1a0da to your computer and use it in GitHub Desktop.
Limit the access of a certain user role to dashboard.
<?php
if ( ! function_exists( 'wp_limit_dashboard_access' ) ) {
/**
* Limit the access of a certain user role to dashboard.
*/
function wp_limit_dashboard_access() {
if ( current_user_can( 'user-role' ) && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
wp_redirect( home_url() );
}
}
add_action( 'init', 'wp_limit_dashboard_access' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment