1.Introduction

The MainWP Codex documents the API (Application Programming Interface) hooks available to MainWP developers, and how to use them to create your own MainWP Extension.

This article assumes you have already read WordPress Plugin API, which gives an overview (and many details) of how to develop a plugin. This article is specifically about the API of “Hooks”, also known as “Filters” and “Actions”, that MainWP uses to set your plugin in

3.1.Adding your Extension to MainWP

3.1.1.mainwp-getextensions

Description
The “mainwp-getextensions” filter is used to add your extension to MainWP.

Usage

Where ‘plugin_get_extension’ is the function MainWP should call when the $extensions array is being 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.

plugin_get_extension should be unique function name. It cannot match any other function name already declared.

Examples
Both examples use the following two actions to add the settings page header and footer: mainwp-pageheader-extensions and mainwp-pagefooter-extensions

Add an extension without authentication
The following example adds your extension to MainWP.

Add an extension with authentication
The following example adds your extension to MainWP.

Please not to add the authentication you need to implement an mechanism to fill up the $locked variable in the example above.

3.2.Checking if the MainWP plugin is enabled

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 initialisation.

In the example above you can see that the child-plugin calls the function “activate_this_plugin”, this function will include the initialisation of your own plugin.

3.3.Initialising your own plugin

The function “activate_this_plugin” is called when the main is initialized. Since extensions may be enabled and disabled in our extension section 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. (You will find more about this in the filters using this key)

3.5.Distributing your Extension

You have a few different options to getting your Extension out to MainWP users. With any of these options just send us an email at *protected email* and we’ll be sure to mention your Extension in our weekly email.

6.Add content to MainWP

6.1.Dashboard Filters

Description
The “mainwp-getmetaboxes” filter is used to add metabox-widgets on the main dashboard.

Usage

Where ‘filter_function_name’ is the function MainWP should call when the $metaboxes array is being retrieved. Note that the filter function must return an array of metaboxes after it is finished processing, or no widgets will be displayed, and other plugins also filtering the $metaboxes array may generate errors.

filter_function_name should be unique function name. It cannot match any other function name already declared.

Example
The example below uses the child key, without a correct key your metabox will not be added. How to retrieve your child key is explained here.

6.2.Page Filters

6.2.1.mainwp-getsubpages-page

Description
The “mainwp-getsubpages-page” filter is used to add tabs on the Page screen.

Usage

Where ‘filter_function_name’ is the function MainWP should call when the $subpages array is being retrieved. Note that the filter function must return an array of subpages after it is finished processing, or no subpages will be displayed, and other plugins also filtering the $subpages array may generate errors.

filter_function_name should be unique function name. It cannot match any other function name already declared.

Example
The example uses the following two actions to add the page header and footer: mainwp-pageheader-page and mainwp-pagefooter-page.

It also uses the child key, without a correct key your sub-page will not be added. How to retrieve your child key is explained here.

6.2.2.mainwp-getsubpages-plugins

Description
The “mainwp-getsubpages-plugins” filter is used to add tabs on the Plugins screen.

Usage

Where ‘filter_function_name’ is the function MainWP should call when the $subpages array is being retrieved. Note that the filter function must return an array of subpages after it is finished processing, or no subpages will be displayed, and other plugins also filtering the $subpages array may generate errors.

filter_function_name should be unique function name. It cannot match any other function name already declared.

Example
The example uses the following two actions to add the Plugins page header and footer: mainwp-pageheader-plugins and mainwp-pagefooter-plugins.

It also uses the child key, without a correct key your sub-page will not be added. How to retrieve your child key is explained here.

6.2.3.mainwp-getsubpages-themes

Description
The “mainwp-getsubpages-themes” filter is used to add tabs on the Themes screen.

Usage

Where ‘filter_function_name’ is the function MainWP should call when the $subpages array is being retrieved. Note that the filter function must return an array of subpages after it is finished processing, or no subpages will be displayed, and other plugins also filtering the $subpages array may generate errors.

filter_function_name should be unique function name. It cannot match any other function name already declared.

Example
The example uses the following two actions to add the themesheader and footer: mainwp-pageheader-themes and mainwp-pagefooter-themes.

It also uses the child key, without a correct key your sub-page will not be added. How to retrieve your child key is explained here.

6.2.4.mainwp-getsubpages-post

Description
The “mainwp-getsubpages-post” filter is used to add tabs on the Post screen.

Usage

Where ‘filter_function_name’ is the function MainWP should call when the $subpages array is being retrieved. Note that the filter function must return an array of subpages after it is finished processing, or no subpages will be displayed, and other plugins also filtering the $subpages array may generate errors.

filter_function_name should be unique function name. It cannot match any other function name already declared.

Example
The example uses the following two actions to add the Post page header and footer: mainwp-pageheader-post and mainwp-pagefooter-post.

It also uses the child key, without a correct key your sub-page will not be added. How to retrieve your child key is explained here.

6.2.5.mainwp-getsubpages-settings

Description
The “mainwp-getsubpages-settings” filter is used to add tabs on the Settings screen.

Usage

Where ‘filter_function_name’ is the function MainWP should call when the $subpages array is being retrieved. Note that the filter function must return an array of subpages after it is finished processing, or no subpages will be displayed, and other plugins also filtering the $subpages array may generate errors.

filter_function_name should be unique function name. It cannot match any other function name already declared.

Example
The example uses the following two actions to add the Settings page header and footer: mainwp-pageheader-settings and mainwp-pagefooter-settings.

It also uses the child key, without a correct key your sub-page will not be added. How to retrieve your child key is explained here.

6.2.6.mainwp-getsubpages-comment

Description
The “mainwp-getsubpages-comment” filter is used to add tabs on the Comment screen.

Usage

Where ‘filter_function_name’ is the function MainWP should call when the $subpages array is being retrieved. Note that the filter function must return an array of subpages after it is finished processing, or no subpages will be displayed, and other plugins also filtering the $subpages array may generate errors.

filter_function_name should be unique function name. It cannot match any other function name already declared.

Example
The example uses the following two actions to add the Comment page header and footer: mainwp-pageheader-comment and mainwp-pagefooter-comment.

It also uses the child key, without a correct key your sub-page will not be added. How to retrieve your child key is explained here.

6.2.7.mainwp-getsubpages-user

Description
The “mainwp-getsubpages-user” filter is used to add tabs on the User screen.

Usage

Where ‘filter_function_name’ is the function MainWP should call when the $subpages array is being retrieved. Note that the filter function must return an array of subpages after it is finished processing, or no subpages will be displayed, and other plugins also filtering the $subpages array may generate errors.

filter_function_name should be unique function name. It cannot match any other function name already declared.

Example
The example uses the following two actions to add the User page header and footer: mainwp-pageheader-user and mainwp-pagefooter-user.

It also uses the child key, without a correct key your sub-page will not be added. How to retrieve your child key is explained here.

6.2.8.mainwp-getsubpages-sites

Description
The “mainwp-getsubpages-sites” filter is used to add tabs on the Sites screen.

Usage

Where ‘filter_function_name’ is the function MainWP should call when the $subpages array is being retrieved. Note that the filter function must return an array of subpages after it is finished processing, or no subpages will be displayed, and other plugins also filtering the $subpages array may generate errors.

filter_function_name should be unique function name. It cannot match any other function name already declared.

Example
The example uses the following two actions to add the Sites page header and footer: mainwp-pageheader-sites and mainwp-pagefooter-sites.

It also uses the child key, without a correct key your sub-page will not be added. How to retrieve your child key is explained here.

6.2.9.mainwp-getsubpages-backups

Description
The “mainwp-getsubpages-backups” filter is used to add tabs on the Backups screen.

Usage

Where ‘filter_function_name’ is the function MainWP should call when the $subpages array is being retrieved. Note that the filter function must return an array of subpages after it is finished processing, or no subpages will be displayed, and other plugins also filtering the $subpages array may generate errors.

filter_function_name should be unique function name. It cannot match any other function name already declared.

Example
The example uses the following two actions to add the Backups page header and footer: mainwp-pageheader-backups and mainwp-pagefooter-backups.

It also uses the child key, without a correct key your sub-page will not be added. How to retrieve your child key is explained here.