=== HXSR — Smart Redirecter ===
Contributors: youheiokubo
Tags: redirect, short url, qr code, link management, scheduled redirect
Requires at least: 6.3
Tested up to: 7.0
Requires PHP: 7.4
Stable tag: 0.1.13
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Code-First Smart Redirect Manager. Custom short links with scheduled redirects, QR codes, usage memos, and Markdown export.

== Description ==

HXSR (Smart Redirecter) is part of the [HX Series](https://github.com/okuboyouhei) — a collection of AI-ready, buildless WordPress plugins following the WAHX stack philosophy.

**Core features:**

* **Custom short links** — Define your own slugs: `example.com/go/summer-sale`
* **Custom prefix** — Change `/go/` to anything you like (`/r/`, `/link/`, etc.)
* **Scheduled redirects** — Set a date/time to automatically switch the redirect destination
* **Chained schedules** — Add multiple scheduled redirects in sequence
* **Usage memos** — Note where each link is used (flyers, banners, email campaigns, etc.)
* **Access counting** — Track total hits per link (no IP logging, privacy-safe)
* **QR code generation** — Download as PNG, with or without a serial number
* **Post / Page targets** — Redirect to a post or page by ID; the URL is resolved at runtime via `get_permalink()`, so links keep working across staging and production environments with different domains
* **Media Library integration** — Redirect to Media Library items by attachment ID (great for PDFs and images), resolved at runtime via `wp_get_attachment_url()`
* **Markdown export** — Export any link's info as a `.md` file; auto-connects to HXMD if active (HX Bridge pattern)
* **302 redirects** — Always temporary, cache-safe, correct for scheduled switching

**AI-friendly documentation** is bundled in the plugin zip (`CLAUDE.md`, `ai-reference.md`, `llms.txt`) — designed for use with Claude Code and other AI coding agents.

== Installation ==

1. Upload the plugin folder to `/wp-content/plugins/` or install via the WordPress admin.
2. Activate the plugin.
3. Go to **Settings → HXSR** to configure your prefix and add links.

== External services ==

This plugin uses the **QR Server API** (api.qrserver.com, operated by goQR.me) to generate QR code images.

* **What data is sent:** the short link URL (e.g. `https://example.com/go/summer-sale/`) is sent to api.qrserver.com when an administrator previews or downloads a QR code in the admin screen. No visitor data, personal data, or site credentials are ever sent.
* **When:** only on explicit admin actions (QR preview / PNG download). Site visitors never trigger any external request.
* **Service terms:** https://goqr.me/api/ and privacy policy: https://goqr.me/privacy-safety-security/

== Frequently Asked Questions ==

= Why 302 and not 301? =

HXSR is designed for scheduled and changeable redirects. 301 redirects are cached by browsers and would prevent scheduled switching from working reliably. 302 is always the correct choice here.

= Does this log visitor IPs? =

No. HXSR only counts total accesses per link (a simple integer increment). No IP addresses, user agents, or timestamps are stored. Visitors never trigger any external request either — the QR Server API (see External services) is only called from the admin screen.

= Does clicking my own short links count toward the total? =

No. If you're logged in as an administrator (`manage_options`), visiting a short link still redirects you normally but does not increment the counter — only visits from logged-out visitors are counted. You can also manually reset any link's count to 0 from the links list.

= What is the serial number on QR codes? =

An optional 6-digit identifier (e.g. `SN:000042`) printed below the QR code image. Useful for tracking which physical printout or flyer a scan came from.

= What is the HX Bridge pattern? =

If the HXMD plugin is active, HXSR will automatically save link data as a Markdown log via HXMD. If HXMD is not installed, HXSR still works perfectly and offers standalone `.md` download.

== Screenshots ==

1. Link management list
2. Edit modal with QR preview and schedule
3. Settings (prefix configuration)

== Changelog ==

= 0.1.13 =
* Fix: restored the "Plugin URI" header now that the GitHub repository (https://github.com/okuboyouhei/hxsr-smart-redirecter) is public

= 0.1.12 =
* Fix: removed the "Plugin URI" header (repository not yet public; the field is optional and was flagged as a dead link during WordPress.org review)
* Fix: corrected the goQR.me privacy policy URL in the "External services" section (was pointing to a 404)

= 0.1.11 =
* New: live duplicate-slug check while typing — shows a warning under the Slug field and disables Save, instead of waiting for a failed save to report it (no scrolling needed, since the Slug field is always at the top of the modal)

= 0.1.10 =
* Fix: on WP_DEBUG_DISPLAY-enabled sites, a duplicate-slug save could leak a raw database error page into the AJAX response, breaking JSON parsing so the error silently failed to display. Expected constraint-violation errors are now suppressed at the query level.
* Fix: save error message now names the conflicting slug specifically
* Change: the in-modal error box now scrolls into view automatically, so it's visible even if you had scrolled down while filling the form (e.g. adding a schedule)

= 0.1.9 =
* New: reset access count to 0 from the links list (small reset icon next to the count)
* Change: logged-in administrators (manage_options) no longer increment the access count when visiting a short link themselves — only real visitor traffic is counted

= 0.1.8 =
* Refactor: removed all inline style="" attributes from the admin template (21 occurrences) and moved them into CSS classes. Previous layout fixes had inconsistent effect because inline styles on individual elements were competing with the stylesheet; the admin UI now fully follows the --hxsr-* token system.

= 0.1.7 =
* Style: fixed list row layout — serial number and memo icon now sit on one line instead of wrapping separately
* Style: Delete button now matches the other pill buttons instead of looking like plain text
* Style: Add Schedule fields top-align consistently across URL / Post-Page / Media (was bottom-aligned, which broke when field heights differed)

= 0.1.6 =
* New: search by QR serial number — "SN:000001", "000001", or the plain ID all resolve to the link
* New: serial number shown in the links list (under the short URL)

= 0.1.5 =
* Change: Markdown export now opens a copy-to-clipboard viewer instead of downloading a file (downloads could stall as .crdownload)
* Fix: icon/text alignment in pill buttons

= 0.1.4 =
* Fix: serial number on QR downloads was invisible (GD colors were allocated on the source palette image — black bar with black text)
* Fix: save errors were hidden behind the modal — errors now show inside the modal
* New: search box on the links list (matches slug, redirect URL, and memo; uses plugin-prefixed `hxsr_s` param)
* Style: Add Schedule form realigned (labels above fields, baseline-aligned row)

= 0.1.3 =
* Style: admin UI redesigned with the HX Series token system (HXRV-style CSS custom properties, indigo brand color)
* Style: segmented control for redirect type, dashicons instead of emoji, x-cloak to prevent modal flash

= 0.1.2 =
* Fix: fatal error when rendering the link list after saving a link (leftover variable from template refactor)

= 0.1.1 =
* Fix: admin screen was blank — Alpine.js initialized before the component was defined (script loading order)
* Change: moved to a top-level admin menu (dashicons-randomize)
* Change: removed unused bundled htmx (admin uses fetch, visitors load zero JS)

= 0.1.0 =
* Initial release

== Upgrade Notice ==

= 0.1.0 =
Initial release.
