Adding Code to Plugin Files in Base directory

Adding code to files in the Base directory.

The Base directory contains all the tools we will use in your plugin. The base directory also contains the files that run when we deactivate and activate the plugin.

Recall that in the domain-core.php file, we added the register activation and register deactivation hooks. These hooks call methods which reference the following classes.

  • Regsiter_activation hook invokes the activate_domain_core_plugin function, which calls the activate method in Activate class via Domain_Core\Base\Activate and 
  • Regsiter_deactivation hook invokes the deactivate_domain_core_plugin function, which calls the deactivate method in Deactivate class via Domain_Core\Base\Activate.

The BaseController directory will there have the following files.

  1. Activate Class – for the activate method.
  2. Deactivate Class – for reactive method.
  3. BaseController Class – for plugin base methods.

We will import the package and namespace lines for these three files from the Init.php file.

Note

Make changes to the namespace in these three files. Since all the three files are inside the Base directory, we need to append it to the new namespace. Therefore, the new namespace should be Domain_Core\Base.

Activate.php

Open the Activate.php file and add the following code.

The Activate Class has the activate method, which flushes rewrite rules when the plugin is activated.

Deactivate.php

Open the Deactivate.php file and add the following code.

The Deactivate Class has the deactivate method, which also flushes rewrite rules when the plugin is activated.

Note

You can call more functions when activating or deactivating the plugin by adding functions inside in their respective activate and deactivate methods. 

BaseController.php

Open the BaseController.php file and add the following code.

We use the BaseController class to set up a series of base methods. These methods are plugin references for stuff such as the plugin directory path, among others.