The myCred Plugin consist of several modules that work together to manage and execute different tasks and features. You can use the Module API to create your own modules for myCred or adjust / disable existing modules to suit your needs. Modules should be used when you want to:
- Add an admin page under the myCred or any point type menu and or
- Add settings to the myCred > Settings page.
The Module API uses the myCred_Module abstract class which provides several built in functions to make module creations as easy as possible, providing you the code for mundane tasks like adding a new admin page or added custom settings to the myCred Core.
myCred comes with the following built-in modules:
|Handles BuddyPress integrations. Only available if BuddyPress is installed.
|Handles exports. Added in 1.7
|Handles all log pages in the admin area.
|Handles balance adjustments and user profile edits. Added in 1.7
|Handles network settings. Only available on Multisite installations.
|Handles the settings page.
Create New Module
Creating a module using the myCred_Module class is relatively easy and straight forward. In order for us to utilize the myCred_Module abstract class, our module class must extend it. This gives us the ability to use pre-defined class functions or replace them with our own before using them if they do not fit our needs.
Basic myCred Module class example.
First we will need to setup or class constructor using the myCred_Module constructor. This way, the abstract class will setup our module based on the settings we provide.
While our class constructor only uses one variable; the point type, the parent constructor uses three:
- Module id – This needs to be a unique module ID, by default I use the class name as the ID.
- Module arguments – An associative array of settings for our module.
- Point Type – The point type used with this module.
The following arguments are available for myCred Modules:
|A unique ID for the module. Used for settings and module loading.
|Must be set to true if you are registering settings. Set to false if you want to register your own settings. Defaults to true.
|If you want the module to register your own settings using the WordPress Settings API, you can define either a single option key in a form of a string or an array of option values. Not used if no settings are required to be saved / used.
|Array of default options. Only used if you are using
option_id to register your settings.
|The screen ID if we are adding a custom admin screen.
|If adding a custom admin screen, this array needs to contain the menu label and the screen page title.
|The capability required to access the custom admin screen.
|If adding a custom admin screen, the menu position.
|Must be set to true if the module needs to insert settings on the point type's settings page.
|Should myCRED enqueue the accordion script on the custom admin screen. Defaults to false.
Module argument example for adding in a custom admin screen under the myCred menu.
Accessing myCred Instances
Once we have constructed our module, we need to load the module via the load() function. Using this function will hook your module into several myCred instances allowing you to use any of the
By default, there are four available instances you can use:
|Accessed via class method
When loading our custom module from outside the myCred plugin, the most important thing is to load the module once the myCred_Module abstract hook is available and not before.
You can use the mycred_pre_init action hook to load your module class which only fires when myCred is ready and the abstract class is available.
If you are using myCred 1.7 or higher and need to load your module for all point types, you could instead use the mycred_load_modules filter. (Not available before 1.7)
Example: Load our custom module for all point types. This example will add an admin screen under each point type menu called “My Admin Page”.
Example of how to use the mycred_pre_init action hook to load our custom myCred module in versions older then 1.7.