| 1 |
# How to add a new addon |
| 2 |
|
| 3 |
This document explains how the CookieBot plugin can be expanded with addons to block cookies set by specific third-party WordPress Themes and Plugins. |
| 4 |
|
| 5 |
Addon classes |
| 6 |
--- |
| 7 |
Every addon is contained in its own class. |
| 8 |
- All addon classes should be located in a subdirectory of [](../src/addons/controller/addonssrc/addons/controller/addons](../src/addons/controller/addons](../src/addons/controller/addons) |
| 9 |
- Addon classes for third party plugins should extend the `Base_Cookiebot_Plugin_Addon` abstract class. |
| 10 |
- Addon classes for third party themes should extend the `Base_Cookiebot_Theme_Addon` abstract class. |
| 11 |
- There is also a miscellaneous `Base_Cookiebot_Other_Addon` abstract class, which is used for WordPress core features like embedded videos. |
| 12 |
|
| 13 |
Addons with alternative versions |
| 14 |
--- |
| 15 |
Addons can return a different addon class for each incompatible version. |
| 16 |
- The `ALTERNATIVE_ADDON_VERSIONS` class constant should contain an array of strings. |
| 17 |
- Each array key should correspond to a valid semver version number of the plugin or theme. |
| 18 |
- Each array value should point to the classname of the addon for that previous plugin/theme version. |
| 19 |
- One example is the [](../src/addons/controller/addons/custom_facebook_feed/Custom_Facebook_Feed.phpCustom_Facebook_Feed](../src/addons/controller/addons/custom_facebook_feed/Custom_Facebook_Feed.php](../src/addons/controller/addons/custom_facebook_feed/Custom_Facebook_Feed.php) addon, which had to block its cookies in a different manner for [](../src/addons/controller/addons/custom_facebook_feed/Custom_Facebook_Feed_Version_2_17_1.phpan older version](../src/addons/controller/addons/custom_facebook_feed/Custom_Facebook_Feed_Version_2_17_1.php](../src/addons/controller/addons/custom_facebook_feed/Custom_Facebook_Feed_Version_2_17_1.php) |
| 20 |
|
| 21 |
Steps |
| 22 |
--- |
| 23 |
|
| 24 |
1. Add a new addon to [](../src/addons/addons.phpsrc/addons/addons.php](../src/addons/addons.php](../src/addons/addons.php) |
| 25 |
2. Create a directory in [](../src/addons/controller/addonssrc/addons/controller/addons](../src/addons/controller/addons](../src/addons/controller/addons) |
| 26 |
3. Create a class in that new directory (copy class from another addon and adjust the namespace, classname, interfaces and methods.) |
| 27 |
4. Edit the `load_addon_configuration` method. This is the only method that needs to be worked on in order to block the cookies. |
| 28 |
5. Update all variables and methods according to the addon plugin. |
| 29 |
6. Test |
| 30 |
7. Create integration test if you did use dependencies from the addon plugin. (We run daily tests to see if the dependencies from the addons plugin are still valid.) |
| 31 |
8. Send a pull-request in github |
| 32 |
|
| 33 |
Example |
| 34 |
--- |
| 35 |
1. New addon to [](../src/addons/addons.phpsrc/addons/addons.php](../src/addons/addons.php](../src/addons/addons.php) |
| 36 |
|
| 37 |
```php |
| 38 |
Litespeed_Cache::class, |
| 39 |
matomo::class, |
| 40 |
Instagram_Feed::class, |
| 41 |
Add_To_Any::class, |
| 42 |
``` |
| 43 |
|
| 44 |
2. Create directory 'add_to_any' in src/addons/controller/addons |
| 45 |
|
| 46 |
3. Create a class 'Add_To_Any' in 'add_to_any' directory (copy class from another addon and rename everything accordingly) |
| 47 |
|
| 48 |
5. Go to 'load_addon_configuration' method. Write your cookie-blocking logic in that function. You can find more information about how to block cookies in [how-to-block-cookies](how-to-block-cookies.md). |
| 49 |
|
| 50 |
6. Test if the cookies are blocked. |
| 51 |
|
| 52 |
7. Create integration test for the addon dependencies: https://github.com/CybotAS/CookiebotAddons/blob/develop/tests/integration/addons/test-add-to-any.php |
| 53 |
|
| 54 |
8. Send a pull-request to our github repository. |
| 55 |
|