@@ -4,18 +4,18 @@ With phpMyFAQ 4.0 and later, we have a new, currently experimental plugin system
44This system allows you to extend phpMyFAQ with new features.
55The plugin system is based on the Symfony Dependency Injection component.
66
7- ## 9.1 Plugin installation
7+ ## 9.1 Installation
88
99Plugins are installed in the ` content/plugins ` directory of your phpMyFAQ installation.
1010The plugin directory should contain a subdirectory for each plugin, e.g. ` content/plugins/HelloWorld ` .
1111The plugin directory should contain a ` HelloWorldPlugin.php ` file that implements the ` PluginInterface ` interface.
1212If you want to remove a plugin, you can delete the plugin in the plugin directory.
1313
14- ## 9.2 Plugin configuration
14+ ## 9.2 Configuration
1515
1616Plugins can have configuration options, implemented via the ` PluginConfigurationInterface ` interface.
1717Configuration options can be defined in the plugin configuration class with Constructor Property Promotion by adding
18- public properties.
18+ public properties. There are no other options to configure plugins at this time.
1919
2020### 9.3.1 Example configuration class
2121
@@ -41,7 +41,7 @@ The plugin manager is an instance of the `PluginManager` class.
4141
4242To uninstall a plugin, you can delete the plugin directory from the ` content/plugins ` directory.
4343
44- ## 9.5 Plugin examples
44+ ## 9.5 Examples
4545
4646phpMyFAQ comes with an example plugin that demonstrates how to use the plugin system called ` HelloWorldPlugin ` .
4747
@@ -50,9 +50,14 @@ phpMyFAQ comes with an example plugin that demonstrates how to use the plugin sy
5050``` php
5151<?php
5252
53- namespace App\Plugins\Plugin1 ;
53+ declare(strict_types=1) ;
5454
55- use App\Core\PluginInterface;
55+ namespace phpMyFAQ\Plugin\MyPlugin;
56+
57+ use phpMyFAQ\Plugin\PluginEvent;
58+ use phpMyFAQ\Plugin\PluginInterface;
59+ use phpMyFAQ\Plugin\PluginConfigurationInterface;
60+ use phpMyFAQ\Translation;
5661use Symfony\Component\EventDispatcher\EventDispatcherInterface;
5762
5863class MyPlugin implements PluginInterface
@@ -84,6 +89,21 @@ class MyPlugin implements PluginInterface
8489 return null;
8590 }
8691
92+ public function getStylesheets(): array
93+ {
94+ return [];
95+ }
96+
97+ public function getTranslationsPath(): ?string
98+ {
99+ return null;
100+ }
101+
102+ public function getScripts(): array
103+ {
104+ return [];
105+ }
106+
87107 public function registerEvents(EventDispatcherInterface $dispatcher): void
88108 {
89109 $dispatcher->addListener('hello.world', [$this, 'onContentLoaded']);
@@ -120,7 +140,7 @@ class MyPlugin implements PluginInterface
120140</div>
121141```
122142
123- ## 9.6 Plugin stylesheets
143+ ## 9.6 Stylesheets
124144
125145Plugins can provide pre-compiled CSS files that will be automatically injected into both frontend and admin pages.
126146
@@ -155,7 +175,7 @@ public function getStylesheets(): array
155175 └── admin-style.css
156176```
157177
158- ## 9.7 Plugin translations
178+ ## 9.7 Translations
159179
160180Plugins can provide translations in multiple languages that integrate seamlessly with phpMyFAQ's translation system.
161181
@@ -166,7 +186,7 @@ Plugins can provide translations in multiple languages that integrate seamlessly
166186``` php
167187public function getTranslationsPath(): ?string
168188{
169- return 'translations'; // Path relative to plugin directory
189+ return 'translations'; // Path relative to the plugin directory
170190}
171191```
172192
@@ -231,7 +251,7 @@ plugin.{PluginName}.{messageKey}
231251 └── language_es.php
232252```
233253
234- ## 9.8 Plugin JavaScript
254+ ## 9.8 JavaScript
235255
236256Plugins can provide pre-compiled JavaScript files that will be automatically injected into both frontend and admin pages.
237257
@@ -289,6 +309,7 @@ public function getScripts(): array
289309
290310** Security notes:**
291311- Always use strict mode (` 'use strict' ` )
312+ - Lint your code with ESLint, you can run ` npx eslint phpmyfaq/content/plugins/YourPlugin//assets/ ` from the phpMyFAQ root
292313- Wrap code in IIFE to avoid global namespace pollution
293314- Validate and sanitize user input
294315- Use DOM API safely
0 commit comments