注册区+保留区

时间:2012-10-08 作者:Salvatore Dibenedetto

正如这篇文章的标题所说,我需要创建一个注册表,让读者注册到我的网站,并访问每个人都看不到的特殊内容。

是否有处理此功能的插件?我尝试了一些,但在登录后,他们在wordpress管理后端重定向了我。

我不想让人们访问网站管理页面。

有什么建议吗?

1 个回复
SO网友:Adam

将其粘贴到函数中。php文件并根据注释进行编辑。

add_filter(\'login_redirect\', \'redirect_user\', 10);

function redirect_user(){

    global $user;

    //where you want to redirect users too
    $redirect = home_url() . \'/where-do-we-go-from-here/\';

   /*
    *  each role listed in this array will be redirect to above URL
    *  if you only have one user role to redirect then simply remove
    *  the others.
    */

    $role = array( 

        \'subscriber\',
        \'another_role\',
        \'etc\'

    );

    if ( in_array( $user->roles[0], array( \'administrator\') ) ) {

        //admin will go to the dashboard
        return admin_url();

    } elseif ( in_array( $user->roles[0], $role ) ) {

        return $redirect;

    } 

}
我应该补充一下,

$redirect = home_url() . \'/where-do-we-go-from-here/\';
//returns http://www.example.com/where-do-we-go-from-here/
也可以写为,

$redirect = home_url( \'/where-do-we-go-from-here/\' );
//returns http://www.example.com/where-do-we-go-from-here/
。。。函数的位置home_url 接受路径作为其参数之一。

结束

相关推荐