I am trying to integrate the WP functions in a external php file.
The problem is that user’s and login’s authentication functions like is_user_logged_in()
, is_admin()
, etc doesn’t work at all. However, Post’s functions are working correct.
So, it has to be a “Session” problem.
Actually after a deep deep search, the only “good” post in the web about the issue is the following old post in WP support: https://wordpress.org/support/topic/how-to-integrate-sessionlogin-authentication-to-non-wordpress-pages-w-wp-auth
But, that solution isn’t working at all, and if I enable the root Cookie
plugin, I can not even login into my /wp-blog/
So, is there any idea how to integrate and the login functions in the php file?
Code is pretty simple:
file.php
<?php
//define('WP_USE_THEMES', false);
//include($_SERVER['DOCUMENT_ROOT'].'/wp-blog/wp-load.php');
include($_SERVER['DOCUMENT_ROOT'].'/wp-blog/wp-blog-header.php');
if ( is_user_logged_in() ) {
echo 'logged in.';
} else {
echo 'NOT logged in.';
}
?>
Also, I have the following warning in my error logs
PHP Warning: session_start(): Cannot send session cache limiter –
headers already sent (output started at /…./) in
/……/wp-content/plugins/global-content-blocks/global-content-blocks.php
on line 302
Edit:
I add the function.php
as rnevius said in the comments
Code:
include($_SERVER['DOCUMENT_ROOT'].'/wp-blog/wp-blog-header.php');
include($_SERVER['DOCUMENT_ROOT'].'/wp-blog/wp-includes/functions.php');
and I have
the following fatal warning and fatal error:
PHP Warning: session_start(): Cannot send session cache limiter –
headers already sent (output started at /…./) in
/……/wp-content/plugins/global-content-blocks/global-content-blocks.php
on line 302PHP Fatal error: Cannot redeclare mysql2date() (previously declared
in /…../wp-includes/functions.php:26) in
/……/wp-includes/functions.php on line 42
Edit:
Also, I have already tried it with all the following:
define('WP_USE_THEMES', false);
//include($_SERVER['DOCUMENT_ROOT'].'/wp-blog/wp-load.php');
include($_SERVER['DOCUMENT_ROOT'].'/wp-blog/wp-blog-header.php');
and
define('WP_USE_THEMES', false);
include($_SERVER['DOCUMENT_ROOT'].'/wp-blog/wp-load.php');
//include($_SERVER['DOCUMENT_ROOT'].'/wp-blog/wp-blog-header.php');
Edit:
This may help to think ideas:
We have the following structure:
domain.com/test/
domain.com/wp-blog/
domain.com/wp-blog/test/
If the file file.php
if in the /test/
it doesn’t work.
domain.com/test/file.php
domain.com/wp-blog/
domain.com/wp-blog/test/
If the file file.php
is in the /wp-blog/
it works!!
domain.com/test/
domain.com/wp-blog/file.php
domain.com/wp-blog/test/
If the file file.php
is in the /wp-blog/test/
it works!!
domain.com/test/
domain.com/wp-blog/
domain.com/wp-blog/test/file.php
Every folder on the “domain” has 755 and files 644 permissions. So it is not a “permission” problem. any other thoughts?
You’re missing the variable that stops it from loading all the output: