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");
}
2
Answers
So the answer to this question is using a hook:
So we deactivate and then use the admin_notice hook to post the result. Customise CSS to your heart's content.
This is the biggest challenge with the concept of Licences and WordPress Plugins. How do you not only validate a valid or invalid licence and what does that architecture look like. In addition to this, what does the technical implementation details look like to support and enforce this validity.
From your question, it certainly sounds like the architecture is wrong. It sounds like the licence validity is being placed on the WordPress Installation end rather than the Licence Giver end.
It’s a much broader discussion that the StackOverflow website is going to be able to help with, but I hope that provides a bit of food for thought on this topic.