WordPress循环之外的登录用户(_I)

时间:2014-06-16 作者:Rizzo

我有一个会员网站,它维护着一系列书籍。我希望在循环之外的文件夹上有一个页面,可以查看用户是否登录到主站点,然后显示book viewer。如果用户未登录到主站点,则显示其他页面。我想我在吃饼干时遇到了一些麻烦。我安装了Root Cookie Plugin, 帮助

这是我编写的代码,需要做得更好:

<?php
define(\'WP_USE_THEMES\', false); 
if (file_exists(\'../books/wp-blog-header.php\')) {
    require_once(\'../books/wp-blog-header.php\');
} else {
    echo \'ERROR: blog header does not exist\';
}
global $current_user;
get_currentuserinfo();
// Start Site
$sitetitle = \'Book Viewer\';
include \'head.php\';

if ($current_user->ID == 0)
{
    include (\'guest.php\');
    exit;
}
else
{
    include (\'viewer.php\');
}
include \'foot.php\';
?>
我应该使用wp-load.php 而不是wp-blog-header 或者我需要做点什么wp_signon

1 个回复
SO网友:Rizzo

这适用于根cookie:

<?php
define(\'WP_USE_THEMES\', false); 
if (file_exists(\'../books/wp-blog-header.php\')) {
    require_once(\'../books/wp-blog-header.php\');
} else {
    echo \'ERROR: blog header does not exist\';
}

global $current_user;
get_currentuserinfo();

# Either load WordPress : http://codex.wordpress.org/Integrating_WordPress_with_Your_Website
# or Manually define your url like...

$cookieurl = "mybooksite.com";

define( \'COOKIEHASH\', md5( $cookieurl ) );

$cookiename = "wordpress_logged_in_" . COOKIEHASH;

$sitetitle = \'Book Viewer\';
include \'head.php\';


if (isset($_COOKIE[$cookiename])) {
    include (\'viewer.php\');
} else {
    include (\'guest.php\');
}

include \'foot.php\';

?>
不确定是否有更好/更安全的方法。

结束

相关推荐

按上次登录日期排序Get_Users()。有可能吗?

我想创建一个页面,显示按上次登录日期排序的所有博客用户。我尝试了get\\u users()函数,我可以成功地获取用户列表,但不是按照我想要的顺序:$query = get_users(\'&offset=\'.$offset.\'&orderby=login&order=DESC&number=\'.$number); 我认为orderby=登录不是我想要的。。。有没有其他方法可以做到这一点?