Skip to content

Plugin activation

Metapress comes with a plugin activation service that can be used to setup your plugin's activation hooks. The service is already included by default into the Plugin's container but it only fires if the config.php file has the appropriate settings.

Configuration

Open the config.php file and add the following code:

php
use Your_Plugin_Name\My_Plugin_Activation;

return [
    'activation' => My_Plugin_Activation::class,
];

The activation key is the fully qualified class name of your own custom activation class. The service will be instantiated and the framework will handle the rest behind the scenes.

The activation class

The activation class is responsible for handling all the logic that needs to be executed when the plugin is activated. It's highly recommended that the class extends the AbstractPluginActivation class provided by the framework.

Your class should then implement the magic method __invoke() which will be called when the plugin is activated.

php
<?php

namespace Your_Plugin_Name;

use Sematico\Metapress\Abstracts\AbstractPluginActivation;

class My_Plugin_Activation extends AbstractPluginActivation
{
    public function __invoke()
    {
        // Do something when the plugin is activated
    }
}