$body['usage'], 'plan' => $body['plan'] ?? ( $body['usage']['tier'] ?? null ), 'at' => time(), // Which key this plan was reported FOR (LK1). A snapshot taken under a // different key says nothing about the one saved now. 'key_fp' => altorewrite_shared_key_fingerprint( $slug ), // QW1. The backend refused this request for quota. Recorded HERE, the one // writer every path reaches, because the automatic paths (publish, upload, // save) discard their errors and this is the only trace they leave. The // next successful generation overwrites it, which is what clears the wall. 'refused' => 'quota' === ( $body['code'] ?? '' ), ), false ); } } if ( ! function_exists( 'altorewrite_shared_usage_state' ) ) { /** * What the cached snapshot says about this site's plan and allowance. * * The ONE place the snapshot is interpreted. The usage panel and the QW1 quota * notices both read it, and a second copy of the LK1 rule is exactly how AltoScribe * ended up reading "Not confirmed yet" forever (AS1). * * LK1. A saved key is NOT a working key, and these three states were previously * collapsed into one test on whether the box was empty: the panel said "Pro" for a * key the backend has never seen, and hid the upgrade button for a key it had seen * and REJECTED. `isProKey` (ruac-backend db.js) returns false for any key it does * not hold as an active pro licence, so a typo silently bought the free allowance * while the panel congratulated the user on Pro. Found 2026-09-24 by Simon, who * noticed a wrong key made the upgrade button disappear. * * The snapshot is the only evidence we have of what the backend thinks, so the * three states are named rather than guessed: * paid - the last generation came back on a paid plan * unrecognised - a key IS saved and the last generation came back free * unconfirmed - a key IS saved and nothing has been generated yet * A snapshot only speaks for the key it was taken under, so one taken before the * user pasted a new key is treated as no evidence at all rather than as a verdict * on the key saved now. * * @param string $slug The calling plugin's slug. * @param bool $has_key Whether a licence key is saved. * @return array { * @type mixed $plan Raw plan from the snapshot, or null. * @type array|null $usage Raw usage block, or null. * @type int|null $allow Monthly allowance, or null when unknown. * @type int|null $used Used this period, or null when unknown. * @type bool $paid Last generation came back on a paid plan. * @type bool $unrecognised A saved key came back free. * @type bool $unconfirmed A saved key has not been checked yet. * @type bool $walled Refused for quota THIS calendar month (UTC, the * backend's period), under the key saved now. * } */ function altorewrite_shared_usage_state( $slug, $has_key ) { $snap = get_option( $slug . '_last_usage', null ); $plan = is_array( $snap ) ? ( $snap['plan'] ?? null ) : null; $usage = ( is_array( $snap ) && isset( $snap['usage'] ) && is_array( $snap['usage'] ) ) ? $snap['usage'] : null; // `allowance` is AltoScribe's tiered field, `limit` the flat one; prefer // allowance so this file serves both without branching at the call site. $allow = null; if ( $usage ) { if ( isset( $usage['allowance'] ) ) { $allow = (int) $usage['allowance']; } elseif ( isset( $usage['limit'] ) ) { $allow = (int) $usage['limit']; } } $snap_fp = is_array( $snap ) ? (string) ( $snap['key_fp'] ?? '' ) : ''; $stale_key = ( $snap_fp !== altorewrite_shared_key_fingerprint( $slug ) ); $plan_name = ( $has_key && $stale_key ) ? '' : strtolower( trim( (string) $plan ) ); // The backend meters by UTC calendar month (ruac-backend config.js `period`), so a // refusal from an earlier month says nothing about this one. A stale key also clears // it: the user has done the one thing that could have changed the answer. $at = is_array( $snap ) ? (int) ( $snap['at'] ?? 0 ) : 0; $walled = is_array( $snap ) && ! empty( $snap['refused'] ) && ! $stale_key && gmdate( 'Y-m', $at ) === gmdate( 'Y-m' ); return array( 'plan' => $plan, 'usage' => $usage, 'allow' => $allow, 'used' => ( $usage && isset( $usage['used'] ) ) ? (int) $usage['used'] : null, 'paid' => ( '' !== $plan_name && 'free' !== $plan_name ), 'unrecognised' => ( $has_key && 'free' === $plan_name ), 'unconfirmed' => ( $has_key && '' === $plan_name ), 'walled' => $walled, ); } } if ( ! function_exists( 'altorewrite_shared_usage_panel' ) ) { /** * Render the "your usage this month" card, with an upgrade CTA. * * Shown on the plugin's own settings page. Before the first generation * there is no snapshot, so the card states the free allowance instead of * rendering an empty meter — a 0/0 bar reads as broken rather than unused. * * @param string $slug The calling plugin's slug (e.g. 'altosum'). * @param string $display_name Display name (e.g. 'AltoSum'). * @param string $noun Plural noun for the metered unit (e.g. 'summaries'). * @param int $free_limit Free monthly allowance, for the pre-first-run case. * @param bool $has_key Whether a licence key is saved, for the plan label. * @param string $paid_cta Optional label for a CTA shown even to a licensed user. * AltoScribe needs one because a paying customer can still buy * credits; the flat-tier plugins have nothing to sell a Pro user, * so they leave it empty and only the free-tier upsell renders. * This parameter exists so there stays ONE usage panel: AltoScribe * previously carried a private duplicate of this whole function, * which is how two implementations of one rule start to drift. * @return void */ function altorewrite_shared_usage_panel( $slug, $display_name, $noun, $free_limit, $has_key, $paid_cta = '' ) { $state = altorewrite_shared_usage_state( $slug, $has_key ); $plan = $state['plan']; $usage = $state['usage']; $allow = $state['allow']; $paid = $state['paid']; $unrecognised = $state['unrecognised']; $unconfirmed = $state['unconfirmed']; if ( $paid ) { $plan_label = ucfirst( (string) $plan ); } elseif ( $unconfirmed ) { $plan_label = 'Not confirmed yet'; } else { $plan_label = 'Free'; } ?>

Your usage

Plan: ·

ⓘ The licence key saved in Settings was not recognised, so this site is on the free plan. Check it for a typo, and that it is the key for .

Your licence key is checked the first time you generate, and your plan appears here after that.

0 ? min( 100, (int) round( $used / $allow * 100 ) ) : 0; ?>

This month: used 0 ) : ?> · credits available

As of your last generation. The service is the source of truth.

This month:

As of your last generation. The service is the source of truth.

Your usage this month will appear here after your first generation.

Upgrade to Pro