BUG – Tracking code removed on deactivation
-
Hello,
I saw that you didn’t address this one https://wordpress.org/support/topic/deactivation-loses-the-code/ and it is basically same thing. You are not using deactivation hook properly since it should be used to clear temp data: “The deactivation hook is sometimes confused with the uninstall hook. The uninstall hook is best suited to delete all data permanently such as deleting plugin options and custom tables, etc.”
In your plugin when it is DEACTIVATED it also remove all tracking codes which is incovinient for end user having to copy code again from your platform and in most cases it can be temporary deactivations maybe for periods of time wher tracking doesn’t need to run or when debugging something or else…
You can use suggested approach from WordPress documentation with uninstall.php file https://developer.wordpress.org/plugins/plugin-basics/uninstall-methods/Or, alternative one using
register_uninstall_hook()with your existing class:Changes to
plerdy_heatmap_tracking.php:1. Modify line 36 – change hook type and make it static:
// REPLACE:
register_deactivation_hook(__FILE__, array( $this, 'delete_option' ) );
// WITH (register_uninstall_hookcannot use$thisbecause the class instance doesn't exist during uninstall.
):
register_uninstall_hook(__FILE__, array( 'Plerdy', 'uninstall' ) );2. Modify lines 48-51 – rename method, make it static, add
checkboxcleanup:// REPLACE: public function delete_option($order_id) { delete_option('plerdy_tracking_script'); delete_option('plerdy_abtracking_script'); } // WITH: public static function uninstall() { delete_option('plerdy_tracking_script'); delete_option('plerdy_abtracking_script'); delete_option('checkbox'); }When we are at it also consider changing ‘checkbox’ since it is too generic, it needs to be prefixed e.g. plerdy_collect_commerce_data or somethihg like that.
You must be logged in to reply to this topic.