我正在制作一个插件,它接收一个表单中输入的关键词,然后处理这个词并在网页中进行搜索,当收到结果时(通过AJAX ),视频将被屏蔽。PHP - 从另一个域的外部文件调用wordpress函数
在我的script.php而不是回显所有的html行中,我使用“include”来包含一个php文件(托管在一个外部域中)与html行,然后这些打印在域中使用插件的人。一切正常,但在想要显示调用Wordpress内部函数的类别列表时,插件失败,显然这是因为脚本试图从托管文件的域中查找这些函数,而不是从本地wordpress。我怎么能这样做?
我的scrypt.js托管在本地域中,即包含在用户将下载的插件的文件中。正如你所看到的,它可以调用外部域中托管的api.php。
<script>
jQuery(function($){
var pluginUrl = '<?php echo plugin_dir_url(__FILE__); ?>' ;
$('[id^="form-busqueda"]').on('submit', function(e) {
e.preventDefault();
$.ajax({
type : 'POST',
url : 'http://example.com/server/api.php',
data : $(this).serialize(),
cache: false,
beforeSend: function(){
$('#results').html('<img src="'+pluginUrl+'../../assets/img/loading.gif" />');
}
}).done(function(data) {
$('#results').html(data);
});
});
});
</script>
好吧,这个查询将通过AJAX到另一个域名托管我api.php文件,该文件将与“包括(” results.php“)”,该文件results.php也回应装在相同的外部域哪里是我的api.php文件
api.php
<?php
//A series of validations are made, variables are generated (example $variable1, and finally the file "results.php" is called that calls all the variables so that finally the content is printed in the site of the client that is using the plugin.
include("results.php");
?>
results.php
<div class="container">
<p><?php echo $variable1 ?></p>
<p><?php echo $variable2 ?></p>
<p><?php echo $variable3 ?></p>
<?php
$category=addslashes($_GET['cat']);
$args = array(
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => 0,
'selected' => $category,
'name' => 'cat_',
);
wp_dropdown_categories($args);
?>
</div>
问题是当我从这个文件中调用Wordpress函数时。但我不知道我还能用什么。我希望我的问题已经清楚了。提前致谢。