字preSS:从外部调用wp_create_user功能? [英] Wordpress : Call wp_create_user function from external?
本文介绍了字preSS:从外部调用wp_create_user功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Word中preSS,我想创建外部新用户。我发现这是词preSS功能:
wp_create_user($的用户名,密码$,$电子邮件);
所以,我怎么可以运行外部调用请这个功能呢?
我的意思是,如何运行此功能从任:
- 通过用GET,像简单的URL:
www.example.com/adduser/?username=james&password=simpletext&email=myemail
- 经卷曲与POST
..从外部网站。
解决方案
您可以尝试这一点,但也确保收听网址有一个处理程序来处理你的字preSS请求
端(使用 GET
methof)
函数curlAdduser($ strUrl)
{
如果(空($ strUrl))
{
回报错误:无效的URL给';
} $ CH = curl_init();
curl_setopt($ CH,CURLOPT_URL,$ strUrl);
curl_setopt($ CH,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ CH,CURLOPT_CONNECTTIMEOUT,30);
curl_setopt($ CH,CURLOPT_CUSTOMREQUEST,'GET');
$收益率= curl_exec($ CH);
curl_close($ CH);
返回$返回;
}
从外部站点调用函数:
<$p$p><$c$c>curlAdduser(\"www.example.com/adduser?username=james&password=simpletext&email=myemail\"); 更新:是 POST
法
函数curlAdduser($ strUrl,$数据){
$栏='';
的foreach($数据,$关键=&GT; $值){
$领域。= $键。 =。 $值。 '和;';
}
$栏= RTRIM($领域,'和;'); $ CH = curl_init();
curl_setopt($ CH,CURLOPT_URL,$ strUrl);
curl_setopt($ CH,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ CH,CURLOPT_CONNECTTIMEOUT,30);
curl_setopt($ CH,CURLOPT_POST,1);
curl_setopt($ CH,CURLOPT_POSTFIELDS,$领域);
$收益率= curl_exec($ CH);
curl_close($ CH);
返回$返回;
}
通话与数据的功能
$数据=阵列(
用户名= GT; 詹姆斯,
密码=&GT; 的SimpleText
电子邮件=&GT; 我的电子邮件
);
curlAdduser(www.example.com/adduser,$数据);
In Wordpress, i want to create New Users from external. I've found this is function in wordpress:
wp_create_user( $username, $password, $email );
So how can i run this function from external call please?
I mean, how to run this function from either:
- Via simple URL with GET, like:
www.example.com/adduser/?username=james&password=simpletext&email=myemail
- Via cURL with POST
.. from external website.
解决方案
You may try this but also make sure that the listening url has a handler to handle the request in your WordPress
end (using GET
methof)
function curlAdduser($strUrl)
{
if( empty($strUrl) )
{
return 'Error: invalid Url given';
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $strUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
$return = curl_exec($ch);
curl_close($ch);
return $return;
}
Call the function from external site :
curlAdduser("www.example.com/adduser?username=james&password=simpletext&email=myemail");
Update : using POST
method
function curlAdduser($strUrl, $data) {
$fields = '';
foreach($data as $key => $value) {
$fields .= $key . '=' . $value . '&';
}
$fields = rtrim($fields, '&');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $strUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
$return = curl_exec($ch);
curl_close($ch);
return $return;
}
Call the function with data
$data = array(
"username" => "james",
"password" => "simpletext",
"email" => "myemail"
);
curlAdduser("www.example.com/adduser", $data);
这篇关于字preSS:从外部调用wp_create_user功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文