How to setup admin redirect based on membership level on main site?

I am trying to setup a network function (multisite) that will check the user level (via the Membership plugin) and redirect if it is not that level. I have a basis for the code via https://premium.wpmudev.org/forums/topic/php-if-for-user-role-on-main-site#post-532116. I tried replacing $cap with $level_id and updating the level in the code with the correct ID but it still comes back with undefined variable for $level_id. Please let me know how I can modify the code from the plugin on https://premium.wpmudev.org/forums/topic/php-if-for-user-role-on-main-site#post-532116 to make this happen. Thank you.