来自覆盖文件夹的 WordPress 身份验证


Wordpress authentication from override folder

我在wordpress网站的根目录中有一个文件夹。因此,wordpress 似乎被绕过了(预期的结果),但现在我想向谨慎的模块添加功能(位于 wordpress 根目录中的代码)以检查我们是否已登录到 wordpress...这能做到吗?

澄清文件夹结构

/wp-admin/
/wp-content/
index.php
... (all wordpress files)
/my-folder/    <~ I want to access via http://mysite.com/my-folder/
    index.php  <~ I want a line of php to check if user is logged in to wordpress or not
    style.css
为此,

您需要包含/要求包含所有单词press文件的文件"wp-blog-header.php",并使用返回布尔值的WorldPress函数"is_user_logged_in()",有关更多详细信息,请参阅此处的WorldPress PHP代码。

因此,您可以在文件/my-folder/index.php 中使用这样的函数来检查用户是否已登录到您的 WorldPress

function checkWPLogin(){
    require_once("../wp-blog-header.php");
    return is_user_logged_in();
}