mirror-and-mountain / meros-framework
A developer-friendly package for creating advanced Wordpress themes.
Package info
github.com/mirror-and-mountain/meros-framework
pkg:composer/mirror-and-mountain/meros-framework
Requires
- ext-dom: *
- bacon/bacon-qr-code: ^3.0
- mirror-and-mountain/meros-foundations: ^1.2.0
- opis/json-schema: ^2.6
- pragmarx/google2fa: ^9.0
Requires (Dev)
- illuminate/testing: ^13.0
- phpunit/phpunit: ^9.6
- yoast/phpunit-polyfills: ^3.1
Suggests
None
Provides
None
Conflicts
None
Replaces
None
- 1.x-dev
- v1.2.1
- v1.2.0
- v1.1.1
- v1.1.0
- v1.0.0
- 0.x-dev
- v0.4.16
- v0.4.15
- v0.4.14
- v0.4.12
- v0.4.10
- v0.4.8
- v0.4.6
- v0.4.5
- v0.4.4
- v0.4.3
- v0.4.2
- v0.4.1
- v0.4.0
- v0.2.18
- v0.2.17
- v0.2.16
- v0.2.15
- v0.2.14
- v0.2.12
- v0.2.11
- v0.2.10
- v0.2.9
- v0.2.8
- v0.2.7
- v0.2.6
- v0.2.5
- v0.2.4
- v0.2.3
- v0.2.2
- v0.2.1
- v0.2.0
- v0.1.12
- v0.1.11
- v0.1.10
- v0.1.9
- v0.1.8
- v0.1.7
- v0.1.6
- v0.1.5
- v0.1.4
- v0.1.3
- v0.1.2
- v0.1.1
- v0.1.0
- v0.0.12
- v0.0.11
- v0.0.10
- v0.0.9
- v0.0.8
- v0.0.7
- v0.0.6
- v0.0.5
- v0.0.4
- v0.0.3
This package is auto-updated.
Last update: 2026-11-30 22:26:13 UTC
README
Theme/package providers, feature contracts, registers and WordPress-facing services for Meros themes, powered by Meros Foundations.
Documentation
Detailed documentation is maintained in meros-docs.
Testing before a pull request or release
Run composer test and composer test:integration from a source checkout with
development dependencies. From a consuming theme, also run:
wp meros:test settings --all --provider=framework wp meros:test postTypes --all --provider=framework
Reusable checks also cover settings containers/UI, post meta items/containers,
taxonomies, assets/groups, static/dynamic blocks, admin pages, roles/capabilities,
tables, integrations, routes, Livewire components and views. Every category accepts a name or --all, plus provider
scoping, for example:
wp meros:test postMeta --all --provider=framework wp meros:test assets --all --provider=theme wp meros:test blocks --all --provider=meros_blocks wp meros:test routes --all --provider=framework wp meros:test livewire meros::form-builder --provider=framework wp meros:test views meros::forms.builder --provider=framework
Disabled block/asset-group defaults are preserved and reported as skipped, not passed; an all-skipped selection is not a passing release gate. Checks boot actual project code in a separate WordPress test environment and require a dedicated test database. They complement, rather than replace, MFA, forms and API regression tests. See the testing workflow for setup, provider scopes and CI/release gates.
Resource ownership is tracked during provider registration, not guessed from names. Route checks use a JSON request context and never dispatch endpoints. Livewire checks resolve class and single/multi-file components without constructing, mounting or rendering them; view checks resolve and compile/lint templates without application data. Keep authored tests for runtime behavior.
Theme API keys
New API keys appear once on the theme settings page after saving. Copy them
somewhere safe; the notice is limited to the creating login session and expires
after one hour. If a key is lost, remove and recreate its configuration to
generate a replacement. Keys are encrypted with the application's APP_KEY
before storage, and existing plaintext keys are encrypted on the next admin
request. Keep APP_KEY stable and backed up to retain access to encrypted keys.
Meros API
Send the key as Authorization: Bearer <key>. A key needs the
read_<post-type> scope to read that type:
Post types are exposed by default. Set $this->showInMerosRest(false) in a
post type's configuration to exclude it from API requests and the API-key scope
picker. Existing key scopes do not override this exclusion.
Browser GET requests that prefer HTML are left to WordPress to render the theme's
404 page. API clients should send Accept: application/json; curl's default
Accept: */* also works. API responses and browser 404s send
X-Robots-Tag: noindex, nofollow, noarchive to discourage search indexing.
These directives are not a security control; bearer authentication remains required.
GET /meros-api/posts/<post-type>returns a JSON object withdataandpagination(page,per_page,total,total_pages).pagedefaults to 1 andper_pageto 25;per_pagemust be between 1 and 100.GET /meros-api/posts/<id>returns one inspected post as a JSON object. Numeric path segments are interpreted as IDs.
Requests handled by the API middleware are logged to the meros-api channel
(storage/logs/meros-api.log by default), including successes, authentication
failures, and errors. Entries include the HTTP method, path, response status,
and duration, but never bearer keys, headers, query strings, or request/response bodies.
The theme settings API Logs subpage lets administrators view and reset this log.
Only published, non-password-protected posts are returned. The API removes
post_password and omits undeclared raw post metadata. Declared post-meta
definitions are visible by default; explicitly hide sensitive definitions:
$container->add('string', function (\MM\Meros\Contracts\Features\Data\PostMeta $meta) { $meta->name('private_note'); $meta->showInMerosRest(false); });
Audit existing definitions before issuing read scopes, including nested values.
$postType->inspect($id, refresh: true, excludeSensitive: true) applies the
same metadata filtering; the default inspect() behavior is unchanged.
Overrides of inspect() must accept and honor the new optional argument.
Post types using UsesForms also expose stored form_structure, form_actions,
and form_settings. Inspection normalizes single- and double-underscore
meros storage prefixes, including host/template settings containers, and
removes the storage aliases. Declared sensitive action/settings fields remain
excluded from API responses.
Creating and updating posts
Keys require write_<post-type> independently of read scopes:
POST /meros-api/posts/<post-type>creates a post, defaulting todraft, and returns its inspected JSON with status201.POST /meros-api/posts/<id>updates a draft, pending, published, or private post and returns its inspected JSON with status200.
Send Content-Type: application/json and a non-empty JSON object. Writable
WordPress properties are post_title, post_content, post_excerpt, post_name,
post_password, post_status, post_parent, and menu_order. ID, guid,
post_type, and other server-managed properties cannot be supplied. Read
restrictions remain unchanged; a successful write does not grant read access.
Exposed metadata uses the same normalized names as inspection. Omitted values
remain unchanged, while a supplied metadata value (including arrays or objects)
replaces that value rather than recursively merging it. A supplied form_settings
object replaces the exposed settings; omitted settings revert to their defaults.
Hidden container values
are preserved. Form structure is reconstructed through the existing form builder
and saved in its storage serialization format.
For automatic row layout, provide fields instead of rows in
form_structure, or inside a row's childGroup:
{
"form_structure": {
"fields": [
{ "type": "text", "name": "first_name" },
{ "type": "text", "name": "last_name" },
{ "type": "textarea", "name": "message" }
]
}
}
Fields are packed in order using each type's row positions, as in the PHP form
API. Each form or group must specify either fields or rows, not both.
Explicit rows can contain groups whose fields use the shortcut. Responses
always contain the resulting rows.
On creation, a form host can supply form_template to select an available
template. Use the declared template key for a custom post type, or the template
post's post_name (slug) for a generic form. The latter must be published and
not owned by another post type. A custom post type with one declared template
applies it automatically. Selection is creation-only; form-template posts
cannot select a template. Omit the selector to start from scratch when multiple
templates are available.
For a templated form, supplied form_structure components merge by field and group
name into the template or existing structure. Omitted components remain in place;
new components are added only when permitted, and locked component properties
cannot be changed. Repeater columns merge by name as well. Structure merges do
not move or remove existing components, even when the template permits those
operations in the builder. Groups and fields must have unique non-empty names.
Template title, description, action and individual form-setting locks are also
enforced. Template-selection fields inside form_settings are not writable.
For forms without a template, supplying form_structure still replaces it.
Action configurations use the normalized form_actions array,
not the editor's internal __form_data JSON strings. Action execution accepts both
the normalized configuration and existing editor-stored payloads, including
actions inherited from a template.
New editor rows may have an empty configuration until their action is configured;
required action inputs are validated when the action runs.
Form submissions store a response before running actions. The optional Delete
Response (delete_form_response) action removes that saved response.
taxonomies maps associated taxonomy handles to arrays of existing integer
term IDs. Each supplied list replaces that taxonomy's assignments; [] clears
it. Omitted taxonomies are unchanged. Invalid term IDs never create new terms.
For example:
{
"post_title": "Example post",
"post_status": "draft",
"taxonomies": {"category": [12, 34]}
}
Schema validation errors return 422 with an errors object. Malformed JSON
returns 400, a non-JSON content type returns 415, and storage/schema failures
return 500 and are logged without payloads. Writes use WordPress's save APIs
and a transaction on the WordPress database connection. Database rollback requires
transactional tables; external side effects performed by WordPress hooks cannot
be rolled back.
Generated JSON Schemas
PostType::getSchema() now describes the writable API payload using JSON Schema
2020-12, explicit metadata types, recursive repeater definitions, and reusable
$defs for forms, rows, field groups, and every registered field type. Component
schemas follow storage serialization and declared PHP types, including nullable
and union types, rather than guessing types from example/default values.
Custom components can override getStorageSchema() to add more specific constraints.
Validation uses opis/json-schema.
Schemas are cached in storage/framework/cache/meros-api/schemas/<handle>.json. A missing
schema is generated automatically on the first write; corrupt or unreadable
schemas fail explicitly rather than bypassing validation. Current API visibility
and template locks are checked separately so cached schemas cannot restore access
to newly hidden metadata or post types.
Regenerate schemas regularly during development after changing post types, metadata definitions, or component/field definitions:
wp meros:make schema <posttypehandle> wp meros:make schema --all
After updating the meros-framework package, theme developers must also run
wp meros:make schema --all. Include regeneration in the deployment workflow
after WordPress has loaded the updated theme/packages. --all skips post types
that opt out of the API.
Generated schemas can also be associated with request JSON files in an editor.
A versioned first-party schema repository can distribute reusable component
definitions, while each theme's generated schemas describe its own post types
and custom metadata. Editor-only $schema annotations must be removed before
posting a payload; the server always selects its own cached schema and never
fetches a client-supplied schema URL.
Forms on custom routes
Views rendered by non-WordPress routes can include the framework's built form
assets directly with @merosFormStyles() in the document head and
@merosFormScripts() before @livewireScripts. The script directive must run
before Alpine starts so the form components are registered. Both directives
include the dependencies from resources/assets/wordpress/build/mforms before
the main bundle, together with the standalone build/modal script and styles,
using the framework's public asset URLs without WordPress
enqueue hooks. External script dependencies declared in index.asset.php are
printed through WordPress's script registry, including their inline initialization
(for example, Quill's window.lodash dependency). Alpine is supplied by Livewire
(or by the consuming layout). Livewire @script blocks listening for form submit
events must contain a <script> element.
Asset URLs include a content-based version so rebuilt bundles bypass browser
caches, including when the Blade view is already compiled.
Forms with onSubmit('eventName') dispatch mforms::eventName with
{ form, formId, formName, formData }. form is the Alpine form instance.
Callbacks now own completion: dispatching the event does not automatically
display feedback or reset the inputs. Existing callbacks that want success
feedback must explicitly call form.showSuccess(message) (omit the message to
use the configured success message); form.showError(message) displays an error
without resetting inputs. Redirecting callbacks can leave feedback untouched.
Validation and forms using the default AJAX submission retain their existing
behavior. submitForm(true) still returns the validation/dispatch outcome for
repeater editors, not the outcome of asynchronous callback logic.
Livewire actions that return callback results without changing server-rendered
content should use #[\Livewire\Attributes\Renderless] so their response does not
replace the form before client-side feedback is applied. Attach component-local
listeners to $wire.$el rather than document to avoid stale navigation listeners.
For asynchronous callbacks, set form.isSubmitting = true before the request
and clear it in the promise's finally handler. This activates the existing
submit-button spinner, busy overlay, and duplicate-submission protection.
Repeater edit forms on custom routes
The existing modal, row-save behavior, validation and per-row HTML cache are
shared by WordPress and custom views. WordPress AJAX remains the default.
The standalone modal bundle exposes window.MerosModal; MFormsDeps and the
form asset directives load it before any consuming scripts.
For a custom transport, configure $form->repeaterEditFormLoader('myLoader').
Listen for mforms::myLoader on the form's parent and call
event.detail.respondWith(htmlOrPromise) synchronously. The event also contains
formId, name, originalName, rowData and currentValue. The promise must
resolve to the edit-form HTML, not a JSON response envelope; missing handlers,
failed requests and invalid responses display a modal error.
For reusable Livewire support:
- Use
MM\Meros\App\Livewire\Concerns\InteractsWithFormson the component. - Implement
protected function makeMerosForm(string $formId): Form, selecting and rebuilding the component's authorized PHP form definition on every call. - Configure
$form->repeaterEditFormLoader('livewireRepeaterEditForm'). - Include
@include('meros::forms.livewire-repeater-loader')once in the component view.
The trait supplies a renderless renderRepeaterEditForm action and checks the
requested form ID. Other HTTP transports can call
$form->renderRepeaterEditForm($name, $originalName, $rowData, $currentValue) from
their own CSRF-protected/authorized endpoint. Only repeaters in that form can be
resolved. Edit-form callbacks must return their configured Form instance.
PHP closures and schemas stay on the server rather than being serialized into
the browser or session.
Taxonomies
Extend MM\Meros\Contracts\Features\Content\Taxonomy and configure it like a
post type:
class Genre extends \MM\Meros\Contracts\Features\Content\Taxonomy { protected function configure(): void { $this->handle('genre'); $this->label('Genre', 'Genres'); $this->public()->hierarchical()->showInRest()->showAdminColumn(); } }
In a theme or package provider, $this->taxonomies()->register(Genre::class)
registers the feature class, and $this->taxonomies()->makeFrom(Genre::class)
instantiates it. Use $this->taxonomies()->make(fn ($taxonomy) => ...) to create
a taxonomy at runtime. The MM\Meros\Facades\Content\Taxonomies facade exposes
the same register; check it out with a provider before creating features.
Standalone taxonomies can associate post types using postType('book') or
postTypes(['book', 'film']).
Inside a PostType feature's configure() method:
$this->taxonomy(Genre::class); $this->taxonomy(function (\MM\Meros\Contracts\Features\Content\Taxonomy $taxonomy) { $taxonomy->handle('reading-level')->label('Reading Level'); $taxonomy->public()->showInRest(); });
taxonomy() returns the taxonomy feature and automatically associates the
current post type, including when its handle is inferred from its class name.
Class-based taxonomies are reused across post types. Associations are additive,
including for already-registered WordPress taxonomies. Use core() with an
existing handle such as category to associate without registering it anew.
Taxonomies register on WordPress init after post types. The existing
PostType::taxonomies(array $handles) API remains available for raw handles.
Use args([...]) for additional WordPress taxonomy registration options.
Taxonomy models
App\Models\Taxonomy represents a term_taxonomy record, not a taxonomy feature
definition. Its term() relationship exposes the associated App\Models\Term
record containing the term's name and slug. Term::taxonomies() returns its
taxonomy records.
Post::taxonomies() and Taxonomy::posts() use WordPress's term_relationships
table, including the pivot's term_order. Post subclasses inherit this relationship.
$post = \MM\Meros\App\Models\Post::with('taxonomies.term')->findOrFail($postId); $tags = $post->taxonomies()->where('taxonomy', 'form-tags')->with('term')->get();
Use WordPress taxonomy APIs for writes so term counts and caches stay in sync.
PostType::inspect($postId) includes a taxonomies key grouped by associated
taxonomy handle. Each assigned term is an array containing term_id, name,
slug, and term_group. Unassigned taxonomies have empty lists; calling
inspect() without a post ID returns empty lists for all associated taxonomies.
Associations include configured taxonomy features, raw handles and WordPress
registrations. Existing post attributes and metadata remain alongside this data.
Built-in form taxonomies
The framework's built-in Form and FormTemplate post types share the
non-hierarchical form-tags taxonomy, configured by App\Content\FormTags.
It is available in the REST API and adds a tags column to their admin lists.
Both post types are grouped under the framework's top-level Forms menu,
alongside a single Form Tags link. Their native list and editor screens
remain available. PostType::showInMenu() accepts either a boolean or a parent
menu slug when grouping other post types.
Form Templates are non-public, with their WordPress admin UI explicitly enabled.
Templates declared by a post type through the UsesForms trait are provisioned
by code, show a Provided by theme label, and cannot be deleted or trashed
while the declaring post type is registered. Once that post type is no longer
registered, its templates can be deleted. Templates can also be created with
WordPress's Add New action; these are offered as starting points for generic
forms. A template's actions are copied to the forms that use it; disabling the
template's Allow Actions Overrides setting makes those actions read-only on
the forms, which then always run the template's actions.
Forms and Form Templates use read_forms for list access and edit_forms for
editing. Form Readers can browse the lists, while Form Managers can edit both
types, create/delete regular forms and create/delete unprotected templates.
Editors and administrators receive both capabilities by
default; grants remain configurable through Security settings.
The shared Form Tags screen is readable with read_forms; changing or assigning
tags requires edit_forms. Explicit meta capabilities separate read-only list
access from editing, without changing access to ordinary WordPress posts.
All four form capabilities opt into assignment to default WordPress roles in
Security > Manage Permissions. For other capabilities, call both
userConfigurable() and assignableToDefaultRoles() to enable this. The latter
does not grant capabilities automatically; roles([...]) still defines defaults.
Administrator remains read-only and receives every registered capability.
The special form post at slug f is hidden from the Forms admin list, but
remains available for front-end form-host rendering.
WordPress permission checks prevent editing, trashing or deleting it, including
through direct editor links or API requests. Its former editor redirect is no
longer needed; normal forms remain editable by users with edit_forms.
License
MIT.