簡體   English   中英

如何為Wordpress使用其他登錄/注冊機制

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

到目前為止,我已經在一個wordpress安裝中集成了一個使用4個主要子域模板的多站點wordpress:college.mysite.com | jobs.mysite.com | advisors.mysite.com | answers.mysite.com

一個wp用戶只需要登錄一次,他們就可以訪問任何wp模板。

但是,我想實現的目標要比這復雜得多。 我不希望新用戶和現有成員使用wordpress作為其訪問私有內容的主要用戶界面。

實際上,我已禁用注冊並完全隱藏了wp登錄。 我想要一個更安全,更少公開的注冊/登錄。

對於這種情況,我希望wordpress忽略默認的登錄憑據,而改用自定義db表名和從同一wordpress數據庫中提取的哈希方法。

例如,我有一個名為ii的yii平台:humhub。 對於要使用wordpress的用戶,他們需要通過humhub登錄並讓wp讀取數據庫表名稱:user而不是wp_users

需要讀取輔助數據庫名稱作為密碼,因為humhub使用:user_password而不是wp_users(user_pass)中的默認值

我嘗試將yii框架與wordpress集成,我嘗試在yii框架中進行調整,以便它分別讀取兩個數據庫,但是它比通過更改默認登錄表名稱簡單地重定向wp登錄憑據要復雜得多。 wordpress文件,請幫助我,

假設您有一些唯一的標識符,以便一個用戶不會與另一個用戶意外碰撞(在YII / HumHub中)

您可以通過以下方式加載WordPress API

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

然后,您可以在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

然后登錄(假設您記得用戶名和密碼!)

$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
}

然后使用Cookie等將它們登錄到WordPress,而不會干擾HumHub

注意-如果WordPress和YII / HumHub之間存在名稱沖突,則上述方法可能無效。 如果是這種情況,您將得到一個包含錯誤詳細信息的php錯誤,並且必須嘗試其他操作(例如Oauth插件)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM