最合适的回答,由SO网友:Brooke. 整理而成
这是一篇很好的文章,它解释了一种解决方案,可以实现我个人使用过的目标。http://justintadlock.com/archives/2012/10/16/how-i-run-a-membership-site
在您的情况下,您需要自定义th3_club_member_template
功能如下:
add_filter( \'template_redirect\', \'nifty_log_in_check\', 99 );
function nifty_log_in_check( $template ) {
if ( is_page(\'clients_only\' ) ) && !current_user_can( \'view_client_content\' ) ) //change this to suite your needs
{
wp_redirect( home_url() );
exit();
}
}
然后,您可以使用主题“我的登录”来设置登录表单。
用户登录后,您可以手动重定向它们或使用类似的插件Peters Login Redirect
要手动重定向它们,可以执行以下操作:
function nifty_login_redirect( $redirect_to, $request, $user ){
//is there a user to check?
global $user;
if( isset( $user->roles ) && is_array( $user->roles ) ) {
//check for admins
if( in_array( "administrator", $user->roles ) ) {
// redirect them to the default place
return $redirect_to;
} else {
return home_url().\'/client-area\'; //change this
}
}
else {
return $redirect_to;
}
}
add_filter("login_redirect", "nifty_login_redirect", 10, 3);
[Codex]