🧩 Plugin Development Guide
emlog supports a plugin mechanism, allowing developers to easily add needed functions to the system.
Implementation Principle
Throughout the operation of emlog, we have defined some action events. When these events are encountered, emlog will automatically call all plugin functions bound to that event, thereby implementing the plugin's functionality.
Hook Function: doAction
The doAction function is built into the emlog core code and serves as the so-called plugin mounting point (hook).
// This is the mounting point for the index head. When the homepage loads, the plugin functions mounted on this point will be executed.
doAction('index_head')
Plugin Hook: addAction
addAction is used by plugins to mount their own functions to a mounting point. It is written in the plugin file. It takes two parameters: the mounting point name and the plugin's own function name.
// The plugin's add_some_style function is mounted to the system's index_head mounting point.
// Whenever the system executes to the index_head mounting point, the add_some_style function will be called.
addAction('index_head','add_some_style');
function add_some_style() {
// Add some styles, etc.
}
Development Standards
File Structure
- Plugin Directory:
/content/plugins. Each folder under the plugin directory represents a plugin. - Plugin English Alias: For example, the system's built-in tips plugin has the alias:
tips. Only plugins with the directory structure "Plugin English Alias/Plugin English Alias.php" are recognized, e.g.,tips/tips.php.
| File | Description |
|---|---|
| xxx.php | Main plugin file |
| xxx_callback.php | Event callback related function file |
| xxx_setting.php | Plugin backend settings page (Visible only to administrators) |
| xxx_user.php | Plugin backend settings page (Visible to everyone) |
| xxx_show.php | Plugin frontend page |
| preview.jpg | Plugin icon, used for backend plugin list display, size: 75x75 pixels |
The xxx in the table above is the plugin English alias. Detailed introductions to plugin files are below.