Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nextab/006715e124b2ea155ff31781aedcc9da to your computer and use it in GitHub Desktop.
Save nextab/006715e124b2ea155ff31781aedcc9da to your computer and use it in GitHub Desktop.
#region Redirect non-authors back to profile page when accessing /wp-admin
function nxt_redirect_non_admin_user() {
if(!defined('DOING_AJAX') && !current_user_can('edit_posts')) {
wp_redirect(site_url() . '/my-account/');
exit;
}
}
add_action( 'admin_init', 'nxt_redirect_non_admin_user' );
#endregion Redirect non-authors back to home page when accessing /wp-admin
#region Disable the WP admin bar for non-authors
add_filter('show_admin_bar', function($show) {
if(!current_user_can('edit_posts')) {
return false;
}
return $show;
});
#endregion Disable the WP admin bar for non-authors
@nextab
Copy link
Author

nextab commented Jan 22, 2021

To prevent everything below...

  • admin -> use !current_user_can('edit_plugins');
  • editor -> use !current_user_can('delete_others_posts');
  • author -> use !current_user_can('publish_posts');
  • contributor -> use !current_user_can('delete_posts');

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