MainWP allows you to create your own extension and plug it into our main plugin. To do this we have added some actions and filters to our main plugin.
Here is an example of how to implement your own plugin, afterward the actions and filters used are explained:
mainwp_getextensions – Adding your Extension
The mainwp_getextensions filter is used to add your extension to MainWP.
Where mainwp_getextensions is the function MainWP should call when the $extensions array is retrieved. Note that the filter function must return an array of extensions after it is finished processing, or no extensions will be displayed, and other plugins also filtering the $extensions array may generate errors.
mainwp_getextensions should be unique function name. It cannot match any other function name already declared.
Examples 1: Add an extension without authentication
Examples 1: Add an extension with authentication
Examples 1: Add an extension without authentication and with custom name and icon
mainwp_activated_check – Check if MainWP Dashboard is Active
To check if the MainWP Dashboard plugin is enabled, we work with a two-step mechanism.
First, you have the filter mainwp_activated_check. This filter will return true if the main plugin is activated. Because sometimes our main plugin is activated after the extension plugin is activated we also have a second step, listening to the mainwp_activated action. This action is triggered by MainWP after initialization.
activate_this_plugin – Initialising your own plugin
The function activate_this_plugin is called when the main is initialized. Since extensions may be enabled and disabled in Extensions management page, we have to check if this particular plugin is enabled.
This is done with the mainwp_extension_enabled_check hook. If the plugin is not enabled this will return false, if the plugin is enabled, an array will be returned containing a key. This key is used for some data requests to our main.
Distributing your Extension
You have a few different options for getting your Extension out to MainWP users. With any of these options just send us an email at support@mainwp.com and we’ll be sure to mention your Extension in our weekly email.
Free Extensions
If you plan on making your Extension free for anyone to use you can add it directly to WordPress.org. If you have never added a plugin to WordPress.org before there is a quick tutorial on WPBeginner.
Paid Extensions
If you plan on selling your Extension you can:
Add it to your own site and promote (harder)
Add it to http://codecanyon.net (easier)