In my case I have created a page named test.php
inside my theme folder. I have a specific html structure in test.php
file. I don't include header and footer files here. I hard code them in this file because they are different.I validate user details using $_SESSION
in function.php
. Now what I want to do is, I want to validate the SESSION
. If the SESSION is false I need to load the test.php
file, else I will follow Wordpress flow.
Asked
Active
Viewed 782 times
2

Ramesh
- 2,297
- 2
- 20
- 42
-
You can use `get_template_part`. First check session validity then you can use this function to add a page within the page. https://developer.wordpress.org/reference/functions/get_template_part/ – Zaid Bin Khalid Jul 11 '18 at 06:56
-
I want to load the `test.php` page individually. It's not about loading the page inside another – Ramesh Jul 11 '18 at 10:01
2 Answers
1
You mentioned:
I validate user details using $_SESSION in function.php
So I'm assuming you have the validation part down, and are struggling with the redirection to test.php
. You can achieve the redirect by hooking in to the template_redirect
action.
Inside your functions.php
, add:
add_action( 'template_redirect', function() {
if (!session_is_validated()) {
include( get_template_directory() . '/test.php' );
exit;
}
});

Frits
- 7,341
- 10
- 42
- 60
-
It's loading the `test.php` inside all the wordpress pages. It's not what I want to happen. I want to load only the `test.php` file which has the complete **HTML DOM**. When the session is valid I want to load `test.php` file without intercepting with any other wordpress pages. – Ramesh Jul 11 '18 at 10:11
0
If you are just trying to validate just the session, then something like this should be enough:
function IsAdmin() {
if( !isset($_SESSION['user_level'])){
return false;
}
return ($_SESSION['user_level'] == 1337);
}

Gucci
- 921
- 1
- 7
- 27
-
Session validation is not the issue sir.I want to call the custom page when it's valid. – Ramesh Jul 11 '18 at 09:59