我创建了一个插件,并将其安装在任何wordpress网站上。出于任何原因,我需要从其他站点(不是wordpress站点)调用这些插件上的函数。
我已经尝试使用cURL 和file_get_contents 要调用该函数,在一些wordpress网站上它运行良好,但在另一些wordpress网站上它不工作。
调用函数失败,因为wordpress站点有重定向URL,或者wordpress站点安装了其他插件,如验证码、安全性等。
以下是我的插件中的代码/功能:
Class Myplugin{
..........
function get_wp_version(){
// to do
}
function call_api(){
if($_GET[\'get_wp_version\'] && $_GET[\'token\']){
$wp_version = $this->get_wp_version();
echo $wp_version;
}
}
........
}
下面是我用来从另一个站点调用函数的代码:$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, \'http://mysite.com/?call_api=get_wp_version&token=xxx\');
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER[\'HTTP_USER_AGENT\']);
curl_setopt($ch, CURLOPT_TIMEOUT, 0);
$curl_msg = curl_exec($ch);
任何帮助都将不胜感激!哎呀,打字错误!我的插件的函数应该是这样的:
Class Myplugin{
..........
function get_wp_version(){
// to do
}
function call_api(){
if($_GET[\'call_api\'] && $_GET[\'token\']){
if($_GET[\'call_api\'] == \'get_wp_version\'){
$wp_version = $this->get_wp_version();
echo $wp_version;
}
}
}
........
}