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 badges1 Answer
Reset to default 1You 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.