BBPress是一个轻量级的论坛程序,作为Wordpress的同门师弟,自然能够与Wordpress很好的集成,但我近日试装后却发现无法用Wordpress中的用户登录,登录后没有任何提示,更不能进行管理操作,注册新用户也出现同样的情况。在BBPress的论坛上看到有人遇到了同样的问题,但尝试回复中所提到的一些解决方法并没有效果,今天论坛版主(Key Master)mdawaffe在留言中提议去看一下BBPress文档中有关Cookie的部分,而这段关于Cookie的说明的确帮助我找到了解决登录问题的办法:
Cookies
If you’ve installed bbPress into a subdirectory of your WordPress installation, define $bb->wp_home and $bb->wp_siteurl as your WordPress blog address and WordPress address, respectively. Both sites will now share the same cookies so that when you’re logged into one, you’re logged into the other. (The addresses referenced above can be found in WordPress’ Options -> General admin tab.)
If bbPress is not installed in a subdirectory of your WordPress install, you’ll probably need to adjust both bbPress’ and WordPress’ cookies to meet your specific requirements. Below is a brief outline of the variables and constants that control the cookie behavior in the two programs.
PHP bbPress WordPress
name $bb->usercookie USER_COOKIE
name $bb->passcookie PASS_COOKIE
path $bb->cookiepath COOKIEPATH
path $bb->sitecookiepath SITECOOKIEPATH
domain $bb->cookiedomain COOKIE_DOMAIN
注意文中的红色部分,这就是我问题的原因所在。我最初所设计的网站结构是在一个主域名下设置两个子目录,分别装Wordpress(子目录1)与BBPress(子目录2),但要将BBPress与子目录1中的Wordpress整合在一起(即BBPress装入该WP的数据库,与其共享用户数据),这样就导致了BBPress与Wordpress(子目录1)无法共享Cookie,才使得登录前后没有什么变化,BBPress文档中提到的解决方法是调整WP和BP的Cookie设置,这显然有些麻烦,而且我也不知道该如何调整:wink:,那么只好使用腾挪的“笨办法”了:将子目录2移至子目录1下,注意转移后需要更改BBPress配置文件中的相关部分:
// Just the domain name; no directories or path. There should be no trailing slash here.
$bb->domain = ‘http://主域名’; // Example: ‘http://bbpress.example.com’
// There should be both a leading and trailing slash here. ‘/’ is fine if the site is in root.
$bb->path = ‘/子目录2/’; // Example: ‘/forums/’
将其中的$bb->path = ‘/子目录2/’;改为$bb->path = ‘/子目录1/子目录2/’;即可。