=== Ngaycdn CDN ===
Contributors: vuongnguyenbinh
Tags: cdn, media, image, cloudflare, optimize
Requires at least: 6.4
Tested up to: 6.6
Requires PHP: 7.4
Stable tag: 0.2.0
License: GPL-2.0-or-later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Auto-upload WP media to Ngaycdn CDN. Rewrite attachment URLs and srcset to CDN edge for fast global delivery.

== Description ==

Ngaycdn CDN integrates a self-hosted Cloudflare-backed image CDN with WordPress:

* Every uploaded image goes to the CDN automatically
* `wp_get_attachment_url()` returns the CDN URL — every theme, plugin, REST endpoint sees CDN URLs without modification
* `srcset` rewritten to CDN with on-the-fly width transforms (`?w=400`, `?w=800`, etc.)
* Optional `the_content` legacy rewrite for posts that pre-date plugin install
* WP-CLI bulk migrate command for existing libraries
* Auto-update from GitHub releases (no WP.org submission required)

== Installation ==

1. Upload the `ngaycdn` folder to `/wp-content/plugins/`, or install via the GitHub release zip.
2. Activate the plugin.
3. Go to **Settings → Ngaycdn CDN** and paste your API key (generate one in the CDN admin under **API Keys**, scope `wp`).
4. Click **Test connection** to confirm.
5. Upload an image via the media library — the URL returned should be your CDN endpoint.

== Migrate existing media ==

After configuring, run:

`wp ngaycdn migrate --dry-run` (preview)
`wp ngaycdn migrate` (full)

Each attachment is uploaded once and tagged with `_ngaycdn_id` meta so subsequent runs skip it.

== Frequently Asked Questions ==

= What if the CDN is unreachable when uploading? =
The plugin degrades gracefully — your upload still completes via WP's native handler. No CDN URL is stored for that attachment; you can re-run `wp ngaycdn migrate` later.

= Does it support custom widths? =
Yes. Filter `ngaycdn_srcset_widths` to override the default `[400, 800, 1200, 1600]`.

= Where is my API key stored? =
In `wp_options` under the `ngaycdn_settings` row. Treat it like any password — restrict admin access.

== Changelog ==

= 0.2.0 =
* "Rewrite legacy image URLs" now rewrites the whole page output (not only post content) — inline backgrounds, lazy-load attributes, theme-builder markup; originals get `?format=auto`, size-suffixed files become `?w=` variants.
* Tenant-scoped delivery URLs (`https://cdn.ngay.net/<tenant>/<slug>.<ext>`) — new **Tenant slug** setting.
* Attachment URLs prefer the exact URL returned by the CDN at upload time; presets and srcset degrade to WP's local URLs (never broken images) when the tenant slug is unknown.
* Admin notice when an API key is set but the tenant slug is empty.
* Responsive `srcset`/`sizes` injected via `wp_content_img_tag` + `wp_get_attachment_image_attributes` (WP core skips its own srcset once `src` leaves wp-content/uploads); `image_downsize` maps intermediate sizes to `?w=` variants instead of non-existent `-WxH` files.

= 0.1.0 =
* Initial release.
* Settings page, upload hook, attachment URL + srcset rewrite, optional content filter, WP-CLI migrate, GitHub auto-update.
