MainWP Codex

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.API/Getting Started

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:

3.1.Adding your Extension to MainWP

Adding your extension is done by using the getextensions-hook

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

To check if the 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 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.4.Getting Help

If your stuck on your development and could use a little help from the MainWP Developers you can join us on our Slack Channel. We’ll do our best to help you but we will not build it for you.

If you are already member jump in at https://mainwp.slack.com

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 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)

4.Current Hooks for Actions

Current list of action hooks in MainWP.

4.1.mainwp-pageheader-comment

Description
The “mainwp-pageheader-comment” action is used to render the tabs on the Comment screen. It’s used together with mainwp-pagefooter-comment and mainwp-getsubpages-comment

Usage

Example
An example is listed in mainwp-getsubpages-comment

4.3.mainwp-pageheader-backups

Description
The “mainwp-pageheader-backups” action is used to render the tabs on the Backups screen. It’s used together with mainwp-pagefooter-backups and mainwp-getsubpages-backups

Usage

Example
An example is listed in mainwp-getsubpages-backups

4.5.mainwp-pageheader-sites

Description
The “mainwp-pageheader-sites” action is used to render the tabs on the Sites screen. It’s used together with mainwp-pagefooter-sites and mainwp-getsubpages-sites

Usage

Example
An example is listed in mainwp-getsubpages-sites

4.7.mainwp-pageheader-page

Description
The “mainwp-pageheader-page” action is used to render the tabs on the Page screen. It’s used together with mainwp-pagefooter-page and mainwp-getsubpages-page

Usage

Example
An example is listed in mainwp-getsubpages-page

4.9.mainwp-pageheader-plugins

Description
The “mainwp-pageheader-plugins” action is used to render the tabs on the Plugins screen. It’s used together with mainwp-pagefooter-plugins and mainwp-getsubpages-plugins

Usage

Example
An example is listed in mainwp-getsubpages-plugins

4.11.mainwp-pageheader-post

Description
The “mainwp-pageheader-post” action is used to render the tabs on the Post screen. It’s used together with mainwp-pagefooter-post and mainwp-getsubpages-post

Usage

Example
An example is listed in mainwp-getsubpages-post

4.12.mainwp-pagefooter-post

Description
The “mainwp-pagefooter-post” action is used to render the footer on the Post screen. It’s used together with mainwp-pageheader-post and mainwp-getsubpages-post

Usage

Example
An example is listed in mainwp-getsubpages-post

4.13.mainwp-pageheader-settings

Description
The “mainwp-pageheader-settings” action is used to render the tabs on the Settings screen. It’s used together with mainwp-pagefooter-settings and mainwp-getsubpages-settings

Usage

Example
An example is listed in mainwp-getsubpages-settings

4.15.mainwp-pageheader-themes

Description
The “mainwp-pageheader-themes” action is used to render the tabs on the Themes screen. It’s used together with mainwp-pagefooter-themes and mainwp-getsubpages-themes

Usage

Example
An example is listed in mainwp-getsubpages-themes

4.17.mainwp-pageheader-user

Description
The “mainwp-pageheader-user” action is used to render the tabs on the User screen. It’s used together with mainwp-pagefooter-user and mainwp-getsubpages-user

Usage

Example
An example is listed in mainwp-getsubpages-user

4.19.mainwp-pageheader-extensions

Description
The “mainwp-pageheader-extensions” action is used to render the tabs on the Extensions screen. It’s used together with mainwp-pagefooter-extensions and mainwp-getextensions

Usage

Example
An example is listed in mainwp-getextensions

5.Current Hooks for Filters

In MainWP we work with two kind of filter hooks: filters to fetch data and filters that allow a child-plugin to add content to the main site.

5.1.Fetch data from MainWP

5.1.1.mainwp-getsites

Description
The “mainwp-getsites” filter may be used to retrieve information about the child-sites added to MainWP.

Usage
$sites = apply_filters(‘mainwp-getsites’, $pluginFile, $childKey, $siteId);
Parameters
$pluginFile
(string) (required) The pluginfile is required here, mostly __FILE__
$childKey
(string) (required) The child-key is required here, how to retrieve your child key is explained here
$siteId
(integer) (optional) The id of the child-site you wish to retrieve

Return Values
(array)
An array which contains an array per child-site with the following keys: id, url, name

Examples
Display the number of child-sites:

Display the information of a specific child-site:

Display the information of all child-sites:

5.1.2.mainwp-getgroups

Description
The “mainwp-getgroups” filter may be used to retrieve information about the groups added to MainWP.

Usage
$sites = apply_filters(‘mainwp-getgroups’, $pluginFile, $childKey, $groupId);
Parameters
$pluginFile
(string) (required) The pluginfile is required here, mostly __FILE__
$childKey
(string) (required) The child-key is required here, how to retrieve your child key is explained here
$groupId
(integer) (optional) The id of the group you wish to retrieve

Return Values
(array)
An array which contains an array per group with the following keys: id, name, websites, where websites is an array of website ids.

Examples

Display information about the groups:

Display the information of a the child-sites in a specific group (uses mainwp-getsites):

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.1.1.mainwp-getmetaboxes

6.2.Page Filters

These filters are used to add extra sub-pages. Filter function arguments: Array with the sub page slug, title and callback to render.

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.

Suggest Edit