Skip to content

Commit

Permalink
Edit admonitions + steps
Browse files Browse the repository at this point in the history
  • Loading branch information
billz committed Nov 10, 2024
1 parent b77d040 commit 5d31bd5
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions docs/custom-plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Several common plugin functions are demonstrated in `SamplePlugin`, as well as a
The `SamplePlugin` requires an installation of RaspAP, either via the [Quick install](quick.md) method or with a [Docker container](docker.md). The default application path `/var/www/html` is used here. If you've chosen a different install location, substitute this in the steps below.

1. Begin by creating a fork of the [SamplePlugin repository](https://github.com/RaspAP/SamplePlugin).
2. SSH into the device hosting RaspAP, change to the install location and create a `/plugins` directory.
2. Change to your RaspAP install location and create a `/plugins` directory.
```
cd /var/www/html
sudo mkdir plugins
Expand All @@ -25,20 +25,20 @@ The `SamplePlugin` requires an installation of RaspAP, either via the [Quick ins
cd plugins
sudo git clone https://github.com/[your-username]/SamplePlugin
```
4. The `PluginManager` will autoload the plugin. A **:fontawesome-solid-plug: Sample Plugin** item will appear in the sidebar.
5. Proceed with customizing the plugin by using the tips in the next sections.
4. The `PluginManager` will detect and autoload the plugin. A **:fontawesome-solid-plug: Sample Plugin** item will appear in the sidebar.
5. Proceed with customizing your plugin by using the tips in the next sections.

## Scope of functionality
The `SamplePlugin` implements the server-side methods needed to support basic plugin functionality. It initalizes a `Sidebar` object and adds a custom navigation item. User input is processed with `handlePageAction()` and several common operations are performed, including:

1. Saving plugin settings
2. Starting a sample service
3. Stopping a sample service
1. Saving plugin settings.
2. Starting a sample service.
3. Stopping a sample service.

Template data is then collected in `$__template_data` and rendered by the `main.php` template file located in `/templates`. Property get/set methods are demonstrated with `apiKey` and `serviceStatus` values. A method is then used in `persistData()` to save the `SamplePlugin` object data.

!!! tip "Tip"
Importantly, `SamplePlugin` does _not_ use the PHP `$_SESSION` object as this super global can lead to conflicts with other user plugins.
!!! warning "Caution"
Importantly, `SamplePlugin` does _not_ use the PHP `$_SESSION` object. Known as a "superglobal", or automatic global variable, this is available in all scopes throughout a script. Using the `$_SESSION` object in a plugin context can lead to conflicts with other plugin instances.

On the front-end, Bootstrap's [form validation](https://getbootstrap.com/docs/5.3/forms/validation/) is used to validate user input. A custom JavaScript function is used to generate a random `apiKey` value. The `sample.service` LED indicator is functional, as are the service stop/start form buttons.

Expand Down Expand Up @@ -110,14 +110,14 @@ The `PluginManager` is a managerial class responsible for locating, instantiatin

![multiple-plugins](https://github.com/user-attachments/assets/2d156efe-8cfc-49e7-b682-219d2db4eeee){: style="width:640px"}

As previously noted, developers should avoid using PHP's `$_SESSION` object in their plugins to prevent conflicts with other plugin instances. An alternative method for session data storage is provided in the `SamplePlug` `persistData()` function.
As previously noted, developers should avoid using PHP's `$_SESSION` object in their plugins to prevent conflicts with other plugin instances. An alternative method for session data storage is provided in the `SamplePlugin` `persistData()` function.

!!! note "Note"
The `persistData()` function writes serialized data to the volatile `/tmp` directory which is cleared on each system boot. For this reason, it should not be used as a permanent method of data persistence. However, this functionality roughly approximates PHP's `$_SESSION` object; the difference being that each plugin's data is isolated from other plugin instances.


## Publishing your plugin
The `SamplePlugin` contains an "About" tab where you may provide author information, a description and link to your project. If you've authored a plugin you feel would be useful to the RaspAP community, you're encouraged to share it in the `SamplePlugin` repo's [Discussions](https://github.com/RaspAP/SamplePlugin/discussions).
The `SamplePlugin` contains an "About" tab where you may provide author information, a description and link to your project. If you've authored a plugin you feel would be useful to the RaspAP community, you're encouraged to share it in the `SamplePlugin` repository's [discussions](https://github.com/RaspAP/SamplePlugin/discussions).

## Discussions
Questions or comments about creating user plugins? Join the [discussion here](https://github.com/RaspAP/raspap-webgui/discussions/).

0 comments on commit 5d31bd5

Please sign in to comment.