Skip to content

Instantly share code, notes, and snippets.

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 jerrickhakim/a54a352be47b54a87d9a412de6112fa7 to your computer and use it in GitHub Desktop.
Save jerrickhakim/a54a352be47b54a87d9a412de6112fa7 to your computer and use it in GitHub Desktop.
Only admin can access WordPress Dashboard
// BLOCK WORDPRESS DASHBOARD
function block_dashboard() {
$file = basename($_SERVER['PHP_SELF']);
if (is_user_logged_in() && is_admin() && !current_user_can('edit_posts') && $file != 'admin-ajax.php'){
wp_redirect( home_url('/account') );
exit();
}
}
add_action('init', 'block_dashboard');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment