@ -5,20 +5,20 @@ So you want to write a plugin for NodeBB, that's fantastic! There are a couple o
Like WordPress, NodeBB's plugins are built on top of a hook system in NodeBB. This system exposes parts of NodeBB to plugin creators in a controlled way, and allows them to alter content while it passes through, or execute certain behaviours when triggered.
The complete list of hooks built into NodeBB can be found at [[List of Hooks]]
See the full :doc:`list of hooks <hooks>` for more information.
Filters and Actions
------------------
There are two types of hooks: **filters** and **actions**.
*Filters* act on content, and can be useful if you want to alter certain pieces of content as it passes through NodeBB. For example, a filter may be used to alter posts so that any occurrences of "apple" gets changed to "orange". Likewise, filters may be used to beautify content (i.e. code filters), or remove offensive words (profanity filters).
**Filters** act on content, and can be useful if you want to alter certain pieces of content as it passes through NodeBB. For example, a filter may be used to alter posts so that any occurrences of "apple" gets changed to "orange". Likewise, filters may be used to beautify content (i.e. code filters), or remove offensive words (profanity filters).
*Actions* are executed at certain points of NodeBB, and are useful if you'd like to *do* something after a certain trigger. For example, an action hook can be used to notify an admin if a certain user has posted. Other uses include analytics recording, or automatic welcome posts on new user registration.
**Actions** are executed at certain points of NodeBB, and are useful if you'd like to *do* something after a certain trigger. For example, an action hook can be used to notify an admin if a certain user has posted. Other uses include analytics recording, or automatic welcome posts on new user registration.
When you are writing your plugin, make sure a hook exists where you'd like something to happen. If a hook isn't present, [file an issue](https://github.com/designcreateplay/NodeBB/issues) and we'll include it in the next version of NodeBB.
When you are writing your plugin, make sure a hook exists where you'd like something to happen. If a hook isn't present, `file an issue <https://github.com/designcreateplay/NodeBB/issues>`_ and we'll include it in the next version of NodeBB.
plugin.json
Configuration
------------------
Each plugin package contains a configuration file called ``plugin.json``. Here is a sample:
@ -36,7 +36,7 @@ Each plugin package contains a configuration file called ``plugin.json``. Here i
@ -49,13 +49,10 @@ The ``staticDir`` property is a path (relative to your plugin's root) to a direc
The ``less`` property contains an array of paths (relative to your plugin's directory), that will be precompiled into the CSS served by NodeBB.
The ``css`` property contains an array of paths (relative to your plugin's ``staticDir``) that will be served to the end user as a stylesheet. In the example above, the ``style.css`` would end up accessible at: ``/plugins/my-plugin/public/style.css``, and would be located in the ``public`` directory in your plugin's root. **Note**: The ``css`` property is not recommended, as it may be deprecated in the future. Use ``less`` instead.
The ``hooks`` property is an array containing objects that tell NodeBB which hooks are used by your plugin, and what method in your library to invoke when that hook is called. Each object contains the following properties (those with a * are required):
* ``hook``*, the name of the NodeBB hook
* ``method``*, the method called in your plugin
* ``callbacked``, whether or not the hook expects a callback (true), or a return (false). Only used for filters. (Default: false)
* ``hook``, the name of the NodeBB hook
* ``method``, the method called in your plugin
* ``priority``, the relative priority of the method when it is eventually called (default: 10)
Writing the plugin library
@ -65,8 +62,8 @@ The core of your plugin is your library file, which gets automatically included
Each method you write into your library takes a certain number of arguments, depending on how it is called:
* Filters send a single argument through to your method, although asynchronous methods can also accept a callback (if specified in ``plugin.json``).
* Actions send a number of arguments (the exact number depends how the hook is implemented). These arguments are listed in [[List of Hooks]].
* Filters send a single argument through to your method, while asynchronous methods can also accept a callback.
* Actions send a number of arguments (the exact number depends how the hook is implemented). These arguments are listed in the :doc:`list of hooks <hooks>`.
Example library method
------------------
@ -102,7 +99,7 @@ Occasionally, you may need to use NodeBB's libraries. For example, to verify tha
Installing the plugin
------------------
In almost all cases, your plugin should be published in [npm](https://npmjs.org/), and your package's name should be prefixed "nodebb-plugin-". This will allow users to install plugins directly into their instances by running ``npm install``.
In almost all cases, your plugin should be published in `npm <https://npmjs.org/>`_, and your package's name should be prefixed "nodebb-plugin-". This will allow users to install plugins directly into their instances by running ``npm install``.
When installed via npm, your plugin **must** be prefixed with "nodebb-plugin-", or else it will not be found by NodeBB.