Launchpad
Launchpad
Launchpad
  • Introduction
  • General
    • Installation
    • Creating a subscriber
    • Contributing
  • Tutorials
    • Beginner documentation
      • Beginner handbook
        • Creating subscribers
        • Wiring subscribers
        • Installing local environment
        • Adding front-end
        • Building the plugin
      • Plugin life circle
        • Activation
        • Deactivation
        • Uninstall
    • Starting with the framework
    • Migrating to Launchpad
    • Notions
      • Framework concepts
        • Inversion of control
        • Subscribers
        • Dispatcher
      • Good practices
        • Hooks
          • Preventing magic constants
          • Decouple features
          • Sanitize filters output
      • Testing
        • Organize tests
  • CLI
    • Commands
    • Creating a command
  • Testing
    • Unit test
    • Fixtures
    • Integration test
  • Container
    • Architecture
    • Parameters
    • Providers
    • Auto wiring
    • Manual wiring
    • Activation/Deactivation
    • Inflectors
  • Modules
    • Definition
    • Listing
      • Action Scheduler
      • BerlinDB
      • Bus
      • Options
      • Renderer
      • Logger
      • Uninstaller
      • Filesystem
      • Front-end
      • Hook extractor
    • Creating a module
Powered by GitBook
On this page
  • Install the module
  • Creating an uninstall logic
  1. Tutorials
  2. Beginner documentation
  3. Plugin life circle

Uninstall

PreviousDeactivationNextStarting with the framework

Last updated 5 months ago

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 you need to run the following command: composer require wp-launchpad/uninstaller-take-off.

Once the command finished being executed 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 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.

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

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

For that it is important to first using interface and trait:

It is then possible to have access to the inside :

the module wp-launchpad/uninstaller-take-off
a new file uninstall.php
use the @uninstall annotation
add the necessary logic into the provider
HasUninstallerServiceProviderInterface
HasUninstallerServiceProviderTrait
register_uninstaller method to register our uninstaller
the define method