extend wordpress session into main domain

2020-04-21 04:23发布

I have a site that uses wordpress for community purposes, it is installed under subdirectory "mysite/community" but when I try to call wordpress functions into "mysite" I cannot retrieve the logged user.

Here's my sample code:

require $xcart_dir . DIR_COMMUNITY . '/wp-load.php';

wp_get_current_user();
if ( 0 == $current_user->ID ) {
    echo "Not logged in";
} else {
    echo "Logged in";
}

标签: php wordpress
2条回答
淡お忘
2楼-- · 2020-04-21 04:47

Cookies can contain a Path, this is probably what you are looking for: http://codex.wordpress.org/Editing_wp-config.php#Additional_Defined_Constants

To allow the cookie for all path on the domain, use define('COOKIEPATH',"/");.

You can also set the cookie domain in wp-config.php: http://codex.wordpress.org/Editing_wp-config.php#Set_Cookie_Domain

Use ".example.com" to allow the cookie for all subdomains of example.com.

查看更多
smile是对你的礼貌
3楼-- · 2020-04-21 05:03

This plugin does exactly that, http://wordpress.org/plugins/root-cookie/

Although I highly recommend yscik's solution to edit wp-config, in case you do not have access to the wp-config.php you can use this plugin.

查看更多
登录 后发表回答