=== 404ops S3 Data Mover ===
Contributors: spwhite
Tags: s3, storage, sync, media, cloud
Requires at least: 7.0
Tested up to: 7.1
Requires PHP: 8.2
Stable tag: 1.13.8
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Move, sync, and schedule file transfers between WordPress and Amazon S3 or any S3-compatible storage service.

== Description ==

Move, sync, and schedule file transfers between WordPress and Amazon S3 or any S3-compatible storage service, such as MinIO, DigitalOcean Spaces, Backblaze B2, Cloudflare R2 or Wasabi. It has no third-party dependencies: its own S3 client signs each request with AWS Signature Version 4 and sends it through WordPress's HTTP API.

**What's included:**

* Connections: add one or more S3 connections, each with its own access key ID and secret access key. Choose AWS (with a region) or S3-compatible (with your endpoint URL). One connection is active at a time.
* File Browser: browse a connected bucket from the admin, and pull selected files to your site or push local files up.
* Pull, push and sync: move files into the Media Library or a folder under wp-content/uploads, or run a two-way sync. Conflicts can overwrite, skip, or keep every version under a timestamped name. Files over 512 MB are skipped.
* Scheduled tasks: recurring pull, push or sync tasks, run by WP-Cron. If a task starts failing, the plugin emails the admin address once, and again when it recovers. Leave the address empty to send no email.
* Automatic offload (off by default): copy new Media Library uploads, and their generated sizes, to S3 in the background. Failed pushes are retried three times, and can be retried from the Settings screen.
* Serve from the bucket (off by default): serve offloaded files from the bucket or a CDN base URL you set. Only files confirmed to be in the bucket are served from it. Public-read buckets and CDNs only.
* Optional verified local-copy removal. The plugin commits recovery information and serving protection before removing a matching local copy. After updating from an earlier version, drain the old requests, confirm a current backup, and authorize removal again in Local copies. Verified removal requires a private staging directory on the uploads filesystem configured with S3DM_RECOVERY_DIR. Older releases may have left incomplete recovery records.
* Switch from WP Offload Media: adopt the files it already put in your bucket, in any bucket, including sizes and non-library files, without uploading them again.
* Activity logs: every operation is recorded with its status, file count, bytes and duration, and can be exported to CSV.
* AI alt text (optional): draft missing alt text from the file name, dimensions, title and caption only.
* WP-CLI: `wp s3dm push`, `wp s3dm pull` and `wp s3dm status`, with batching, `--resume` and `--dry-run`.

Access keys are encrypted before they are stored in your database. The External services section lists every outside host the plugin can contact, and when.

== Installation ==
1. Upload the plugin through `Plugins > Add New > Upload Plugin`, or copy it to `wp-content/plugins/`.
2. Activate 404ops S3 Data Mover through the `Plugins` screen.
3. Go to `404ops > S3 Data Mover` in the admin sidebar, add a connection with your access key ID and secret access key, then use the navigation row at the top of the page to reach the File Browser, Scheduler, or Logs screens and move files.

== Frequently Asked Questions ==

= Where can I get help? =
Visit https://supportminer.404ops.com to open a support request.

= What data does this plugin send to S3, and why? =
It sends the file contents you choose to pull/push/sync, plus the bucket name and object path/key for each transfer, to Amazon S3 or the S3-compatible endpoint you configure. This is required for the plugin's core purpose of moving files between WordPress and S3-compatible storage.

= Does this work with providers other than Amazon S3? =
Yes. The connection form has presets for Cloudflare R2, Backblaze B2, Wasabi, DigitalOcean Spaces and MinIO that fill in the authentication type, the endpoint pattern and the region the way each provider documents them; you replace the parts in braces (an account ID, a region, a host) with your own. Any other provider that speaks the S3 API works with "Other S3-compatible service" and its endpoint URL.

= How are my access keys stored? =
Access key IDs and secret access keys are encrypted (AES-256-CBC, keyed from your site's WordPress authentication salts) before being stored in your WordPress database.

= Can new uploads be copied to S3 automatically? =
Yes. Turn on "Copy new Media Library uploads to S3 automatically" on the Settings screen, and choose a connection and an optional key prefix. New uploads (and their generated thumbnail sizes) are queued after the upload finishes, never during it, and pushed to S3 in the background via WP-Cron. A failed push is retried up to three times with increasing delays; if it still fails, the upload is marked failed and can be retried from the Settings screen, which also shows how many uploads are currently offloaded or failed. This only copies files to S3: it does not delete the local copy or change any Media Library URLs.

= Is there a Pro add-on? =
Yes: 404ops S3 Data Mover Pro, a separate plugin that needs this one and is not part of it. It adds resumable, rate-limited and parallel transfers, scheduled tasks that carry deletions across (a mirror) with a preview and a safety stop, an offsite engine that 404ops Backup and other plugins can ship files through (with checksums and retention), and failure alerts by webhook and email. Everything on this page stays in this plugin; the add-on only adds to it. This plugin never loads the add-on's code, and works exactly the same without it. Support: https://supportminer.404ops.com

= What happens to my data if I uninstall the plugin? =
Restore any media that relies on bucket-only serving before you delete the plugin. Uninstall removes its scheduled tasks, sync history, automatic offload settings, and cron events. It preserves media recovery records and keeps the connections and serving settings when there are recorded removals or when recovery state cannot be verified. On multisite, shared settings and connections are kept if any site still needs them for recovery. Uninstall leaves existing local files and S3 objects in place.

= Is there a file size limit? =
Yes, individual files larger than 512 MB are skipped during pull and push operations.

= Is there a way to move a large media library without clicking through the File Browser? =
Yes, with WP-CLI: `wp s3dm push --all` pushes every attachment, `wp s3dm pull --all` pulls every object in the bucket into the Media Library, and `wp s3dm status` reports counts of what is local-only, remote-only, and already synced. See the WP-CLI section below.

== WP-CLI ==

For bulk or scripted transfers, three commands are available once the plugin is active:

* `wp s3dm push [--ids=<ids>] [--all] [--dry-run] [--batch=<n>] [--resume]` — push media library attachments to the active connection's bucket, either specific attachment ids or the whole library.
* `wp s3dm pull [--ids=<ids>] [--all] [--dry-run] [--batch=<n>] [--resume]` — pull objects from the bucket into the Media Library, either specific S3 object keys or the whole bucket.
* `wp s3dm status` — counts of what is local-only, remote-only, and already synced, plus how many uploads automatic offload has copied or failed to copy.

Both `push --all` and `pull --all` process attachments/objects in batches (50 by default; `--batch` changes that) and can be resumed with `--resume` if interrupted. `--dry-run` reports what would be transferred without transferring anything. Credentials are always the ones already configured on the Settings screen; they are never accepted as command-line flags. Run `wp help s3dm push`, `wp help s3dm pull`, or `wp help s3dm status` for the full option list.

Local copies check and restore commands report recorded file failures as a nonzero exit. The network cursor reports the current invocation. Review earlier warnings after using `--resume`.

Restore keeps conflicting local files and their recovery records. If a report identifies a conflict, make an independent backup of the local file before moving it aside and retrying. A file whose recorded size or checksum is missing needs manual review. Earlier versions may have left incomplete records.

= Which files can I pull to my site? =

Imports support common image, audio, video, document, text/data and archive formats that your WordPress upload policy permits. JSON, XML and SQL need an allowed-MIME entry when your site does not permit them by default. HTML, SVG, executable scripts, configuration files and script-bearing double extensions are refused. XML must be inert data without DTDs, processing instructions or browser-executable namespaces. Archives are copied without extraction. Downloads are checked in private temporary storage before they replace a public file; a failed or refused download leaves the existing file intact.

== External services ==

This plugin's core function is transferring files to and from Amazon S3 or an S3-compatible storage provider, so by design it sends data outside your WordPress site. It contacts an outside service only when you add a connection and run an operation:

* Pull, push and sync, from the File Browser, the WP-CLI commands, a scheduled task you created, or automatic offload of new uploads (when you turn that on). The bucket and object names, and the file contents you choose to transfer, are sent over HTTPS to Amazon S3 or to the S3-compatible endpoint you configure, using the plugin's own S3 client (AWS Signature Version 4 over WordPress's HTTP API). No other service is contacted.
* The optional local-copy check and removal query the configured bucket for object size and checksum. A restore can download a recorded object when no staged local copy is available.
* Switching from WP Offload Media: "Verify" and the optional size check query the bucket for the objects WP Offload Media recorded. Nothing is uploaded.
* Serving media from the bucket: visitors' browsers fetch offloaded files directly from the bucket or CDN base URL you set. The plugin sends nothing for this.

Each connection needs an access key ID and secret access key from your storage provider. Nothing is sent on activation.

Amazon Web Services: https://aws.amazon.com/service-terms/ and https://aws.amazon.com/privacy/. If you use a non-AWS S3-compatible provider, that provider's own terms and privacy policy apply instead.

**AI alt text (optional).** Only if you connect an AI provider on the shared AI Connection screen (404ops > AI Connection) and run "Fill missing alt text with AI". For each image, the plugin sends its file name, dimensions, title and caption to that provider. The image itself is not sent. The providers are OpenAI (`api.openai.com`), Anthropic (`api.anthropic.com`), Google Gemini (`generativelanguage.googleapis.com`), OpenRouter (`openrouter.ai`), an OpenAI-compatible base URL you enter, and Ollama (by default `localhost`). Each provider's own terms and privacy policy apply to that request.

AI provider policy references for the optional shared AI connection:

* OpenAI: [API services agreement](https://openai.com/policies/services-agreement/) and [privacy policy](https://openai.com/policies/privacy-policy/).
* Anthropic: [commercial terms](https://www.anthropic.com/legal/commercial-terms) and [privacy policy](https://www.anthropic.com/legal/privacy).
* Gemini: [API terms](https://ai.google.dev/gemini-api/terms) and [Google privacy policy](https://policies.google.com/privacy).
* OpenRouter: [terms](https://openrouter.ai/terms) and [privacy policy](https://openrouter.ai/privacy). OpenRouter can route requests to another model provider; review the provider selected in your account as well.

For Ollama or an OpenAI-compatible endpoint, requests go to the server URL you configure. Review that server operator's terms and privacy policy. The plugin sends requests to the configured address; its operator determines any onward processing. The information sent and the actions that trigger a request are described above.

Failure notification emails go through your site's own mail system (wp_mail) to the address on the Scheduler screen. No other service is contacted.

== Screenshots ==

1. Settings: S3 connections, automatic offload of new uploads, CDN base URL and signed URLs for private buckets.
2. Scheduler: create pull, push and sync tasks, with an email when a scheduled task starts failing.
3. Migrate from WP Offload Media: adopt the files it already put in your bucket without uploading them again.
4. Check offloaded files, authorize verified local-copy removal, and recover recorded files.

== Changelog ==

= 1.13.8 =
* Updated: match the Pro multisite licence cleanup release.

= 1.13.7 =
* Documentation: explain which settings and records uninstall keeps for media recovery.

= 1.13.6 =
* Fixed: verify the recovery record and serving protection before removing a local copy.
* Fixed: recover interrupted removals and retain both copies when a replacement conflicts.

= 1.13.5 =
* Security: authenticate stored connection credentials and refuse missing, blank or sample encryption keys. Failed replacements preserve stored connections.
* Fixed: blank credential edits keep stored values without unnecessary encryption; site and network screens explain encryption failures.

= 1.13.4 =
* Security: validate downloaded file names and content in private temporary storage before publishing uploads; preserve existing files on failure.
* Fixed: scheduled imports, restored local media and Pro mirror use the same safe file policy; empty recorded text restores require no ranged download.

= 1.13.3 =
* Added: guarded read-only administrative status interfaces.
* Added: five bundled draft language catalogs with checked WordPress loading.
* Improved: development test-session and catalog packaging checks.

= 1.13.2 =
* Fixed: Settings, Scheduler and File Browser saved text with extra backslashes. A connection or task name with an apostrophe, and a secret key containing a backslash, now save exactly as typed.
* Fixed: the File Browser's pull and push refuse a malformed file list instead of failing partway.
* Fixed: the Logs screen reads its filters the same way as its CSV export.
* Fixed: a missing form field or notice count no longer raises a PHP warning on the Settings and Scheduler screens.
* Maintenance: removed the call that loaded translation files (translations are delivered by wordpress.org), and tidied database queries and internal names.

= 1.13.1 =
* Updated the licence client (0.3.5): Pro keeps working after a licence expires.

= 1.13.0 =
* New: Switching from WP Offload Media also adopts sizes its records never listed (an optional check against the bucket), records in other buckets (each to the connection for its bucket), files that are not Media Library items, its object prefix for new uploads, and its multisite key layout.
* New: The S3 client can send several uploads at once, for the Pro add-on's "Transfers at once" setting.
* Pro: parallel transfers, an offsite engine for 404ops Backup and other plugins (checksums, manifests, retention), and offsite failure alerts by email and webhook.

= 1.12.5 =
* Updated the bundled licence client to 0.3.4.

= 1.12.4 =
* Listing: real WordPress.org screenshots, with one matching caption each in the Screenshots section. No code change.

= 1.12.3 =
* Fixed a fatal error on the licence screen after activating a Pro licence.

= 1.12.2 =
* Pro update packages now publish with maintenance information and one shared licence client version.

= 1.12.1 =
* Mirror deletions now need approval of the exact reviewed plan.

= 1.12.0 =
* Added the Pro add-on extension points and refreshed wording.

= 1.11.7 =
* Admin menu labels and page headings drop the 404ops brand prefix.

= 1.11.6 =
* Changed: S3 requests use a native SigV4 client in place of the AWS SDK, which is removed from the dependencies; Composer's generated loader is hardened for Plugin Check.

= 1.11.5 =
* Plugin URI points to the 404ops.com plugins page.

= 1.11.4 =
* Fixed: WordPress.org listing corrections. The readme now names the contributor account, has a standalone External services section, and its description and changelog are shortened. No runtime behaviour change.

= 1.11.3 =
* Changed: Bundled libraries updated; translatable strings now use this plugin's text domain.

= 1.11.2 =
* Requires WordPress 7.0 or newer (it was 6.9); tested up to WordPress 7.1.

= 1.11.1 =
* Requires WordPress 6.9 or newer; tested up to WordPress 7.1.

= 1.11.0 =
* New: Test connection writes, reads back and deletes one small object, so it works with scoped keys such as Cloudflare R2 tokens and Backblaze application keys.
* Security: S3-compatible endpoints must be https:// and point at a public address. The connection follows no redirects. A "Local test endpoint" option allows http:// to a private address.

= 1.10.0 =
* New: Audit the bucket. A resumable scan lists files in the plugin's folder that no attachment uses. Deletion is available only after you confirm that exact audit, and each file is checked again before it is deleted.

Older entries are in CHANGELOG.md.

== Upgrade Notice ==

= 1.13.8 =
Drain requests running older versions before authorizing local-copy removal again. Keep a current backup. Sites using older credential storage may need to re-enter their connection keys.

= 1.13.5 =
Security update: configure private AUTH_KEY and SECURE_AUTH_KEY values. Credentials stored in an older format require deliberate re-entry; failed reads or replacements leave stored rows intact.

= 1.13.4 =
Security update: remote downloads are validated before they become public files.

= 1.13.3 =
Includes checked draft translations and administrative status reporting. Human linguistic review is separate.

= 1.13.2 =
Fixes text being saved with extra backslashes in Settings and the Scheduler. Safe to update.

= 1.13.0 =
Adds a database table for WP Offload Media files that are not Media Library items. Safe to update.


= 1.12.4 =
Listing-only update: new screenshots and captions. No code change.

= 1.11.4 =
Readme and WordPress.org listing corrections only; no change to plugin behaviour. Safe to update.

= 1.11.3 =
Bundled libraries updated. Safe to update.

= 1.11.2 =
Now requires WordPress 7.0 or newer and is tested up to 7.1. Safe to update.

= 1.11.1 =
Now requires WordPress 6.9 or newer and is tested up to 7.1. Safe to update.

= 1.11.0 =
Safer, more useful connection test; endpoints must be https and public unless you tick the local test box. Safe to update.

= 1.10.0 =
Adds a bucket audit and a confirmed clean-up of files no attachment uses. Safe to update.

= 1.9.0 =
Fixes a too-early translation notice and bundles its own prefixed UI kit. Safe to update.

= 1.8.1 =
Maintenance release: AI features use a private copy of the AI client; re-enter your AI connection once. Safe to update.

= 1.8.0 =
Adds optional delete sync and private media via signed links. Safe to update.

= 1.7.0 =
Adds multisite network support. Per-site activation is unchanged. Safe to update.

= 1.6.0 =
Adds an optional mode to remove local media copies once they are safely in the bucket. Off by default. Safe to update.

= 1.5.0 =
Adds switching from WP Offload Media without re-uploading media. Safe to update.

= 1.4.0 =
Optional: serve offloaded media from your bucket or CDN (off by default). Safe to update.

= 1.1.0 =
* Feature release. No configuration changes needed.
= 1.0.0 =
Submission-readiness release. No functional transfer changes.
