The first thing admin-ajax.php
does is define DOING_AJAX
. Then, it loads wp-load.php
. It does some other stuff, and the first thing it comes across that you have control over is wp-config.php
.
So if you want to stop all ajax, you can add to following to your wp-config.php
file.
if( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
wp_die( '0', 400 );
}
If you don’t have access to the wp-config
file, or just want to do it via a plugin, you can do that too. No need to add it to a hook since if it’s a request that doing ajax, it’s already defined.
/**
* Plugin Name: Stop Ajax
*/
if( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
wp_die( '0', 400 );
}
There will be side effects if you’re using plugins or themes that require ajax, so be careful.