Skip to content

Instantly share code, notes, and snippets.

@mattneal-stafflink
Last active October 17, 2021 23:35
Show Gist options
  • Save mattneal-stafflink/3ca46ac49a02ccfa8f5c5c8f3c696608 to your computer and use it in GitHub Desktop.
Save mattneal-stafflink/3ca46ac49a02ccfa8f5c5c8f3c696608 to your computer and use it in GitHub Desktop.
<?php
// Stop Authors from accessing the admin dashboard unless you are an admin.
function prevent_author_access(){
if( current_user_can( 'author' ) && is_admin() ) {
// do something here. maybe redirect to homepage
wp_safe_redirect( get_bloginfo( 'url' ) );
}
}
add_action( 'admin_init', 'prevent_author_access' );
// Remove the admin bar for all users except for admins.
add_action('after_setup_theme', 'remove_admin_bar');
function remove_admin_bar() {
if (!current_user_can('administrator') && !is_admin()) {
show_admin_bar(false);
}
}
@mattneal-stafflink
Copy link
Author

Copy all of this (without the '<?php') and paste it into your themes' functions.php.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment