AnsweredAssumed Answered

Password parameter not working while creating user

Question asked by haris haris on Mar 6, 2017
Latest reply on Apr 22, 2017 by

Hi All, I am trying to create a new user using using canvas LMS API. At first I was creating user with out sending anything in pseudonym[password] parameter and everything was working fine. Now I am sending the password too in the request but the request is not creating a user anymore. if I remove the password from the parameters it works fine again.


Here is my code:


add_action('user_register', 'create_canvas_user', 10, 1);

function create_canvas_user( $user_id ) {
global $wpdb;
$max_id = $wpdb->get_var( 'SELECT MAX(id) FROM wp_users');
$name = $_POST['field_1'];
$email = $_POST['signup_email'];

$url = "https://<mysite>/api/v1/accounts/1/users";
$token = 'hidden';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt( $curl, CURLOPT_HTTPHEADER, array( 'Authorization: Bearer ' .$token ) );
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_POSTFIELDS, array(
'user[name]' => $name,
'user[short_name]' => $name,
'pseudonym[unique_id]' => $email,
'pseudonym[password]' => 'haris',

curl_setopt($curl, CURLOPT_ENCODING, "");
$curlData = curl_exec($curl);
$res = array();
$res = json_decode($curlData);
//print_r ($curlData);
$can_id = $res->id;

global $wpdb;
$db_res = $wpdb->insert('wp_user_map', array('wp_id' => $max_id,'canvas_id' => $can_id));
echo $db_res;


any idea where i am going wrong?