Pre-1.1 Module API

WordPoints version 1.1.0 brought some updates to the module API, including plugin like file headers. This page explains the changes that were made.

Module Loading #

One of the main changes in the API was how modules were loaded by the plugin. Before version 1.1.0, it was like this:

If you create a .php file in the modules directory, the file will automatically be loaded by WordPoints on each page load after all plugins have been loaded. If you put some code in the file it will get executed each time. You’ve just created your very first WordPoints Module!

Now that isn’t the case. A module’s code is never executed unless it is activated (except for running {the uninstall process} on deletion). Before, a module needed to check whether it was active before running code:

WordPoints Modules differ from plugins in that they are always loaded whether they have been activated or not. This means that if you want to be able to deactivate your module, you need to check whether it is active before it does anything. This is done using the wordpoints_module_is_active() function.

The code that registers your module and performs activation, deactivation and uninstallation needs to go outside of the if statement.

This is no longer the case. In fact, the wordpoints_module_is_active() function has been deprecated, and is_wordpoints_module_active() has taken its place.

The previous API also required that if the module was divided into several files organized in a folder, that the main file had the same name as the folder:

If your module has multiple files, then you can organize them in a folder however you like — the only restriction is that the main file must have the same name as the module folder.

This is no longer a requirement, however it is still considered best practice and is highly recommended.

Module Registration #

Before 1.1.0, a module needed to register itself with the plugin in order to show up on the Modules administration screen (its code would be loaded either way, see above):

To get WordPoints to recognize your module, you need to add some code to it that registers it with WordPoints.

Module registration takes place on the 'wordpoints_modules_register' action, after all modules have been loaded. The function used to register a module is wordpoints_register_module(). The following code example will register a module named ‘My Module’.

In version 1.1.0, the registration process has been replaced by the {file headers}. Now WordPoints detects this information without having to execute the module’s code, the same way WordPress handles plugins.