Is there an option to execute javascript file only on plugin deactivation
I'm creating a custom plugin for WordPress and I'm trying to execute javascript
file only on plugin deactivation.
I'm using register_deactivation_hook()
and wp_enqueue_script()
to execute file only on plugin deactivation.
There are no errors in the code since the javascript
code works well if it is called outside the register_deactivation_hook()
This is what I've tried so far:
register_deactivation_hook( __FILE__, 'deactivation' );
function deactivation() {
function delete_rest_api() {
wp_enqueue_script('deactivation_data_api', plugins_url('assets/js/deactivation_data_api.js', __FILE__));
}
add_action( 'admin_enqueue_scripts', 'delete_rest_api' );
}
In the end, the plugin needs to execute that javascript
file only during plugin deactivation.
Thanks in advance.
Topic deactivation Wordpress javascript
Category Web