Skip to main content
These abilities require the File Uploader release that includes Abilities API support. Earlier builds do not register them. Check ability discovery on your Dashboard before using these examples.
The Abilities-enabled File Uploader release registers eight abilities in the mainwp-file-uploader category. Calls run on your MainWP Dashboard and use the mainwp/ namespace.

What You’ll Learn

  • Read the staging limits and allowed destinations
  • List, inspect, and delete your staged files
  • Preview a deployment and confirm it with a short-lived token
  • Track a deployment and roll it back within the retention window

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_json examples
  • An active File Uploader build that registers these abilities
  • A MainWP Child version on the target site that supports the File Uploader v2 deployment protocol
  • An authenticated user with access to the File Uploader Add-on
  • manage_options for every ability except the policy, list, and get-object reads
  • Access to the selected site, with MainWP permission to edit sites, for preview, start, status, and rollback
Team Control restrictions apply. Each staged file and each deployment belongs to the user who created it. Other users, including other administrators, cannot read, deploy, or delete it. Use an Application Password or another supported authentication method. The examples use an Application Password.

Available Abilities

Discover the abilities and their full input and output schemas:
All abilities reject extra input properties. References such as object_ref, operation_ref, and request_ref are UUIDs.

How Staged Deployment Works

When you upload a file on the File Uploader page, File Uploader keeps an immutable copy in private storage on the Dashboard. Each copy is a staged object with a SHA-256 digest and a revision. The abilities do not upload new files. They work with the staged objects you already uploaded. A deployment follows four steps:
1

Find the staged object

Call mainwp/list-staged-file-objects-v1 and copy the object_ref of the file you want to deploy.
2

Preview the deployment

Call mainwp/preview-file-deployment-v1 with the site and destination. MainWP Child reports whether the target exists and its current digest. The response includes a preview_token that expires after five minutes.
3

Start the deployment

Call mainwp/start-file-deployment-v1 with the same inputs, the preview_token, and a new request_ref. File Uploader queues the deployment and returns an operation_ref. WP-Cron runs the transfer in the background.
4

Check the result

Poll mainwp/get-file-deployment-status-v1 until status is completed, failed, or unknown.

Staging Policy

Ability: mainwp/get-file-uploader-policy-v1
Method: GET
This ability takes no input and does not contact a Child site.
Example response:

Staged Objects

List staged objects

Ability: mainwp/list-staged-file-objects-v1
Method: GET
All inputs are optional. state filters by ready, in_use, or expired. limit accepts 1 to 100 and defaults to 50.
Example response:
The response does not include the original file name or storage path. When truncated is true, pass the next.after_created_at and next.after_object_ref values as input to get the next page. Supply both cursor fields or neither.

Get one staged object

Ability: mainwp/get-staged-file-object-v1
Method: GET
The response wraps the object fields in an object property.

Delete a staged object

Ability: mainwp/delete-staged-file-object-v1
Method: DELETE
Deletion is permanent. Only objects with zero active_references in the ready or expired state can be deleted. All four inputs are required:
  • object_ref: the object to delete
  • if_match: the object’s current revision
  • confirm: must be true
  • request_ref: a new UUID that identifies this request
Example response:
Repeating the same request with the same request_ref returns the stored result. Reusing a request_ref with different input returns mainwp_file_uploader_conflict.

Deployments

Destinations

relative_destination is the full target path, including the file name, relative to the WordPress root. It must start with one of these prefixes: The capabilities are checked for your user on the Dashboard. When DISALLOW_FILE_EDIT is enabled on the Dashboard, WordPress removes edit_plugins and edit_themes, so code destinations are blocked. Paths cannot start with / or contain empty, ., or .. segments, backslashes, %, :, or control characters. Paths are limited to 1,024 characters and 32 segments. The uploads destination refuses server-executable and server-configuration files. This includes .htaccess, .user.ini, web.config, and any file name with a PHP-family token such as .php, .php8, .phtml, or .phar, or with .shtml or ASP.NET extensions. A name such as shell.php.jpg is also refused. These requests return mainwp_file_uploader_destination_forbidden.

Preview a deployment

Ability: mainwp/preview-file-deployment-v1
Method: GET
Preview performs a read-only check on the Child site and changes nothing.
Example response:
Review will_overwrite and prior_sha256 before you start. The preview_token is bound to this object, site, destination, and the current state of the target file. It expires after five minutes. The site must be connected without sync errors, not suspended, and not offline. Otherwise the preview returns mainwp_file_uploader_conflict.

Start a deployment

Ability: mainwp/start-file-deployment-v1
Method: POST
Pass the same object_ref, site_id_or_domain, relative_destination, and confirm_code you used for the preview, plus:
  • preview_token: the token from the preview response
  • request_ref: a new UUID that identifies this request
All six inputs are required.
Example response:
File Uploader repeats the Child check before it queues the deployment. If the target file changed since the preview, or the token expired, the call returns mainwp_file_uploader_stale_preview. Run a new preview and start again. The deployment never runs inside the request. WP-Cron transfers the file, and MainWP Child verifies the byte count and SHA-256 digest before File Uploader marks it complete. Retrying with the same request_ref and input returns the original response.

Check deployment status

Ability: mainwp/get-file-deployment-status-v1
Method: GET
Status reads the stored operation record and does not contact the Child site. Use it for both deployments and rollbacks.
Example response:
kind is deploy or rollback. attempts counts dispatch attempts, up to 3. For failures, code is one of access_denied, stale_preview, destination_forbidden, object_rejected, remote_failure, write_failed, retry_exhausted, or outcome_unknown. bytes and sha256 are set only for completed operations. bytes becomes null after the staged object is removed. rollback_available reports the completion-time window. Rollback can still be refused if the staged object or Child backup is gone or the destination has changed.

Roll back a deployment

Ability: mainwp/rollback-file-deployment-v1
Method: POST
Rollback restores the target path to its state before the deployment, removing the deployed file if no file existed before. It only reverses that file change; it does not undo effects caused by executing uploaded code. You can roll back only a completed deployment, within 24 hours, while its staged object still exists. The target file on the Child must still match the deployed digest. All four inputs are required:
  • operation_ref: the deployment’s operation reference
  • if_current_sha256: the deployment’s sha256 from the status response
  • confirm: must be true
  • request_ref: a new UUID that identifies this request
Example response:
Pass rollback_operation_ref to the status ability to follow the rollback. If the file on the Child changed after the deployment, the rollback returns mainwp_file_uploader_conflict.

Handling Errors

Current authorization and state checks can refuse a repeated start or rollback after the operation changes state. Check status before repeating a completed request. Start and rollback are not idempotent across different request_ref values. After an uncertain response, retry with the same request_ref instead of creating a new one.