mainwp-custom-dashboard category. All use the mainwp/ namespace and manage snippets on the MainWP Dashboard site, not Child sites.
What You’ll Learn
- Read snippet status and its current revision without retrieving saved code
- Validate proposed PHP without storing or executing it
- Preview and confirm snippet replacements or removals
- Handle conflicts and uncertain write outcomes
Prerequisites
- WordPress 6.9 or later on the MainWP Dashboard site
- MainWP Dashboard with Abilities API support; use version 6.2 or later for the
input_jsonand DELETE request examples below - Custom Dashboard 5.2 or later, active and enabled in MainWP Dashboard
- An authenticated WordPress user with
manage_optionsand access to the Custom Dashboard Add-on
Available Abilities
Discover their complete input and output schemas:
Inputs and Execution Scope
Thetype field accepts exactly php, css, or js. There is one stored snippet per type. These abilities reject unknown input fields; they do not accept a Child site ID or a snippet collection.
Code must be a valid UTF-8 string without null bytes. The input limit is 100,000 characters and 262,144 bytes. On servers without mb_strlen, the character check uses byte length, so the effective limit is 100,000 bytes. Replacement requires a nonempty string; use the clear ability to remove a snippet. PHP validation accepts an empty string.
Validation and previews do not execute the submitted code. After a confirmed write, saved code participates in the normal runtime described above. Syntax acceptance does not prove that PHP is safe or that its runtime behavior is correct. CSS and JavaScript previews check input bounds and revisions, but do not lint the code or test its behavior in a browser.
Read Snippet Metadata
Ability:mainwp/get-custom-dashboard-snippet-metadata-v1Method: GET
configured means the stored snippet is nonempty, not that it has executed successfully. observed_at is the UTC observation time. The response does not include saved source, source size, runtime output, or error details.
revision is an opaque 64-character lowercase hexadecimal value bound to the snippet type and current stored state. Use it as expected_revision for previews and changes. Do not compute it yourself or substitute the editor’s internal revision. The repeated a value in these examples is fictional; replace it with the value returned by your metadata read.
Validate PHP
Ability:mainwp/validate-custom-dashboard-php-v1Method: POST
code is the only input. Supply tagless PHP, without opening or closing PHP tags. The validator parses it without executing or storing it. Responses classify the result without echoing code or parser error text.
A closure’s
use (...) clause is allowed. A syntax rejection returns valid: false with the issue category; it is not a runtime execution result. Invalid input types, encoding, or size limits are rejected as request errors.
Preview and Confirm Changes
Both replacement and clearing require a currentexpected_revision and an explicit boolean dry_run:
Read metadata for the selected type, send a preview, and review its result. To apply the change, resend the same target, revision, and proposed code with
dry_run: false and confirm: true. For clearing, omit code. A preview does not reserve the revision, so another edit can still cause the confirmed request to fail with a conflict.
The preview response’s revision remains the current revision. A successful change returns the verified revision after the write. There is no request ID or idempotency-token field for these abilities.
Replace a Snippet
Ability:mainwp/replace-custom-dashboard-snippet-v1Method: POST Preview a CSS replacement:
type, code, expected_revision, and dry_run. Apply with confirm: true as described in Preview and Confirm Changes. This replaces the entire stored snippet for that type; it does not append or merge code.
Example response for a preview that would change the CSS:
status set to applied when the write commits or unchanged when the supplied code already matches. In preview mode, preview.changed reports whether the code would differ; after execution it reports whether a write committed.
For PHP, inspect preview.ready and preview.validation_issue. Invalid PHP can produce a successful preview response with ready: false; a confirmed replacement is then rejected with validation_failed. The submitted source is not returned. Keep your proposed code and review the complete replacement before confirming.
Clear a Snippet
Ability:mainwp/clear-custom-dashboard-snippet-v1Method: DELETE
type, expected_revision, and dry_run. Do not send a code field. After reviewing the preview, set dry_run: false and confirm: true to clear that type’s saved source.
The response contains status, preview, previous_revision, revision, and observed_at. Its nested preview contains type, changed, and result_configured, which is always false. Status is preview, cleared, or unchanged if the snippet is already empty. Other snippet types are unaffected.
Clearing prevents the saved snippet from being used on subsequent requests. It does not undo effects that code already produced, such as database changes made by PHP. Keep a copy of any source you may need before clearing it; these abilities do not provide source retrieval or a rollback history.
Conflicts and Errors
Error codes use themainwp_custom_dashboard_ prefix:
After a conflict, preserve your proposed code and use the Custom Dashboard editor to compare it with the latest saved source. Reading a newer revision and immediately overwriting it can discard someone else’s work.
Do not automatically retry a replacement after a lost response or unknown result. First read metadata and inspect the editor if needed. A metadata revision change alone does not prove your specific replacement succeeded, because metadata does not return source. Clearing is marked idempotent, but its revision check still applies; an old revision can conflict after a successful clear.
Related Resources
- Custom Dashboard Add-on - Editor workflow and PHP recovery
- Abilities API Overview - Authentication, discovery, and request formats
- Code Snippets Add-on - Deploy code to Child sites
