Skip to content

Instantly share code, notes, and snippets.

@greenhornet79
Last active March 16, 2022 11:32
Show Gist options
  • Save greenhornet79/161bdaf9731e59c381ec to your computer and use it in GitHub Desktop.
Save greenhornet79/161bdaf9731e59c381ec to your computer and use it in GitHub Desktop.
<?php
// don't allow users to access WordPress admin
add_action('admin_init', 'endo_hide_dashboard');
function endo_hide_dashboard() {
if ( ! current_user_can( 'manage_options' ) && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) ) {
wp_redirect(home_url()); exit;
}
}
// remove admin bar from non admin users
add_action('after_setup_theme', 'endo_remove_admin_bar');
function endo_remove_admin_bar() {
if (!current_user_can('manage_options') && !is_admin()) {
show_admin_bar(false);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment