Download the PHP package pinkcrab/perique-plugin-lifecycle without Composer
On this page you can find all versions of the php package pinkcrab/perique-plugin-lifecycle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download pinkcrab/perique-plugin-lifecycle
More information about pinkcrab/perique-plugin-lifecycle
Files in pinkcrab/perique-plugin-lifecycle
Package perique-plugin-lifecycle
Short Description A module for the PinkCrab Perique Framework which makes it easy to add subscribers which are triggered during various events within a plugins life cycle(Activation, Deactivation, Uninstall, Update etc).
License MIT
Homepage https://pinkcrab.co.uk
Informations about the package perique-plugin-lifecycle
Perique - Plugin Life Cycle
A module for the PinkCrab Perique Framework which makes it easy to add subscribers which are triggered during various events within a plugins life cycle(Activation, Deactivation, Uninstall etc)
Requires
Perique Plugin Framework 2.0.*
Wordpress 5.9+ (tested from WP5.9 to WP6.2)
PHP 7.4+ (tested from PHP7.4 to PHP8.2)
Why?
Makes for a simple OOP approach to handling WordPress Plugin Life Cycle events such as Activation, Deactivation and Uninstallation.
Connects to an existing instance of the Perique Plugin Framework to make use of the DI container and other shared services. (Please note due to the way these hooks are fired, you may not have full access to your DI Custom Rules, please read below for more details.)
Setup
To install, you can use composer
Installing the Module
This must be bootstrapped with Perique to be used. This can easily be done on your main plugin file.
You can either pass the plugin_base_file
as the path to the main plugin file, or if left empty will assume its the file used to create the app instance.
All events can be passed as there calss name, should be full namespace, or as a string of the class name.
Event Types
There are 3 events which you can write Listeners for. Each of these listeners will implement an interface which requires a single run()
method.
Activation
All classes must implement the PinkCrab\Plugin_Lifecycle\State_Event\Activation
interface.
This would then be run whenever the plugin is activated
Deactivation
All classes must implement the PinkCrab\Plugin_Lifecycle\State_Event\Deactivation
interface.
These events will fail silently when called, so if you wish to catch and handle any errors/exceptions, this should be done within the events run method.
This would then be run whenever the plugin is deactivated
Uninstall
All classes must implement the PinkCrab\Plugin_Lifecycle\State_Event\Uninstall
interface.
We automatically catch any exceptions and silently fail. If you wish to handle this differently, please catch them in your own code.
This would then be run whenever the plugin is uninstalled
Timings
The events are triggered before the init
hook is called, so Perique is only partially booted when these are run. This means that you will have access to the DI_Container
and App_Config
but only custom rules that have been added directly, any rules added via 3rd parties using hooks, will not be available. Try to make events as simple as possible to avoid errors.
Extending
It is possible to create other modules which can be used to add additional events and trigger other actions both before and after the finalise() method is called. This is useful if you wish to add additional events, or trigger other actions.
Adding events
You can use the Plugin_Life_Cycle::STATE_EVENTS
filter to add additional methods.
Const
Plugin_Life_Cycle::STATE_EVENTS
= 'PinkCrab\Plugin_Lifecycle\State_Events'
You can also use the Plugin_Life_Cycle::EVENT_LIST
filter to add additional events, after they have been constructed with the DI container.
Const
Plugin_Life_Cycle::EVENT_LIST
= 'PinkCrab\Plugin_Lifecycle\Event_List'
Triggering actions before finalise
You can use the Plugin_Life_Cycle::PRE_FINALISE
filter to trigger actions before the finalise() method is called.
Const
Plugin_Life_Cycle::PRE_FINALISE
= 'PinkCrab\Plugin_Lifecycle\Pre_Finalise'
Triggering actions after finalise
You can use the Plugin_Life_Cycle::POST_FINALISE
filter to trigger actions after the finalise() method is called.
Const
Plugin_Life_Cycle::POST_FINALISE
= 'PinkCrab\Plugin_Lifecycle\Post_Finalise'
Change Log
- 2.0.1 - Reintroduced the getting the base path from the plugin file, if not defined (thanks @hibernius) and updated dev dependencies.
- 2.0.0 - Updated for Perique V2 and implements the new Module system.
- 1.0.0 - skipped
- 0.2.1 - Updated dev dependencies and GH pipeline.
- 0.2.0 - Improved the handling of Uninstall events and updated all dev dependencies.
- 0.1.1 - Added get_app() to main controller
- 0.1.0 - Inital version