Full-stack blocks
Database, server functions, cron, and CLI in one folder.
db.php
Define schema, get CRUD endpoints
<?php
return [
'storage' => 'sqlite',
'userScoped' => true,
'capability' => [
'create' => true,
'read' => true,
'update' => true,
'delete' => true,
],
'fields' => [
'text' => ['type' => 'string', 'required' => true],
'done' => ['type' => 'boolean', 'default' => false],
],
];rpc.php
Custom server functions
<?php
use Blockstudio\Db;
return [
'toggle' => function (array $params): array {
$db = Db::get('my-theme/todo');
$id = (int) ($params['id'] ?? 0);
$todo = $db->get_record($id);
if ($todo) {
$db->update($id, ['done' => !$todo['done']]);
}
return ['success' => (bool) $todo];
},
'clear_done' => function (): array {
$db = Db::get('my-theme/todo');
foreach ($db->list(['done' => true], 500) as $todo) {
$db->delete((int) $todo['id']);
}
return ['cleared' => true];
},
];Every capability is a file
Each file adds one capability. No configuration and no registration code.
Application block
blockstudio/
└── my-app/
├── block.json Block definition
├── index.php Template + Interactivity API
├── style.css Scoped styles
├── script-inline.js Client logic
├── db.php Data model + CRUD
├── rpc.php Server functions
├── cron.php Scheduled tasks
└── db/default.sqlite
Database
Define schemas, get CRUD endpoints.
6 storage modes
table, sqlite, jsonc, storh, meta, post_type. Choose by portability and query needs.
Storh files
One file per record under uploads, with indexes built from the schema and safer concurrent writes. wp bs db migrate –to=storh moves JSONC records over and keeps their IDs.
Tables and post types
table storage manages a MySQL table with dbDelta and adds columns for new fields. post_type storage makes each record a post, so WP_Query, REST API plugins, and GraphQL tools can read it.
Multiple schemas
Return named schemas from one db.php. Each gets its own storage, endpoints, and access control.
User-scoped data
Set userScoped to isolate records automatically, with no manual filtering.
Validation and hooks
Types, required values, enums, formats, lengths, callbacks, and lifecycle hooks.
RPC
Server functions callable from the frontend.
Client data layer
Read, cache, and write records from the browser.
bs.db() client
Create, list, get, update, and delete records from JavaScript. list takes field filters, limit, and offset.
bs.query()
Cached fetches by key. Calls in flight share one promise, and staleTime skips the request while the data is fresh.
bs.mutate()
Optimistic create, update, and delete on a reactive state array, rolled back to a snapshot when the request fails.
bs.cache
The in-memory cache behind bs.query() and bs.mutate(). Read, set, invalidate, or clear entries directly.
Realtime polling
Set realtime in db.php and the client compares a data hash on an interval, then updates the Interactivity API store. Polling pauses in hidden tabs.
Cached pages
bs.fn() and bs.db() fetch fresh credentials from an uncached endpoint on the first call, so public calls keep working on pages served from long-lived caches.
Forms and app screens
Forms rendered from the schema, and bundled UI to build on.
Schema forms
Give a field a component key and bs_db_form() renders the form through those blocks, passing each one its field definition.
Bundled form
With ui.enabled, bsui/form block=”…” sends its fields to that block’s create endpoint, shows each validation error under its field, and dispatches formsuccess or formerror.
Example apps
The ui setting also registers the app/* examples, such as app/kitchen-sink and app/chat, built from the same bsui components.
Infrastructure
Cron, CLI, setup code, and portability.
Scheduled tasks
cron.php jobs register with WP-Cron. Composer installs remove them with wp bs teardown.
Database CLI
wp bs db lists records with field filters, gets, creates, updates, and deletes them, and prints tables, JSON, or CSV.
Test from the terminal
wp bs rpc call runs a function with –key=value parameters, and wp bs cron run fires a job now, whatever its schedule.
Init files
init.php and other init*.php files in a block folder run once on init, for setup such as registering a post type.
PHP-native definitions
rpc.php and cron.php can return a class with #[Rpc] and #[Cron] methods and the Access, Method, and Schedule enums. db.php can use Schema::make() and Field builders.
Portability
SQLite and JSONC travel with the code: copy one folder to deploy the app.
The official extension kit
Premium site templates, AI system instructions, and a private Discord community. One-time purchase, lifetime updates.
- 500+ site templates
- AI system instructions
- Lifetime updates
- Private Discord community