Ecommerce Shopify WordPress Discussion

Developer How to clean up properly when a wordpress plugin uninstalls

So in a plugin for wordpress that I wrote. I want to improve the plugin removal I realized that in the uninstall process I was removing the custom tables and the options where taken care off automatically, but a custom option that stored the licence key and settings was not being removed. Even worse if the licence was active I wasnt deactivating it. So I created a static accessor to deactivate the licence however I thought what if deactivation fails? How do I correctly report that ? The static accessor throws a WP errow if that happens but how do I notify the user? Keep in mind this is during a plugin deactivation so I don't have general access to plugin methods just wordpress native. Because apparently on Stack Exchange anonmyous people downrate if you dont include code here you go: static function uninstall_plugin(): void { if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { exit; } $users = get_users(); foreach ($users as $user){ delete_user_meta($user->ID,'booking'); $user->remove_role('çlient'); } require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/Licence.php'; //inside this static function is where a potential error might occur. Licence::__deactivate(); require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/Database.php'; Database::uninstall(); //remove custom roles remove_role('client'); remove_role('my-plugin-manager'); //remove plugin option. delete_option("my-plugin-option"); }
So the answer to this question is using a hook: $response = $licence->deactivate(); /** * process response to a message ie check for WP_Error etc */ add_action('admin_notices',function ($message){ ?> <div class="notice notice-success is-dismissible"> <p> <?php _e( 'An error occurred during licence deactivation! ', 'vetbook' ); echo "- ".$message; ?> </p> </div> <?php }); So we deactivate and then use the admin_notice hook to post the result. Customise CSS to your heart's content.

December 30, 2023

TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.