Uninstall

The uninstall logic is some logic executed when the plugin is executed.

By default, Launchpad doesn't ship with a way to execute logic on uninstall.

However, it is possible to install a module to have uninstall logic.

Install the module

To install the module wp-launchpad/uninstaller-take-off you need to run the following command: composer require wp-launchpad/uninstaller-take-off.

Once the command finished being executed a new file uninstall.php should have been added to your project and it is now possible to take advantage of the uninstall module.

Creating an uninstall logic

In Launchpad, to create a logic which will be executed when the plugin is uninstalled, we need to use an Uninstaller.

To create an uninstaller, any class can be used as the only requirement is to use the @uninstall annotation inside the docblock of at least one of the methods:

class MyUninstaller {
    /**
    * @uninstall
    */
    public function unregister_options() {
        
    }
}

Once the uninstaller class is created, it needs to be registered on a service provider to be loaded.

For that it is important to first add the necessary logic into the provider using HasUninstallerServiceProviderInterface interface and HasUninstallerServiceProviderTrait trait:

class Provider extends AbstractServiceProvider implements HasUninstallerServiceProviderInterface {
   use HasUninstallerServiceProviderTrait; 
   
   public function define() {

   }
} 

It is then possible to have access to the register_uninstaller method to register our uninstaller inside the define method:

class Provider extends AbstractServiceProvider implements HasUninstallerServiceProviderInterface {
   use HasUninstallerServiceProviderTrait; 
   
   public function define() {
    $this->register_uninstaller(MyUninstaller::class);
   }
} 

Last updated