最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

don't call ajax if not plugin page

programmeradmin1浏览0评论

I created a plugin that uses ajax the problem is that the plugin requests are loaded on the whole site and not only on the plugin page I need to call the function only on the plugin page

plugin main code

// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
    die;
}

define("Importer",plugin_basename(__FILE__));
define("PLUGIN_DIR",__DIR__);

require_once PLUGIN_DIR."/vendor/autoload.php";


if(is_admin()){
    $moviewp = new \App\Bootstrap();
}

debug error every time I do something on the site using ajax

call_user_func_array() expects parameter 1 to be a valid callback, class 'App\Bootstrap' does not have a method 'process_moviewp_like' in C:\xampp\htdocs\clean\wp-includes\class-wp-hook.php on line 287

how do i exclude site ajax requests and separate them from the plugin?

I created a plugin that uses ajax the problem is that the plugin requests are loaded on the whole site and not only on the plugin page I need to call the function only on the plugin page

plugin main code

// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
    die;
}

define("Importer",plugin_basename(__FILE__));
define("PLUGIN_DIR",__DIR__);

require_once PLUGIN_DIR."/vendor/autoload.php";


if(is_admin()){
    $moviewp = new \App\Bootstrap();
}

debug error every time I do something on the site using ajax

call_user_func_array() expects parameter 1 to be a valid callback, class 'App\Bootstrap' does not have a method 'process_moviewp_like' in C:\xampp\htdocs\clean\wp-includes\class-wp-hook.php on line 287

how do i exclude site ajax requests and separate them from the plugin?

Share Improve this question asked Feb 18, 2021 at 16:42 Vincenzo PiromalliVincenzo Piromalli 1989 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

You can check for WordPress's DOING_AJAX constant:

if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
    return;
}

...or use the related wp_doing_ajax() function:

if ( wp_doing_ajax() ) {
    return;
}

However, I'd also double-check to make sure that App\Bootstrap has a method named process_moviewp_like as well, because that error doesn't look like something that would be limited to AJAX.

发布评论

评论列表(0)

  1. 暂无评论