¡Hola, amigos! I’m Señor FAQ, the mustached maestro of questions and answers! With my trusty glasses and a book of endless wisdom, I turn dudas into solutions. Soy el héroe de los curiosos and the champion of clarity.
Creating a plugin for JScms involves defining the plugin's metadata, registering hooks, and adding functionality. Here's a step-by-step guide using the demo plugin hello_world as an example:
Create a new folder in the /plugins directory. For this example, we'll name the folder hello_world.
manifest.json FileInside the hello_world folder, create a manifest.json file. This file contains the plugin's metadata:
{
"name": "Hello World",
"description": "A simple plugin that displays a message in the footer.",
"version": "1.0",
"author": "JScms",
"installfile": "",
"uninstallfile": "",
"updatefile": "",
"pluginpath": "hello_world/hello_world.php",
"plugindirectory": "hello_world",
"license_required": "0",
"license_api": "https://jscms.ch"
}
Fields explained:
Create a file named hello_world.php in the plugin folder. This file contains the plugin's functionality:
<?php
use JScmsClassDynamicHooks;
// Prevent direct access
if (!defined('JSCMS_PREVENT_PLUGIN_ACCESS')) {
die('Direct access not allowed.');
}
// Example hook: Add a message to the footer
DynamicHooks::addHook('after_render', function ($jkv, $lang) {
echo "Hello, World! This is a message from the footer plugin.";
}, 'hello_world', 15);
// Example hook: Add a message to the admin footer
DynamicHooks::addHook('after_render_admin', function ($jkv, $lang) {
echo "Hello, Admin! Footer plugin is active.";
}, 'hello_world', 15);
?>
Code explained:
DynamicHooks::addHook() function registers hooks with a name, callback function, and priority.after_render is called after rendering the page, while after_render_admin applies to the admin panel.hello_world folder to the /plugins directory.Hello World plugin.JSCMS_PREVENT_PLUGIN_ACCESS constant to prevent direct access to plugin files.