Session management issues with WordPRess 404 Error page

I have tried to integrate wordpress into my existing website as the documentation archive using the existing login session. I have installed wordpress under /wp of the root app.

In my main app, I set the session: isValidUser = true when the user successfully logs in.

Now, in WordPress, I added the following code in functions.php which seemed to do the trick:

add_action('init', 'validate_session', 1);
function validate_session() {
    if(!session_id()) {
        session_start();
    }

     //Only allow the viewing of doco if logged into application
    if ( !isset($_SESSION['isValidUser']) ) 
    {
        header(Location: http://www.domain.com/);
    }
}

I had some issues with old pages which were cache related but I don't know how 404's are handled.

Is the 404 page handled differently? Does it not use the 'init' hook when loading?

Topic session actions init hooks Wordpress

Category Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.