Skip to content

Instantly share code, notes, and snippets.

@corypina
Created September 30, 2020 17:09
Show Gist options
  • Save corypina/070311d84fe1a26edf97d44d7898ec20 to your computer and use it in GitHub Desktop.
Save corypina/070311d84fe1a26edf97d44d7898ec20 to your computer and use it in GitHub Desktop.
Prevent Subscribers from accessing wp-admin
<?php
// If users have multiple roles, refactor line 7 to check for required
// roles instead of rejecting Subscribers
add_action( 'init', function () {
if ( is_admin()
&& in_array( 'subscriber', (array) $user->roles )
&& ! ( defined( 'DOING_AJAX' ) && DOING_AJAX )
) { wp_redirect( '/' ); exit; }
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment