PHPackages                             pinkcrab/perique-plugin-lifecycle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. pinkcrab/perique-plugin-lifecycle

ActiveLibrary[Framework](/categories/framework)

pinkcrab/perique-plugin-lifecycle
=================================

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).

2.1.0(2mo ago)16.6k↓66.7%[2 issues](https://github.com/Pink-Crab/Perique_Plugin_Life_Cycle/issues)[2 PRs](https://github.com/Pink-Crab/Perique_Plugin_Life_Cycle/pulls)1MITPHPPHP &gt;=8.0.0CI passing

Since Dec 8Pushed 2mo agoCompare

[ Source](https://github.com/Pink-Crab/Perique_Plugin_Life_Cycle)[ Packagist](https://packagist.org/packages/pinkcrab/perique-plugin-lifecycle)[ Docs](https://pinkcrab.co.uk)[ RSS](/packages/pinkcrab-perique-plugin-lifecycle/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (7)Dependencies (14)Versions (42)Used By (1)

[![logo](.github/assets/Plugin-Lifecyle.jpg "PinkCrab Perique Plugin Life Cycle")](.github/assets/Plugin-Lifecyle.jpg)

Perique - Plugin Life Cycle
===========================

[](#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)

[![Latest Stable Version](https://camo.githubusercontent.com/8ea617247288081d162a9a8cd75e66132fe11444091b74cf80e7d5004693785a/687474703a2f2f706f7365722e707567782e6f72672f70696e6b637261622f706572697175652d706c7567696e2d6c6966656379636c652f76)](https://packagist.org/packages/pinkcrab/perique-plugin-lifecycle) [![Total Downloads](https://camo.githubusercontent.com/a64b7654524d84d34fe244401dd4d0583b8900bf3dc49e98c738c8f4a897948b/687474703a2f2f706f7365722e707567782e6f72672f70696e6b637261622f706572697175652d706c7567696e2d6c6966656379636c652f646f776e6c6f616473)](https://packagist.org/packages/pinkcrab/perique-plugin-lifecycle) [![Latest Unstable Version](https://camo.githubusercontent.com/119eec034a386f3693b457aa0ee230bd7613eeb3871179354478a9120d175205/687474703a2f2f706f7365722e707567782e6f72672f70696e6b637261622f706572697175652d706c7567696e2d6c6966656379636c652f762f756e737461626c65)](https://packagist.org/packages/pinkcrab/perique-plugin-lifecycle) [![License](https://camo.githubusercontent.com/a15f44d5c6877d6f7e525c8e263fd494c5e884aa3c8c75243e4c52931562b823/687474703a2f2f706f7365722e707567782e6f72672f70696e6b637261622f706572697175652d706c7567696e2d6c6966656379636c652f6c6963656e7365)](https://packagist.org/packages/pinkcrab/perique-plugin-lifecycle) [![PHP Version Require](https://camo.githubusercontent.com/a71e423a4b654264769e1cc935c653e5a86c31e43464463b28e04d978002fcd2/687474703a2f2f706f7365722e707567782e6f72672f70696e6b637261622f706572697175652d706c7567696e2d6c6966656379636c652f726571756972652f706870)](https://packagist.org/packages/pinkcrab/perique-plugin-lifecycle)[![GitHub contributors](https://camo.githubusercontent.com/fdf25636970900502fca396d70ae4d7d905c67aae602dfa9d7e63138e5c93af2/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f636f6e7472696275746f72732f50696e6b2d437261622f506572697175655f506c7567696e5f4c6966655f4379636c653f6c6162656c3d436f6e7472696275746f7273)](https://camo.githubusercontent.com/fdf25636970900502fca396d70ae4d7d905c67aae602dfa9d7e63138e5c93af2/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f636f6e7472696275746f72732f50696e6b2d437261622f506572697175655f506c7567696e5f4c6966655f4379636c653f6c6162656c3d436f6e7472696275746f7273)[![GitHub issues](https://camo.githubusercontent.com/ac856117fb735210ff7659118707522c0efb980566e034a0406a05ffb03fb604/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732d7261772f50696e6b2d437261622f506572697175655f506c7567696e5f4c6966655f4379636c65)](https://camo.githubusercontent.com/ac856117fb735210ff7659118707522c0efb980566e034a0406a05ffb03fb604/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732d7261772f50696e6b2d437261622f506572697175655f506c7567696e5f4c6966655f4379636c65)

[![WordPress 6.6 Test Suite [PHP7.4-8.4]](https://github.com/Pink-Crab/Perique_Plugin_Life_Cycle/actions/workflows/WP_6_6.yaml/badge.svg)](https://github.com/Pink-Crab/Perique_Plugin_Life_Cycle/actions/workflows/WP_6_6.yaml)[![WordPress 6.7 Test Suite [PHP7.4-8.4]](https://github.com/Pink-Crab/Perique_Plugin_Life_Cycle/actions/workflows/WP_6_7.yaml/badge.svg)](https://github.com/Pink-Crab/Perique_Plugin_Life_Cycle/actions/workflows/WP_6_7.yaml)[![WordPress 6.8 Test Suite [PHP7.4-8.4]](https://github.com/Pink-Crab/Perique_Plugin_Life_Cycle/actions/workflows/WP_6_8.yaml/badge.svg)](https://github.com/Pink-Crab/Perique_Plugin_Life_Cycle/actions/workflows/WP_6_8.yaml)[![WordPress 6.9 Test Suite [PHP7.4-8.4]](https://github.com/Pink-Crab/Perique_Plugin_Life_Cycle/actions/workflows/WP_6_9.yaml/badge.svg)](https://github.com/Pink-Crab/Perique_Plugin_Life_Cycle/actions/workflows/WP_6_9.yaml)

[![codecov](https://camo.githubusercontent.com/f198a634ff090c338a70ef4a5f4ed9c9daf9ce4e144f4af8066fac18638a7d2b/68747470733a2f2f636f6465636f762e696f2f67682f50696e6b2d437261622f506572697175655f506c7567696e5f4c6966655f4379636c652f6272616e63682f6d61737465722f67726170682f62616467652e7376673f746f6b656e3d58756376333878727361)](https://codecov.io/gh/Pink-Crab/Perique_Plugin_Life_Cycle)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/f908898c2b29894aa3853a560f802d966ae771ab094b6b951ed6a86514aae6b7/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f50696e6b2d437261622f506572697175655f506c7567696e5f4c6966655f4379636c652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Pink-Crab/Perique_Plugin_Life_Cycle/?branch=master)[![Maintainability](https://camo.githubusercontent.com/7dd859fbe3ac7c6c4c8b60b58331e70d4981f3fb11f6fdd6b6c5bdb3caac9bcd/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f32376161303836616332326630393936353136612f6d61696e7461696e6162696c697479)](https://codeclimate.com/github/Pink-Crab/Perique_Plugin_Life_Cycle/maintainability)

> Requires [Perique Plugin Framework 2.1.\*](https://perique.info)Wordpress 6.6+ (tested from WP6.6 to WP6.9) PHP 7.4+ (tested from PHP7.4 to PHP8.4)

---

Why?
----

[](#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](#Timings).)

---

Setup
-----

[](#setup)

To install, you can use composer

```
$ composer require pinkcrab/perique-plugin-lifecycle
```

Installing the Module
---------------------

[](#installing-the-module)

This must be bootstrapped with Perique to be used. This can easily be done on your main plugin file.

```
// file ../wp-content/plugins/acme_plugin/plugin.php

// Boot the app as normal
$app = (new App_Factory())
    ->default_setup()
    ->module(
        Plugin_Life_Cycle::class,
        fn(Plugin_Life_Cycle $module): Plugin_Life_Cycle => $module
            ->plugin_base_file(__FILE__) // Optional
            ->event(SomeEvent::class)
            ->event('Foo\Some_Class_Name')
     )
    ->boot();
```

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
-----------

[](#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

[](#activation)

All classes must implement the `PinkCrab\Plugin_Lifecycle\State_Event\Activation` interface.

```
class Create_Option_On_Activation implements Activation {
    public function run(): void{
        update_option('plugin_activated', true);
    }
}
```

> This would then be run whenever the plugin is activated

### Deactivation

[](#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.

```
class Update_Option_On_Deactivation implements Deactivation {
    public function run(): void{
        try{
            update_option('plugin_activated', false);
        } catch( $th ){
            Something::send_some_error_email("Deactivation event 'FOO' threw exception during run()", $th->getMessage());
        }
    }
}
```

> This would then be run whenever the plugin is deactivated

### Uninstall

[](#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.

```
class Delete_Option_On_Uninstall implements Uninstall {
    public function run(): void{
        try{
            delete_option('plugin_activated');
        } catch( $th ){
            // Do something rather than let it be silently caught above!
        }
    }
}
```

> This would then be run whenever the plugin is uninstalled

Timings
-------

[](#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
---------

[](#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

[](#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'

```
add_filter(
    Plugin_Life_Cycle::STATE_EVENTS,
    function( array $events ): array {
        $events[] = SomeEvent::class;
        return $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'

```
add_filter(
    Plugin_Life_Cycle::EVENT_LIST,
    function( array $events ): array {
        $events[] = new SomeEventInstance();
        $events[] = $this->container->create(SomeOtherInstance::class);
        return $events;
    }
);
```

### Triggering actions before finalise

[](#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'

```
add_action(
    Plugin_Life_Cycle::PRE_FINALISE,
    function( Plugin_Life_Cycle $module ): void {
        // Do something before finalise is called.
    }
);
```

### Triggering actions after 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'

```
add_action(
    Plugin_Life_Cycle::POST_FINALISE,
    function( Plugin_Life_Cycle $module ): void {
        // Do something after finalise is called.
    }
);
```

Change Log
----------

[](#change-log)

- 2.1.0 - Updated for Perique V2.1 and added some additional filters to allow for extending the module.
- 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

###  Health Score

47

—

FairBetter than 93% of packages

Maintenance71

Regular maintenance activity

Popularity25

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 95.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~139 days

Recently: every ~265 days

Total

12

Last Release

72d ago

Major Versions

0.2.0 → 1.0.0-RC32023-03-02

0.2.1 → 1.0.0-RC12023-03-02

1.0.0-RC5 → 2.0.02023-04-03

PHP version history (4 changes)0.1.0PHP &gt;=7.1.0

1.0.0-RC3PHP &gt;=7.2.0

1.0.0-RC2PHP &gt;=7.4.0

2.1.0PHP &gt;=8.0.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/d82b9e8ef7816d3d0b9812ad233f61f6a313f529e0ac85721781b46ad292e1ea?d=identicon)[glynnquelch](/maintainers/glynnquelch)

---

Top Contributors

[![gin0115](https://avatars.githubusercontent.com/u/28779094?v=4)](https://github.com/gin0115 "gin0115 (104 commits)")[![hibernius](https://avatars.githubusercontent.com/u/5625168?v=4)](https://github.com/hibernius "hibernius (5 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/pinkcrab-perique-plugin-lifecycle/health.svg)

```
[![Health](https://phpackages.com/badges/pinkcrab-perique-plugin-lifecycle/health.svg)](https://phpackages.com/packages/pinkcrab-perique-plugin-lifecycle)
```

###  Alternatives

[laravel/telescope

An elegant debug assistant for the Laravel framework.

5.2k67.8M190](/packages/laravel-telescope)[spiral/roadrunner

RoadRunner: High-performance PHP application server and process manager written in Go and powered with plugins

8.4k12.2M84](/packages/spiral-roadrunner)[nolimits4web/swiper

Most modern mobile touch slider and framework with hardware accelerated transitions

41.8k177.2k1](/packages/nolimits4web-swiper)[laravel/dusk

Laravel Dusk provides simple end-to-end testing and browser automation.

1.9k36.7M255](/packages/laravel-dusk)[laravel/prompts

Add beautiful and user-friendly forms to your command-line applications.

708181.8M591](/packages/laravel-prompts)[cakephp/chronos

A simple API extension for DateTime.

1.4k47.7M119](/packages/cakephp-chronos)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
