don’t call ajax if not plugin page

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 AppBootstrap();
}

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 'AppBootstrap' does not have a method 'process_moviewp_like' in C:xampphtdocscleanwp-includesclass-wp-hook.php on line 287

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

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 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 AppBootstrap has a method named process_moviewp_like as well, because that error doesn’t look like something that would be limited to AJAX.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x