Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/255.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在wordpress向drupal提交注册时添加钩子?_Php_Wordpress_Drupal - Fatal编程技术网

Php 如何在wordpress向drupal提交注册时添加钩子?

Php 如何在wordpress向drupal提交注册时添加钩子?,php,wordpress,drupal,Php,Wordpress,Drupal,我必须在注册的Wordpress用户到Drupal用户注册上写一个钩子。在提交Wordpress注册时,它还应该将用户名、密码等插入Drupal数据库 drupal版本(7.50) wordpress版本(4.6.1)。当用户在wordpress站点注册时,在wordpress中创建用户,并使用RESTful web服务将POST值发送到Drupal网站 参考: wordpress中的用户注册挂钩:wordpress当前活动主题函数.php文件 add_action( 'user_regis

我必须在注册的Wordpress用户到Drupal用户注册上写一个钩子。在提交Wordpress注册时,它还应该将用户名、密码等插入Drupal数据库

drupal版本(7.50)


wordpress版本(4.6.1)。

当用户在wordpress站点注册时,在wordpress中创建用户,并使用RESTful web服务将POST值发送到Drupal网站

参考:


wordpress中的用户注册挂钩:

wordpress当前活动主题函数.php文件

  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站点根目录中创建一个文件(Drupal\u hook\u 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'));

@mike在drupal中实现REST,并与邮递员检查,然后通过CURL将POST值发送到drupal网站。这是一个很大的过程。我已经添加了thr curl函数,即如何在drupal php页面中钩住用户插入。我有一个单独的页面做这件事