Extension Development

PureWiki features a robust Extension System that allows developers to add custom features, Editor.js plugins, settings pages, and API routes without modifying the core codebase.

 A fully functional reference implementation is available in the PureWiki example-extension Repository:
https://github.com/PureWiki/example-extension

You can clone this repository and use it to jumpstart your own extension development.

Directory Structure

Each extension resides in its own repository under /extensions/<extension-id>/. The folder name must match the ID defined in the metadata.

extensions/my-extension/
├── meta.json          # Required: Metadata (ID, version, author)
├── extension.php      # Required: Registers all hooks
├── settings.php       # Optional: Custom settings tab UI
├── api.php            # Optional: Custom API endpoints
├── assets/            # Optional: CSS/JS files
├── lang/              # Optional: Translation files (en.json, de.json)
└── editorPlugins/     # Optional: Editor.js blocks

The meta.json File

This file is mandatory and tells PureWiki how to discover and load your extension.

{
  "id": "my-extension",
  "name": "My Extension",
  "version": "1.0.0",
  "author": "Your Name",
  "description": "A brief description.",
  "url": "Link to your extensions Website or Github",
  "editor_plugins": ["my-block.js"]
}

Registering Hooks

All logic is attached to the core system via hooks inside extension.php. You can register filters (to modify data) or actions (to execute logic or output HTML). 

ExtensionLoader::addHook('frontend.head_css', function($context) {
    echo '<link rel="stylesheet" href="' . ExtensionLoader::getUrl('my-extension') . '/assets/style.css">';
});

Available Hooks

Hook Name Description
parser.block Manipulate block data array before it gets rendered.
renderer.html Post-process the final generated HTML of the entire page.
editor.tools / editor.tunes Register new Editor.js tools/settings.
page_settings.fields Add custom HTML fields to the Page Settings modal.
page_settings.save Hook into the save process to manipulate page data.
settings.tabs Register a custom tab in the global Settings dashboard.
api.routes Add custom API routes mapping to your PHP scripts.
api.admin_actions / api.public_actions Whitelist API routes for access control.
admin.head_css / admin.head_js Inject assets into the Admin Dashboard.
frontend.head_css / frontend.head_js / frontend.footer_js Inject assets into the Frontend.

Auto-Saving Page Settings

To add fields to the Page Settings modal that save automatically, simply append the pw-ext-input CSS class to your input element in the page_settings.fields hook. PureWiki will automatically load and save its value into the page's JSON data.

Extension Settings (Persistence)

Extensions should not use the global config.json. Instead, you can store your own configuration using getExtensionSettings($id) and saveExtensionSettings($id, $data). The data is saved safely in config/extensions/<id>.json.

Internationalization (i18n)

You can provide translations by placing .json files in the lang/ folder (e.g., en.json, de.json). PureWiki automatically loads them. To avoid conflicts, all extension translations are namespaced. Access them using __('ext.my-extension.your_key').