简体   繁体   English

如何为Wordpress使用其他登录/注册机制

[英]How can I use a different login/signup mechanism for wordpress

I have so far integrated a multisite wordpress that uses 4 main subdomain templates in a single wordpress installation: college.mysite.com | 到目前为止,我已经在一个wordpress安装中集成了一个使用4个主要子域模板的多站点wordpress:college.mysite.com | jobs.mysite.com | jobs.mysite.com | advisors.mysite.com | advisors.mysite.com | answers.mysite.com answers.mysite.com

A wp user is only required to login once and they inmediately have acccess to any wp template. 一个wp用户只需要登录一次,他们就可以访问任何wp模板。

However, What I would like to achieve is a bit more complicated than that. 但是,我想实现的目标要比这复杂得多。 I don't want new users and existing members to use wordpress as their main user interface to access private content. 我不希望新用户和现有成员使用wordpress作为其访问私有内容的主要用户界面。

In fact I have disabled registration and hidden wp login altogether. 实际上,我已禁用注册并完全隐藏了wp登录。 I would like a more secure and less public signup/login. 我想要一个更安全,更少公开的注册/登录。

For this occassion I would like wordpress to ignore the default login credentials and use instead custom db table names and hashmethod pulled from the same wordpress database. 对于这种情况,我希望wordpress忽略默认的登录凭据,而改用自定义db表名和从同一wordpress数据库中提取的哈希方法。

For instance I have a yii platform called: humhub. 例如,我有一个名为ii的yii平台:humhub。 For a user to use wordpress they would need to login through humhub and have wp read the db table names: user instead of wp_users 对于要使用wordpress的用户,他们需要通过humhub登录并让wp读取数据库表名称:user而不是wp_users

a secondary db name would need to be read for the password because humhub uses: user_password instead of the default value within wp_users (user_pass) 需要读取辅助数据库名称作为密码,因为humhub使用:user_password而不是wp_users(user_pass)中的默认值

I've tried integrating yii framework with wordpress, I've tried tweaking here and about within the yii framework so that it reads two databases separately but it's far more complicated than simply redirecting the wp login credentials by changing the default login table names within the wordpress files, please help me, 我尝试将yii框架与wordpress集成,我尝试在yii框架中进行调整,以便它分别读取两个数据库,但是它比通过更改默认登录表名称简单地重定向wp登录凭据要复杂得多。 wordpress文件,请帮助我,

Let's assume you have some unique identifier so that one user will not accidentally collide with another (in YII/HumHub) 假设您有一些唯一的标识符,以便一个用户不会与另一个用户意外碰撞(在YII / HumHub中)

You can load up the WordPress API via 您可以通过以下方式加载WordPress API

require_once("/path/to/wp-load.php");
//Found normally in the WordPress root directory alongside wp-config.php

You can then when creating a new user in HumHub do: 然后,您可以在HumHub中创建新用户时执行以下操作:

wp_create_user( $username, $password, $email ); 
//Where username is the unique identifier
//password is ideally a random hash
//email is their email if relevant

And then log them in (assuming you remembered the username and password!!) 然后登录(假设您记得用户名和密码!)

$creds = array();
$creds['user_login'] = $username;
$creds['user_password'] = $password;
$creds['remember'] = true;
$user = wp_signon( $creds, false );
if ( !is_wp_error($user) ) {
    ob_start(); //flush buffers - otherwise login won't work or user gets redirected to dashboard
    $user_id = $user->ID;
    wp_set_current_user( $user_id, null );
    wp_set_auth_cookie( $user_id,true );
    do_action( 'wp_login', $username );
    ob_end_clean();
} else {
   //Handle the login error
}

They are then logged into WordPress with cookies etc without any headers interfering with HumHub 然后使用Cookie等将它们登录到WordPress,而不会干扰HumHub

Note - the above method may not work is there is a name conflict between WordPress and YII/HumHub. 注意-如果WordPress和YII / HumHub之间存在名称冲突,则上述方法可能无效。 You will get a php error with details of the conflict if that is the case and will have to try something else (such as Oauth plugin) 如果是这种情况,您将得到一个包含错误详细信息的php错误,并且必须尝试其他操作(例如Oauth插件)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM