非 wordpress 页面上的 Wordpress if_logged_in 函数 [英] Wordpress if_logged_in function on Non-wordpress page

查看:39
本文介绍了非 wordpress 页面上的 Wordpress if_logged_in 函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想以某种方式在非 wordpress 页面上使用此功能:

I want to somehow use this function on a non-wordpress page :

<?php
if (is_user_logged_in()){
    echo "Welcome, registered user!";
}
else {
    echo "Welcome, visitor!";
};
?>

有没有办法做到这一点?有人告诉我,如果我在非 wordpress 页面中包含我的 wp-header.php 是可能的,但我不想这样做.还有其他方法吗?

Is there any way to do this? I was told it is possible if I include my wp-header.php in the Non-wordpress page, but I do not want to do this. Any other methods?

推荐答案

您必须将 Wordpress Core 加载到当前脚本中.你可以这样做:

You have to load the Wordpress Core into your current script. You can do it like this:

    //wp-admin
    require $_SERVER['DOCUMENT_ROOT'].'/wp-load.php';

    //Check if someone is logged in
    global $user_level;
    get_currentuserinfo() ;
    //echo "User Level = $user_level<br>";
    if ($user_level < 1)
            die('You aren\'t allowed to view this!');

这篇关于非 wordpress 页面上的 Wordpress if_logged_in 函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆