[英]WP is_user_logged_in() doesn't work in integrated site
I am trying to integrate the WP functions in a external php file. 我正在尝试将WP函数集成到外部php文件中。
The problem is that user's and login's authentication functions like is_user_logged_in()
, is_admin()
, etc doesn't work at all. 问题在于,用户和登录名的身份验证功能(例如is_user_logged_in()
, is_admin()
等)根本不起作用。 However, Post's functions are working correct. 但是,Post的功能正常工作。 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 实际上,经过深入的深入搜索后,Web上关于该问题的唯一“好”帖子是WP支持中的以下旧帖子: https : //wordpress.org/support/topic/how-to-in-integrate-sessionlogin-authentication-对非的WordPress的页面-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/ 但是,该解决方案根本不起作用,如果启用了root Cookie
插件,我什至无法登录到/ wp-blog /
So, is there any idea how to integrate and the login functions in the php file? 那么,有什么想法如何集成和php文件中的登录功能吗?
Code is pretty simple: 代码很简单:
file.php 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 PHP警告:session_start():无法发送会话缓存限制器-已在/....../wp-content/plugins/global-content-blocks/global-中发送标头(输出从/..../开始)第302行的content-blocks.php
Edit: 编辑:
I add the function.php
as rnevius said in the comments 我在rnevius的评论中添加了function.php
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 302 PHP警告:session_start():无法发送会话缓存限制器-已在/....../wp-content/plugins/global-content-blocks/global-中发送标头(输出从/..../开始)第302行的content-blocks.php
PHP Fatal error: Cannot redeclare mysql2date() (previously declared in /...../wp-includes/functions.php:26) in /....../wp-includes/functions.php on line 42 PHP致命错误:无法在第42行的/....../wp-includes/functions.php中重新声明mysql2date()(先前在/...../wp-includes/functions.php:26中声明)
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. 如果文件file.php
位于/test/
, 则该文件不起作用。
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!! 如果文件file.php
位于/wp-blog/
则可以正常运行!!
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!! 如果文件file.php
在/wp-blog/test/
则可以使用!
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. “域”上的每个文件夹都有755个文件和644个权限。 So it is not a "permission" problem. 因此,这不是一个“权限”问题。 any other thoughts? 还有其他想法吗?
You're missing the variable that stops it from loading all the output: 您缺少使它无法加载所有输出的变量:
//Load startup
define('WP_USE_THEMES', false);
require_once( $_SERVER[ "DOCUMENT_ROOT" ] . "/wp-blog-header.php" );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.