Q:

wp_redirect only works on main site and not on other sites

My main site is https://www.domain.com/, all my multisites will have https://www.domein.com/multisite1/ link. I made a function in functions.php which will check if the option (in the admin panel) is true or false. If it is true the all sites should redirect to https://maintenance.domain.com. 
PHP 7:
// Check if user is on login page
function is_login_page() {
   return in_array($GLOBALS['pagenow'], array('wp-login.php', 'wp-register.php'));
}

// Check maintenance mode
function nmai_maintenance() {
  $options = get_option('nmai_section_enable_maintenance_id');
  $redirecturl = get_option('nmai_section_maintenance_url_id');

  // If is admin
  if ($options == 1 && ! is_admin() && ! is_network_admin() && ! is_user_logged_in() && ! is_login_page()) {
   // Check the url
   if (empty($redirecturl)) {
     wp_redirect('https://maintenance.domain.com');
     exit();
   }
   else {
    wp_redirect($redirecturl);
    exit();
   }
 }
}
add_action('wp_loaded', 'nmai_maintenance');   

This code works for the main site (https://www.domain.com/) and will redirect it, but all my other sites will just go to their home page. I have tried wp_safe_redirect, and used init instead of wp_loaded but this makes no difference. Putting this PHP code on top in functions.php or only use this code and delete all other code will make no difference. 

A:

get_option is a per sub-site function. In other words it gives you only the value of the option in the sub-site.
If you want to have a netwrok wide option you should use get_site_option and update_site_option.
You can also query an option from a specific sub-site by using get_blog_option and passing as parameter to it the main sub-site id, but in my opinion, get_site_option should be preferred.

