FDP add-ons.

Freesoul Deactivate Plugins already gives you the possibility to manage your plugins depending on many conditions, but if you need to match very specific conditions, you can even make your custom FDP add-on with just a few lines of code.
A FDP add-on is a very tiny plugin that you can create for your specific case.
FDP add-ons are supported from FDP v. > 2.1.8

Let’s give an example. Imagine you want to deactivate some plugins depending on the IP address of the user. The actual version of FDP doesn’t allow you to do that. Well, in this case, you can make an FDP add-on where you can write your custom conditions.
We will see soon how to do it.

How to create an FDP add-on.

Create a plugin folder.

First, create a new folder in your plugins directory, located at wp-content/plugins.

The directory needs a name. Every name that is allowed for a plugin directory is ok, but It’s best practice to give a name that includes the word FDP, and a word that describes the goal of the add-on.
If we want to make an FDP add-on to disable specific plugins depending on the IP address, we can for example have a directory named FDP-by-IP.

 

Create the main file.

Inside the directory that you have just created, create a PHP file with the same name with the extension .php. Following our example, we will create the file FDP-by-IP.php.
Until now we have a directory named FDP-by-IP, and an empty main file FDP-by-IP.php, located in wp-content/plugins/FDP-by-IP/FDP-by-IP.php.
Now we need to add the header to the main file to transform it into a plugin. You can refer to the codex if you need more information about the plugin header.

Here is an example of the main file.

<?php

/*

Plugin Name: FDP by IP

Description: FDP add-on to deactivate plugins by IP address

Author: Your Name

Author URI: https://yourwebsite.com/

Domain Path: /languages/

Text Domain: fdp-by-ip

Version: 0.0.1

*/

What you see above is enough for the main file. You don’t need to write any code into the main file.
Thanks to the main file, WordPress recognizes your FDP add-on as a plugin, nothing else.
The next step will be creating a JSON file that stores the information needed by FDP to create the settings page of your plugin.

Create the JSON file.

In the same directory of your add-on create a JSON file named fdp.json.
In this file, you have to include the information FDP needs to create the settings page of your plugin.

Let’s explain following our example. Here you have the content of the JSON file that works for our example:

{

"parent_menu": "users",

"submenu_name": "By IP",

"description": "Disable plugins by IP address."

}

After creating the JSON file, if you activate your add-on, you will see its settings page under Freesoul Deactivate Plugins => Users => By IP.

As you see in the picture, what you write as a description in the JSON file will be displayed on the settings page.

The following FDP parent menu slugs are available for the property “parent_menu”:

  • singles
  • post-types
  • archives
  • device
  • miscellaneus
  • integration
  • users
FDP add-on settings page

Create the conditions.php file.

In the same directory of your add-on create now the file conditions.php.

Inside this file, you need to assign the conditions to the variable $conditions.
Let’s continue with our example. Here you have the code to disable specific plugins depending on the IP address:

$conditions = isset( $_SERVER['REMOTE_ADDR'] )

    && in_array(

        sanitize_text_field( $_SERVER['REMOTE_ADDR'] ),

        array( '172.31.155.111', '172.31.114.119' )

     );

Add-on activation.

After creating your add-on, activate it from the plugins page.
It’s important that you activate it when Freesoul Deactivate Plugins is active. If you activate it when FDP is not active, then FDP will not recognize it as its add-on, and it will not work.

Wrapping up.

In order, to create a custom FDP add-on for your specific case, you need to:

  • Create a directory into the plugins directory.
  • Name the directory with a descriptive name, better if it includes the word FDP.
  • Create the PHP main file in the directory.
  • Name the main file with the same name as the directory.
  • Add the plugin header to the main file.
  • Create a JSON file in the directory.
  • Write a JSON with the properties “parent_menu”, “submenu_name”, and “description”.
  • Write the conditions.php file in the directory.
  • Assign the conditions to the variable $conditions in the conditions.php file.
  • With FDP active, activate your add-on from the plugins page.
  • That’s it!