我正在尝试使用插件函数(wp-bannerize()
) 在我的自定义插件中。但当我写作时:
if( function_exists(\'wp_bannerize\') ){
echo "exist";
}else{
echo "not exist";
}
输出为
not exists
如何在自定义插件中获取此函数?
更新时间:
下面是我的插件代码:
class Infinite_posts{
public function __construct() {
add_action(\'wp_ajax_is_bannerize\', \'load_plugins\');
//when plugin receive an AJAX call with \'is_bannerize\'parameter load_plugins() is triggered
}
public function load_plugins(){
add_action( \'plugins_loaded\', \'show_bannerize\' );
//when all plugin are loaded show_bannerize() is triggered
}
public function show_bannerize(){
if( function_exists( \'wp_bannerize\' ) ) {
echo "exist";
} else {
echo "not exist";
}
}
}
if( !is_admin() )
$infinitePosts = new Infinite_posts();
这里也是我的javascript:
$(\'.gallerie h2\').on(\'click\', function(){
jQuery.post(
\'http://localhost/~sdibenedetto/d-art/htdocs/wp-content/plugins/infinite-posts/infinite-posts.php\',
{
\'action\': \'is_bannerize\',
\'data\': \'foobarid\'
},
function(response){
alert(\'The server responded: \' + response);
}
);
});
这是正确的吗?如何进行AJAX调用并传递参数“is\\u bannize”来触发插件?使用此javascript,我在警报中出现以下错误:
<b>Fatal error</b>: Call to undefined function add_action() in <b>/Users/sdibenedetto/Sites/d-art/htdocs/wp-content/plugins/infinite-posts/infinite-posts.php</b> on line <b>44</b><br />
请帮忙。谢谢