Deny wp-admin for non administrator users

Moeilijkheidsniveau:

This code will redirect users without "user delete permissions" to the home url.

add_action('admin_init','mp_admin_init');

// Deny wp-admin for loggedin non administrator users
function mp_admin_init()
{
		require_once(ABSPATH . WPINC . '/pluggable.php');
		$current_user = wp_get_current_user();
		$current_user_id = ! empty($current_user) ? $current_user->id : 0;
		$current_user = new WP_User($current_user_id);
		if(!$current_user->has_cap('delete_users'))
		{
			wp_redirect(get_option('home'),302);
			die();
		}
}