T-Work FCM Notify
π WordPress plugin: Firebase Cloud Messaging (FCM) + WooCommerce order push notifications for mobile commerce apps
by T-Work System Β· github.com/tworksystem/twork-fcm-notify Β· website
Install
No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:
wp plugin install https://github.com/tworksystem/twork-fcm-notify/archive/refs/heads/main.zipπ A production-ready WordPress plugin that connects Firebase Cloud Messaging (FCM) with WooCommerce to deliver real-time push notifications when order statuses change β built for mobile commerce apps (Flutter, React Native, native Android/iOS).
π Table of Contents
- Overview
- Features
- Architecture
- Requirements
- Installation
- Configuration
- REST API Reference
- Notification Behavior
- Mobile App Integration
- Security
- Debugging & Troubleshooting
- Development
- Contributing
- Changelog
- License
- Support
π Overview
T-Work FCM Notify bridges your WordPress/WooCommerce backend and mobile clients through Firebase Cloud Messaging. It provides:
- π Secure device token registration via WordPress REST API
- π¦ Automatic push notifications on WooCommerce order status transitions
- π€ Cross-platform delivery (Android & iOS) using FCM HTTP v1
- π§© Stable
datapayload keys for mobile app routing and deep linking
Ideal for T-Work Commerce, MingalarBuy, and similar WooCommerce-powered mobile storefronts.
β¨ Features
| Feature | Description |
|---|---|
| π REST API | Register, update, and manage FCM device tokens per WordPress user |
| π WooCommerce Hooks | Sends notifications automatically on woocommerce_order_status_changed |
| π² Multi-Device Support | Up to 10 tokens per user with platform-aware deduplication |
| π FCM HTTP v1 | Modern Firebase API with OAuth2 service-account authentication |
| π CamelCase Payloads | Preserves mobile-friendly keys (userId, orderId, currentBalance) |
| π‘οΈ Security Hardening | Input sanitization, token validation, masked debug output |
| π Silent Suppression | Optional per-request FCM skip for admin bulk saves |
| π Debug Endpoints | Inspect registered tokens during development (masked) |
π Architecture
flowchart LR
subgraph Mobile["π± Mobile App"]
A[FCM SDK]
end
subgraph WordPress["π WordPress + WooCommerce"]
B[REST: /register-token]
C[User Meta: twork_fcm_tokens]
D[Order Status Hook]
E[twork_send_fcm]
end
subgraph Firebase["π₯ Firebase"]
F[OAuth2 Token]
G[FCM HTTP v1 API]
end
A -->|POST token| B
B --> C
D -->|status change| E
E --> F
F --> G
G -->|push| A
π Plugin Structure
twork-fcm-notify/
βββ twork-fcm-notify.php # Main plugin bootstrap & logic
βββ serviceAccountKey.json.example
βββ .gitignore
βββ LICENSE
βββ README.md
β οΈ
serviceAccountKey.jsonis never committed. Copy from the example file locally.
π Requirements
| Dependency | Minimum Version |
|---|---|
| WordPress | 5.0+ |
| WooCommerce | 3.0+ |
| PHP | 7.4+ (OpenSSL extension required) |
| Firebase Project | FCM enabled + Service Account JSON |
π¦ Installation
1οΈβ£ Clone the Repository
cd wp-content/plugins
git clone https://github.com/tworksystem/twork-fcm-notify.git
cd twork-fcm-notify
2οΈβ£ Configure Firebase Credentials
- Open Firebase Console π₯
- Select your project (or create one)
- Go to Project Settings β Service accounts
- Click Generate new private key
- Save the downloaded JSON as
serviceAccountKey.jsonin this plugin folder
cp serviceAccountKey.json.example serviceAccountKey.json
# Edit serviceAccountKey.json with your real Firebase credentials
chmod 600 serviceAccountKey.json
3οΈβ£ Set Firebase Project ID
Edit twork-fcm-notify.php:
define('TWORK_FCM_PROJECT_ID', 'your-firebase-project-id');
4οΈβ£ Activate in WordPress
- Go to WordPress Admin β Plugins
- Find T-Work FCM Notify
- Click Activate β
βοΈ Configuration
| Constant | Description | Default |
|---|---|---|
TWORK_FCM_PROJECT_ID |
Firebase project ID | Must be set manually |
TWORK_FCM_SERVICE_ACCOUNT_JSON |
Path to service account JSON | __DIR__ . '/serviceAccountKey.json' |
π Suppress FCM for a Single Request
When saving admin forms (e.g. Engagement Hub bulk updates), POST:
twork_skip_fcm_notify=1
This prevents notification storms during backend edits.
π‘ REST API Reference
Base URL: https://your-site.com/wp-json/twork/v1
π Register / Update FCM Token
POST /register-token
Registers or refreshes a device token for a WordPress user.
Request Body
{
"userId": "123",
"fcmToken": "dP0X4xGxR5y3z8vW2mN6kL9hJ...",
"platform": "android"
}
| Field | Type | Required | Notes |
|---|---|---|---|
userId |
string/int | β | Valid WordPress user ID |
fcmToken |
string | β | FCM registration token (min 10 chars) |
platform |
string | β | android or ios (default: android) |
Success β 200 OK
{
"success": true,
"tokenCount": 2,
"platform": "android"
}
Error β 400 Bad Request
{
"success": false,
"error": "userId and fcmToken required"
}
cURL Example
curl -X POST "https://your-site.com/wp-json/twork/v1/register-token" \
-H "Content-Type: application/json" \
-d '{"userId":"123","fcmToken":"YOUR_FCM_TOKEN","platform":"ios"}'
π Debug: List User Tokens
GET /debug/tokens/{user_id}
Returns masked tokens for development. Restrict or disable in production.
Success β 200 OK
{
"userId": 123,
"tokenCount": 1,
"tokens": [
{
"token": "dP0X4xGxR5y3z8vW2mN6kL9hJ...",
"platform": "android",
"updated_at": 1716508800
}
]
}
π Notification Behavior
Triggered on WooCommerce order status changes for logged-in customers with registered tokens.
| Status | Notification Title Pattern |
|---|---|
pending |
Order #123 is being processed |
processing |
Order #123 is being prepared |
on-hold |
Order #123 is on hold |
completed |
Order #123 has been completed |
cancelled |
Order #123 has been cancelled |
refunded |
Order #123 has been refunded |
failed |
Order #123 payment failed |
shipped |
Order #123 has been shipped |
π¦ Data Payload
Every notification includes a data map (all values are strings per FCM spec):
{
"orderId": "123",
"status": "completed",
"total": "99.99",
"currency": "USD",
"type": "order_status_update",
"userId": "456",
"user_id": "456"
}
Mobile apps should route on type and status for deep linking (e.g. open Order Details screen).
π± Mobile App Integration
Recommended Flow
- π² Obtain FCM token in the mobile app after login
- π
POST /register-tokenwith WordPress user ID - π Handle foreground/background notification callbacks
- π§ Parse
data.typeand navigate accordingly
Flutter Example (pseudo-code)
final token = await FirebaseMessaging.instance.getToken();
await http.post(
Uri.parse('$baseUrl/wp-json/twork/v1/register-token'),
headers: {'Content-Type': 'application/json'},
body: jsonEncode({
'userId': userId.toString(),
'fcmToken': token,
'platform': Platform.isIOS ? 'ios' : 'android',
}),
);
π‘ Re-register the token on app launch and whenever Firebase refreshes it.
π‘ Security
β Built-In Protections
- WordPress sanitization on all REST inputs
- User existence validation before token storage
- Platform whitelist (
android/ios) - Token deduplication and 10-token cap per user
- Service account file permission warnings in logs
- Masked tokens in debug responses
β οΈ Critical Practices
| Rule | Why |
|---|---|
π« Never commit serviceAccountKey.json |
Contains private Firebase credentials |
π chmod 600 serviceAccountKey.json |
Prevents world-readable secrets |
| π Rotate keys if ever exposed | Invalidate compromised service accounts |
| π Disable debug routes in production | Prevents token enumeration |
| π Add auth to REST routes in production | Current routes use open callbacks β wrap with JWT/app auth |
Credential Rotation
If a key was leaked:
- Firebase Console β Service Accounts β delete old key
- Generate a new private key
- Replace
serviceAccountKey.json - Test push delivery end-to-end
π Debugging & Troubleshooting
Enable WordPress Debug Logging
Add to wp-config.php:
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);
Logs: wp-content/debug.log β search for [T-Work FCM].
Common Issues
| Symptom | Likely Cause | Fix |
|---|---|---|
| π΅ No push received | Missing/invalid service account | Verify JSON path & project ID |
| π΄ HTTP 401 from FCM | Bad private key or clock skew | Regenerate key; check server time |
| πΎ Tokens not saved | Invalid userId |
Confirm user exists in WP |
| π± App ignores data | Key casing broken | This plugin preserves camelCase keys |
| π Admin save floods devices | Bulk meta updates | Use twork_skip_fcm_notify=1 |
π§βπ» Development
Key Functions
| Function | Purpose |
|---|---|
twork_register_fcm_token() |
REST handler for token registration |
twork_send_fcm() |
Sends FCM v1 message to a device token |
twork_get_access_token_from_sa() |
OAuth2 JWT exchange with Google |
twork_status_message() |
Maps WooCommerce status to user-facing text |
WordPress Hooks
rest_api_initβ registers REST routeswoocommerce_order_status_changedβ triggers order notifications
π€ Contributing
Contributions are welcome! π See CONTRIBUTING.md for setup, code standards, and PR guidelines.
- π΄ Fork the repository
- πΏ Create a feature branch:
git checkout -b feat/your-feature - β Commit with the convention below
- π€ Push and open a Pull Request
π Commit Message Convention
<type>: 24052026 - <professional description in imperative mood>
| Type | When to Use |
|---|---|
feat |
β¨ New feature or enhancement |
fix |
π Bug fix |
docs |
π Documentation only |
style |
π Formatting, no logic change |
refactor |
β»οΈ Code restructure, same behavior |
perf |
β‘ Performance improvement |
test |
β Tests added or updated |
chore |
π§ Tooling, deps, maintenance |
ci |
π· CI/CD changes |
Examples
feat: 24052026 - add FCM token registration REST endpoint
fix: 24052026 - preserve camelCase keys in FCM data payload
docs: 24052026 - expand mobile integration guide in README
π Changelog
π 24 May 2026
- β¨ Published repository under tworksystem/twork-fcm-notify
- π Comprehensive README with architecture, API, and security guides
- π FCM data payload preserves camelCase keys for Flutter/mobile clients
- π Added silent FCM suppression flag for admin bulk operations
π Earlier Releases
- π WooCommerce order status push notifications
- π Service-account based FCM HTTP v1 authentication
- π² Multi-platform token storage with deduplication
π License
MIT License β see LICENSE.
Copyright (c) 2025β2026 T-Work System & contributors.
π¬ Support
- π Open an Issue
- π Firebase Cloud Messaging Docs
- π WooCommerce Developer Docs
- π WordPress Plugin Handbook
Version: 1.0.0 Β· Last Updated: 24 May 2026 Β· Made with β€οΈ for mobile commerce