Admin
Live Theme Preview
Browse any installed theme without activating it or touching settings.json. Works entirely via a signed token in the URL.
How it works
- Admin clicks "Live Preview" in the theme manager.
admin/theme-preview.php(GET?theme=themename):
- Verifies the theme exists.
- Derives an HMAC secret from the bcrypt hash of the stored password.
- Builds a signed token: base64url(themeName + "|" + Unix timestamp + "|" + HMAC-SHA256).
- Redirects to the site root with ?_tp=TOKEN.
index.php→loadSettings(): if?_tpis present and$_SESSION['admin'] === true, the token is decoded and verified (HMAC + 2-hour TTL). If valid,active_themeis overridden for this request only —settings.jsonis never modified.
- All internal
hreflinks are rewritten in JS to append?_tp=TOKEN. AMutationObserverwatches for dynamically added links.
- Closing the preview tab removes the token.
Security
- HMAC-SHA256 signed token, 2-hour TTL
- Only works when
$_SESSION['admin'] === true basename()applied to the theme name (path traversal prevention)
Files involved
| File | Role |
|---|---|
admin/theme-preview.php | Token generator + redirector |
functions.php → loadSettings() | Token validator + theme override |
index.php | Preview banner + JS link rewriting |
admin/templates/theme-manager.php | "Live Preview" button + openThemePreview() JS |
