Skip to content
RustPress

Documentation Build

Plugins

How RustPress plugins work: one JSON protocol, JavaScript, WebAssembly, PHP, Python and HTTP runtimes, permissions, scope, dependencies, plugin tables and Rust builds.

Updated

This page explains how RustPress plugins work, which languages you can write them in, how to install them, and how to keep them fast and safe. For every API in detail, see the Plugin API reference.

What plugins can do

Since 0.1.4, plugins can do what WordPress plugins do, in all four SDKs: filters, actions and shortcodes; REST routes and public addresses; custom content types and taxonomies; custom fields and meta boxes; roles and capabilities; rewrite rules; admin menus and settings pages; editor blocks; scripts and styles; WP_Query and $wpdb; their own tables; background jobs; private files; calls to other websites; dashboard widgets; and AI tools for the site’s agents. Plugins can also depend on each other and extend each other through hooks.

One protocol for every language

A plugin is a folder in rp-content/plugins/. Every runtime speaks the same JSON protocol, documented in sdk/PROTOCOL.md. The core sends a message with kind, hook, args and context, and the plugin answers with result, output and error.

core   → plugin   {"kind", "hook", "args", "context"}
plugin → core     {"result", "output", "error"}

Runtimes

RuntimeHow it runsGood for
jsJavaScript inside the core (QuickJS compiled to WebAssembly, the same sandbox as wasm). Nothing to install.Most plugins: filters, shortcodes, blocks, REST routes, admin pages.
wasmWebAssembly module inside the core (wasmtime). Sandboxed, fuel-limited, a fresh instance per call.Rust, C, Zig, AssemblyScript, TinyGo.
stdioA program started per request, JSON on stdin and stdout. PHP and Python plugins using the SDK are kept running.PHP, Python, Node, Ruby, compiled binaries.
httpA long-running service: an external URL, or a serve command the core starts.Busy plugins, any web stack.

PHP plugins, the classic way

A PHP file with a Plugin Name: header needs no manifest. The PHP SDK is prepended to your code, so the familiar WordPress functions are there, including:

  • add_filter, add_action, add_shortcode, do_action, apply_filters
  • register_rest_route, register_post_type, register_taxonomy, register_block_type, register_post_meta
  • add_menu_page, add_options_page, add_meta_box, wp_enqueue_script, wp_enqueue_style
  • get_option, update_option, get_posts, WP_Query, $wpdb and dbDelta
  • get_post_meta, update_post_meta, user and term meta, wp_remote_get and wp_remote_post
  • Nonces, esc_html and the other escaping functions, transients and wp_cache_*
  • Action Scheduler’s as_enqueue_async_action() and as_schedule_single_action()
  • WP_REST_Request, WP_REST_Response, WP_Error
<?php
/**
 * Plugin Name: Thanks
 */
add_filter( 'the_content', function ( $content ) {
    return $content . '<p>Thanks for reading!</p>';
} );

Large plugins built deep on WordPress internals, such as WooCommerce, Yoast or Elementor, install but won’t activate; the installer says so. Upload the zip in the AI chat and an agent can rebuild one natively.

Sandboxed JavaScript plugins

JavaScript plugins need nothing on the server, not even Node. Add a plugin.json:

{ "name": "Twice", "runtime": "js", "entry": "plugin.js" }

And a plugin.js:

const wp = require('rustpress')();
wp.addShortcode('twice', (atts) => String(Number(atts.n || 0) * 2));
wp.addFilter('the_content', async (html) => html + '<p>' + wp.esc(await wp.getOption('blogname')) + '</p>');
wp.run();

The same file runs under Node too. In the sandbox only the SDK can be required: there is no fetch, timers, files or process (use wp.http() with the network permission), and each call starts fresh, so keep data in options or tables.

Other languages

Any program that reads and writes JSON can be a plugin. Point plugin.json at it and pick the runtime:

{ "name": "My Plugin", "runtime": "stdio", "entry": "main.py" }

Installing plugins

Go to Plugins › Add New Plugin and upload a .zip or a single .php file. RustPress unpacks it safely and can activate it right away. You can also install over the REST API (POST /rp-json/wp/v2/plugins, multipart field pluginzip, status=active) or with rp plugin install FILE.zip. Set disallow_file_mods = true in rp-config.toml to turn installing and removing off.

Dependencies

A plugin that needs another declares it, with an optional minimum version:

{ "requires": ["shop-core", "payments (>=1.2)"], "requires_rustpress": "0.1.4" }

In PHP, use the Requires Plugins: and Requires RustPress: headers. RustPress won’t activate a plugin until what it needs is active, and won’t let a required plugin be turned off from under it. Details in the Plugin API reference.

Permissions

A plugin declares what it needs with a Permissions: content:read, options header in PHP, or a "permissions" list in plugin.json:

PermissionAllows
content:readReading drafts, private content and non-public types
content:writeCreating and changing content
optionsSettings other than the plugin’s own
usersUsers, roles and capabilities
siteSite-wide changes, such as granting manage_options
networkCalling other websites; "network": ["api.stripe.com"] limits it to those hosts

With permissions declared, a plugin gets only those, plus its own options, public settings and its own REST routes. Plugins that declare nothing keep full access and are labelled so. The full rules are in Safety and limits.

Scope: a plugin only runs where it is needed

A plugin is only called for the hooks, shortcodes and routes it registered, and filters and actions only run where they are needed. Declare the scope in plugin.json (areas, paths like /shop/*, content types, page kinds) or with Load On: headers in PHP. The site owner can override it under Plugins › Where it runs.

PHP plugins are kept running in the background on PHP’s built-in server with OPcache, so a call costs a couple of milliseconds instead of starting PHP each time. Python plugins that use the SDK’s run() are kept running the same way. RP_PHP_PER_CALL=1 goes back to one process per call, and php_binary or RP_PHP picks the PHP program.

SDKs and host calls

The sdk/ folder beside rp-config.toml has SDKs for PHP, JavaScript (Node and the sandbox), Python and Rust (WebAssembly). Plugins talk back to the core with host calls, over HTTP with a token (POST /rp-json/rp/v1/host) or through the wp.host_call import in WebAssembly: options, REST requests, filters and actions, mail, scheduled events, the object cache, plugin tables, background jobs, private files, HTTP calls, meta, nonces and logging. Log with wp.log(msg, 'error'), rp_log() or log(); entries land in Tools › Logs.

Plugin data

Plugins create their own tables without SQL (wp.db.createTable('orders', {…}), rp_db_create_table(…)), keep private files that are never served directly (rp.files.put(), rp_file_put()), and queue slow work as background jobs. RustPress records what belongs to which plugin. When you remove a plugin, it asks whether to keep or delete its tables, settings, metadata named after it, scheduled tasks and private files.

Public addresses

Plugins can answer at addresses on the site root: rp_register_page('/sitemap.xml', $callback) in PHP, wp.registerPage(path, cb) in JavaScript, with {name} segments and a trailing *. A plugin’s address replaces the core’s /sitemap.xml or /robots.txt. Core paths (/rp-admin, /rp-json, /rp-content, /rp-login and others) and addresses another plugin already holds are refused. Plugins can also add wp_ajax_{action} and wp_ajax_nopriv_{action} handlers.

Bundled examples

These come installed and switched off, so you can read and try them:

  • Hello PHP: reading time, a [hello] shortcode, a footer note, an admin notice, a settings page and a REST route.
  • WebAssembly Hello: a hand-written WAT module.
  • Word Stats: Node.js over HTTP, calling the REST API back.
  • Simple Books: a custom post type and taxonomy in PHP.

examples/plugins/reading-time-wasm in the repository is a Rust plugin.

Building Rust plugins

rp plugin build DIR compiles a Rust plugin to plugin.wasm. AI agents do the same through check_project. It needs Rust, the wasm32-unknown-unknown target and bubblewrap (Linux) on the server.

  • The build runs in a bubblewrap sandbox that sees only the toolchain, the SDK and the build folder.
  • RustPress writes Cargo.toml itself. Dependencies are limited to the SDK, serde, serde_json, once_cell and regex.
  • build.rs, include_str!, include_bytes!, env! and #[path] are refused, checked with Rust’s own tokenizer.
  • Without the sandbox, nothing is built. You can also build on another computer and upload the zip with plugin.wasm included.

All plugin commands are in the Command reference. To let plugins give tools to AI agents, see MCP and AI tools.