Skip to content

Instantly share code, notes, and snippets.

@KaineLabs
Created April 5, 2019 18:39
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 KaineLabs/ce5a3fd1336806f5dfda28e1ffc2d645 to your computer and use it in GitHub Desktop.
Save KaineLabs/ce5a3fd1336806f5dfda28e1ffc2d645 to your computer and use it in GitHub Desktop.
Hide Dashboard Admin Bar For Non Admins.
<?php
/**
* Hide Dashboard Admin Bar For Non Admins.
*/
function yzc_hide_dashboard_for_non_admins() {
if ( current_user_can( 'administrator' ) ) {
return false;
}
// Hide Admin Bar.
if ( ! is_admin() ) {
show_admin_bar( false );
}
// Hide Admin Dashboard.
if ( is_admin() &&
! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
wp_redirect( home_url() );
exit;
}
}
add_action( 'init', 'yzc_hide_dashboard_for_non_admins', 99 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment