我必须在注册的WordPress用户上写一个挂钩以进行Drupal用户注册。在提交WordPress注册时,它也应该将用户名,密码等插入Drupal数据库。
Drupal版本(7.50(
WordPress版本(4.6.1(。
wordpress当前活动主题函数函数
add_action( 'user_register', 'myplugin_registration_save');
function myplugin_registration_save( ) {
//extract data from the post
//set POST variables
$url = 'http://xxxxxx.com/drupal/drupal_hook_register.php';
$fields = array(
'email' => urlencode($_POST['email']),
'password' => urlencode($_POST['password'])
);
//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
}
和在drupal站点root目录中创建一个文件(drupal_hook_register.php(。此功能将直接将所有WordPress注册字段插入Drupal数据库。
// define static var
define('DRUPAL_ROOT', getcwd());
// include bootstrap
include_once('./includes/bootstrap.inc');
// initialize stuff
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
$email = $_REQUEST['email'];
$password = $_REQUEST['password'];
//This will generate a random password, you could set your own here
//$password = user_password(8);
//set up the user fields
$fields = array(
'mail' => $email,
'pass' => $password,
'status' => 1,
'init' => 'email address',
'roles' => array(
DRUPAL_AUTHENTICATED_RID => 'authenticated user',
),
);
//the first parameter is left blank so a new user is created
$account = user_save('', $fields);
//print_r($account);
// If you want to send the welcome email, use the following code
// Manually set the password so it appears in the e-mail.
$account->password = $fields['pass'];
// Send the e-mail through the user module.
//drupal_mail('user', 'register_no_approval_required', $email, NULL, array('account' => $account), variable_get('site_mail', 'noreply@example..com'));
当用户在WordPress网站中登录时,请在WordPress中创建用户,并使用RESTFUL WEB服务将POST值发送到Drupal网站。
参考:https://www.drupal.org/project/restful
WordPress中的用户注册挂钩:https://codex.wordpress.org/plugin_api/action_reference/user_register