wp_insert_user() failing but only from AWS Lambda.
-
Hi! I’m getting a very weird error that I can’t really explain.
I have some Python code that sends a request to a custom REST API endpoint I added. I have a plugin that listens to the request and adds a new user by doing:
$random_password = wp_generate_password(8, false); $user_data = array( 'user_login' => $user_email, 'user_pass' => $random_password, 'user_email' => $user_email, 'role' => 'subscriber', 'first_name' => $first_name, 'last_name' => $last_name, ); $user_id = wp_insert_user($user_data);
where the fields are passed from the REST API HTTP request.
For some reason the plugin works as expected if I send the request from my local machine, but it doesn’t work when the request is sent from my AWS Lambda, giving a
"User insertion failed: Not enough data to create this user."
error.When I print out the request content, the one sent from my local machine looks identical to the one sent from my AWS Lambda.
When I print out
$user_data
indebug.log
, the content and type of the array is identical.This is the code I use to print out the array:
echo "Type of \$user_data: " . print_r(gettype($user_data)) . " -- "; if (empty($user_data)) { echo "\$user_data is empty." . " -- "; } else { echo "\$user_data is not empty." . " -- "; echo "Contents of \$user_data: " . " -- "; print_r($user_data); } if (is_wp_error($user_id)) { $error_message = $user_id->get_error_message(); print_r("User insertion failed: $error_message"); $result = false; } else { $result = $user_id; }
and this is the error I get:
"arrayType of $user_data: 1 -- $user_data is not empty. -- Contents of $user_data: -- Array\n(\n [user_login] => [email protected]\n [user_pass] => aa0fDLcG\n [user_email] => [email protected]\n [role] => subscriber\n [first_name] => John\n [last_name] => Doe\n)\nUser insertion failed: Not enough data to create this user.{\"code\":\"insert_error\",\"message\":\"Error in inserting user with the user_email [email protected]\"
As it can be seen the array is not empty but I still get the
Not enough data to create this user
error.Unfortunately with my current host I don’t have access to
wp-include
, so I can’t debugwp_insert_user()
directly fromuser.php
.Thank you!
- The topic ‘wp_insert_user() failing but only from AWS Lambda.’ is closed to new replies.