-
Check for administrator user
-
Remove the admin bar for non-administrators
-
Redirect non-administrators to another page
wp_redirect ( site_url( “https://wordpress.stackexchange.com/” ), 302 )
Putting it all together
function wpse_20160318_user_checks() {
// ignore administrators
if ( ! current_user_can( 'manage_options' ) ) {
// ignore these events
if (( defined( 'DOING_AJAX' ) && DOING_AJAX )
|| ( defined( 'DOING_CRON' ) && DOING_CRON )
|| ( defined( 'WP_CLI' ) && WP_CLI )
|| ( defined( 'REST_REQUEST' ) && REST_REQUEST )
) {
return;
}
if ( is_admin() ) {
// redirect if on the dashboard / back-end to a front-end page
wp_redirect( site_url( "https://wordpress.stackexchange.com/" ), 302 );
exit;
}
else {
// remove admin bar on front-end
show_admin_bar( false );
}
}
}
add_action( 'init', 'wpse_20160318_user_checks' );