check_admin_referer fails on new AJAX plugin uninstall with "Are you sure you want to do this?"

Before WordPress core had AJAX plugin actions, uninstallation in register_uninstall_hook() worked fine:

 if ( ! current_user_can( 'activate_plugins' ) )
 return;

 check_admin_referer( 'bulk-plugins' );

It needs a real HTTP/POST, so if you you disable JavaScript in your browser on WP 4.9 it works.

But it fails with AJAX plugin uninstallation with Are you sure you want to do this? I'd like to keep up strong security.

What is the solution? What is the AJAX counterpart of check_admin_referer( 'bulk-plugins' ) in plugin uninstallation?

Thanks.

Topic ajax uninstallation Wordpress

Category Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.