Skip to main content

flexweg-metrics

flexweg-metrics adds two cards to the admin dashboard:

  • Flexweg storage usage — bytes used / plan limit, with an upgrade CTA when usage crosses 80 %.
  • Firestore document counts — posts (online vs draft), pages, terms, media, users.

It's must-use because the storage card is the only proactive nudge to upgrade the Flexweg plan before hitting the wall mid-publish (a hit-the-wall failure manifests as 413 errors mid-upload, with partial-state cleanup that's hard to recover from).

What you see on the dashboard

Below the four built-in stat cards (Posts / Pages / Categories / Tags), the plugin contributes a second row:

Storage card

  • Used — current /files/storage-limits total in MB.
  • Limit — Flexweg plan limit in MB.
  • Progress bar — visual fill, turns amber at 70 %, red at 90 %.
  • Upgrade button — appears at ≥ 80 %, links to your Flexweg billing page.
  • Refresh — manual re-fetch button (no polling — re-mounting the dashboard via navigation is the expected refresh trigger).

Firestore card

  • Postsonline count + draft count (two parallel getCountFromServer queries).
  • Pages — same, posts vs draft.
  • Terms — single count.
  • Media — single count.
  • Users — single count (admins only see this; editors see N/A).

All counts use Firestore's count aggregation queries — single-read each, no documents fetched.

How it hooks in

api.registerDashboardCard({ id: "flexweg-metrics/storage", priority: 10, component: StorageCard });
api.registerDashboardCard({ id: "flexweg-metrics/firestore", priority: 20, component: FirestoreCard });

Two cards, two registrations. Each card is a self-contained React component that fetches its own data on mount and manages its own loading / error / empty states.

Refresh model

Cards do not poll. The dashboard re-mounts on navigation away/back, which is the expected refresh trigger. The Storage card additionally has a manual refresh button for the case where you want to re-check after a large upload without leaving the dashboard.

Toggle

Disabling the plugin (in code, since it's MU and has no UI toggle) would remove both cards from the dashboard. The dashboard would still render — it has no other dependencies on the cards.

Internal details

  • Source: src/mu-plugins/flexweg-metrics/
  • Hooks used: 2 registerDashboardCard registrations
  • API calls: /files/storage-limits (Flexweg) + getCountFromServer aggregation queries (Firestore)
  • Translations: 7 locales

Continue