Endpoint & Routing
Developer reference
This page documents the rewrite rules + router internals. Useful when adding custom views or debugging URL-resolution. Admins and store owners can skip — the URL structure works automatically.
How URLs map to views inside /wallet-central/.
Rewrite Rules
Registered on init by WKWP_Central_Endpoint::register_rewrite(). Four rules, top-priority:
^wallet-central/?$
→ index.php?wkwp_central=1
^wallet-central/([a-z0-9_-]+)/?$
→ index.php?wkwp_central=1&wcc=$1
^wallet-central/([a-z0-9_-]+)/([a-z0-9_-]+)/?$
→ index.php?wkwp_central=1&wcc=$1&wcc_sub=$2
^wallet-central/([a-z0-9_-]+)/([a-z0-9_-]+)/([0-9]+)/?$
→ index.php?wkwp_central=1&wcc=$1&wcc_sub=$2&wcc_id=$3
Auto-flushes once on activation via wkwp_central_rewrite_flushed_v3 option.
Query Vars
| Var | Source | Purpose |
|---|---|---|
wkwp_central | flag | "1" → endpoint render takes over |
wcc | path segment 1 | view slug |
wcc_sub | path segment 2 | sub-action (e.g. view, mode) |
wcc_id | path segment 3 | numeric ID (e.g. withdrawal row id) |
Whitelisted via query_vars filter so get_query_var() reads cleanly.
Allowed Views
home, transactions, send, withdraw,
withdrawals, withdrawal-detail, add-to-wallet,
requests, qr, referral, settings, kyc
Resolved by WKWP_Central_Router::resolve(). Unknown slugs fall back to home — no 404.
URL → View Examples
| URL | Resolves to |
|---|---|
/wallet-central/ | home |
/wallet-central/transactions/ | transactions |
/wallet-central/withdraw/ | withdraw |
/wallet-central/withdrawals/ | withdrawals |
/wallet-central/withdrawals/view/123/ | withdrawal-detail (special-case in router) |
/wallet-central/qr/?mode=mine | qr |
/wallet-central/qr/?mode=scan | qr |
/wallet-central/foo/ | home (fallback) |
Special-Case: withdrawal-detail
The router merges three URL segments into one view:
if ( 'withdrawals' === $raw && 'view' === $sub && $id > 0 ) {
return 'withdrawal-detail';
}
Means /wallet-central/withdrawals/view/123/ resolves to the withdrawal-detail view with wcc_id = 123. The detail view reads the ID via get_query_var( 'wcc_id' ).
Building URLs Programmatically
Use the helper instead of hand-concatenating paths:
$home = WKWP_Central_Router::url(); // /wallet-central/
$txns = WKWP_Central_Router::url( 'transactions' ); // /wallet-central/transactions/
$qrs = WKWP_Central_Router::url( 'qr', [ 'mode' => 'scan' ] ); // /wallet-central/qr/?mode=scan
$wdraw = WKWP_Central_Endpoint::url( 'withdrawals/view/123' ); // /wallet-central/withdrawals/view/123/
Helpers honour the multisite-aware base URL via home_url().
Template Render
Endpoint hooks template_redirect priority 1. When wkwp_central=1 query var set:
- Run auth check — anon →
wp_safe_redirect( wp_login_url( current_url ) ) - Resolve view via router
- Boot
WKWP_Central_Renderer - Output own minimal HTML document via
templates/index.php+templates/chrome.php exit— bypasses theme entirely
Theme Bypass
The templates/index.php writes a complete <!doctype html> document — no wp_head(), no theme stylesheet. Just:
- Wallet Central CSS/JS bundles via
wp_print_styles()/wp_print_scripts()for the registered handles - Minimal favicon via
wp_site_icon() - Body class
wcc-body - Root mount
<div class="wcc-root">…</div>
Themes are completely out of the way. Customizers, page builders, third-party header / footer hooks all skipped.
Cache Headers
| Header | Value |
|---|---|
Cache-Control | no-store, no-cache, must-revalidate, max-age=0 |
Pragma | no-cache |
Expires | 0 |
Wallet UI is per-user and balance-sensitive. Page is never cached at the HTTP layer.
CDN / page-cache plugins should bypass the URL pattern /wallet-central/*. Same rule that applies to /my-account/*.
Multisite
Each blog gets its own /wallet-central/ path. Auth + balance read are per-blog (per-blog wallet tables). Cross-blog navigation is blocked — each blog is an independent wallet store.
Title Map
WKWP_Central_Router::titles() provides the i18n title for each view, used by:
<title>tag in the chrome- Tab strip in the side rail
- Breadcrumbs
home → Wallet
transactions → Transactions
send → Send money
withdraw → Withdraw
withdrawals → Withdrawal requests
withdrawal-detail → Withdrawal detail
add-to-wallet → Add to wallet
requests → Payment requests
qr → QR Pay
referral → Refer & earn
settings → Settings
kyc → KYC verification
All passed through WPML / Polylang string registry.
Hooks
| Hook | Type | Args | When |
|---|---|---|---|
wkwp_central_views | filter | ( array $views ) | extend allowed view list |
wkwp_central_view_resolve | filter | ( string $resolved, string $raw ) | swap final view |
wkwp_central_view_titles | filter | ( array $titles ) | rename / translate titles |
wkwp_central_endpoint_redirect_url | filter | ( string $url ) | mutate the anon redirect target |
wkwp_central_endpoint_send_headers | action | () | inject extra HTTP headers before render |
Add a Custom View
// 1. Allow the slug
add_filter( 'wkwp_central_views', function( $views ) {
$views[] = 'rewards';
return $views;
} );
// 2. Title
add_filter( 'wkwp_central_view_titles', function( $titles ) {
$titles['rewards'] = __( 'Rewards', 'mytheme' );
return $titles;
} );
// 3. Render
add_action( 'wkwp_central_render_view', function( $view ) {
if ( 'rewards' !== $view ) return;
echo '<div class="wcc-h1">My rewards</div>';
} );
Now /wallet-central/rewards/ works.
Troubleshooting
| Problem | Fix |
|---|---|
/wallet-central/ 404s | Flush rewrite — Settings → Permalinks → Save |
| Sub-view always shows home | Slug not in Router::VIEWS; add via wkwp_central_views filter |
| Anon visit not redirected | Theme is intercepting template_redirect first; raise its priority above 1 |
| Detail page shows the list | Router pattern requires withdrawals/view/{id} — confirm trailing slash or query string |
