我正在构建一个 wordpress 系统,我想从外部源而不是 wordpress 数据库对用户进行身份验证。我正在使用 wsdl 服务与外部数据库进行通信,并且我正在根据他们的凭据获取正确的用户信息。但是,我不知道如何进一步处理获得的结果。有人请帮助我。
以下是我到目前为止所做的步骤
在 pluggable.php 中创建自定义函数并调用它user.php
function wp_authenticate_username_password($user, $username, $password) {
if ( is_a($user, 'WP_User') ) { return $user; }
if ( empty($username) || empty($password) ) {
if ( is_wp_error( $user ) )
return $user;
$error = new WP_Error();
if ( empty($username) )
$error->add('empty_username', __('<strong>ERROR</strong>: The username field is empty.'));
if ( empty($password) )
$error->add('empty_password', __('<strong>ERROR</strong>: The password field is empty.'));
return $error;
}
//$user = get_user_by('login', $username); /*Replaced it with the below*/
$user = validate_ep($username,$password);
echo "<pre>";
print_r($user); /*Produces the result in step 3*/
echo "</pre>";
exit;
pluggable.php
与我的外部数据库通信的自定义函数
function validate_ep($username, $userpwd) {
$wsdl = "my web service path";
$client = new SoapClient($wsdl); //(Parameter is the wsdl file in which the services are written.
$newObj = new stdClass;
$user_name = ucfirst($username);
$user_pwd = md5($userpwd);
$display_type = 'wp';
try {
$result = $client->log_process(array(0 => $user_name, 1 => $user_pwd, 2 => $display_type));
if ($result==FALSE)
return FALSE;
foreach($result->item as $key=>$valObj) {
if(!is_numeric($valObj->key)) {
$newObj->{$valObj->key} = $valObj->value;
}
}
/*$actual = unserialize(base64_decode($result));*/
if (count($result) > 0) {
$user = new WP_User;
$user->init($newObj);
return $user;
}
} catch (SoapFault $exp) {
//print_r( $exp->getMessage());
}
return false;
}
从 Web 服务返回的结果
WP_User Object
(
[data] => stdClass Object
(
[id] => ID
[organization] => ID
[login] => UserName
[password] => ***
[name] => Name
)
[ID] => 0
[caps] => Array
(
)
[cap_key] => wp_capabilities
[roles] => Array
(
)
[allcaps] => Array
(
)
[filter] =>
)
有人请帮助我在这些步骤之后能做什么。