'Using is_page() to exclude a page in wordpress from maintenance screen

I'v found a custom plugin for Wordpress that lets me create a custom maintenance/coming-soon page using html & css, However the code only excludes the login page so that login is possible. I'd like it to exclude my opt-in/survey page or any other pages from the maintenance screen when needed. Code as below or at https://www.nosegraze.com/maintenance-screen-wordpress/:

function ng_maintenance_mode() {
    global $pagenow;
    if ( $pagenow !== 'wp-login.php' && ! current_user_can( 'manage_options' ) && ! is_admin() ) {
        header( $_SERVER["SERVER_PROTOCOL"] . ' 503 Service Temporarily Unavailable', true, 503 );
        header( 'Content-Type: text/html; charset=utf-8' );
        if ( file_exists( plugin_dir_path( __FILE__ ) . 'views/maintenance.php' ) ) {
            require_once( plugin_dir_path( __FILE__ ) . 'views/maintenance.php' );
        }
        die();
    }
}

add_action( 'wp_loaded', 'ng_maintenance_mode' );

I'd like to modify this to exempt a specific page. I've tried a few things in the 'if' statement using !is_page('survey') but have not been successful. Any help appreciated!



Solution 1:[1]

The function is_page() must be in the global scope.

if(!is_page('survey')) {
    add_action( 'wp_loaded', 'ng_maintenance_mode' );
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Sergei