【发布时间】:2018-01-24 01:37:10
【问题描述】:
有没有一种方法可以根据用户名而不是 ID 来更新用户库?当我尝试创建用户时,将在另一个网站上添加,但创建的 ID 与我的主网站上的不同。现在我的问题是根据用户名更新该用户库。有可能吗?
这是我尝试更新的内容,它已经可以使用,但基于 ID。
更新的验证码
function update_user_api( $entry, $form ) {
$firstname = $entry[3];
$lastname = $entry[4];
$email = $entry[5];
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://mywebsite/wp-json/wp/v2/users/11?context=edit", //I would like to change this to username if possible
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "first_name=".$firstname."&last_name=".$lastname."",
CURLOPT_HTTPHEADER => array(
"authorization: Basic MDAwOjAwMA==",
"cache-control: no-cache",
"content-type: application/x-www-form-urlencoded",
"postman-token: 0a02f782-eab1-e4d7-e866-737c6894fad3"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
}
add_action( 'gform_after_submission_16', 'update_user_api', 10, 2 );
【问题讨论】:
标签: wordpress wordpress-rest-api