Operational Integrations – WordPress Attendance Sync
This integration enables one-way synchronization of event attendance data into external WordPress sites. Editorial or marketing teams can consume up-to-date attendee and team rosters via a custom WP REST endpoint.
🔍 Overview
- Provides an artisan command (
app:notify-attendance) to push attendance for specific, upcoming, or all events. - Listens to internal signup events (
AttendeeCreated,EventTeamCreated) and batches exports. - Uses an export service to shape data and a WordPress integration to deliver JSON payloads.
📦 Components
| Component | Role | File / Location |
|---|---|---|
| NotifyAttendance (Artisan Command) | Entry point. Filters events, invokes sync. | app/Console/Commands/NotifyAttendance.php |
| NotifyWordpressOfAttendance (Listener) | Handles signup events, formats and sends data. | app/Listeners/NotifyWordpressOfAttendance.php (listens to AttendeeCreated, EventTeamCreated) |
| EventSignupExportService | Extracts attendee or team data; maps players to payload arrays. | app/Services/EventSignupExportService.php |
| Wordpress (Integration) | Builds WP API URL, authenticates, issues HTTP POST to /pn/v1/attendance. |
app/Integrations/Wordpress.php |
| Configuration | WP credentials and env under config/services.php:wordpress. |
config/services.php |
⚙️ Workflow
flowchart TD
A[Artisan: app:notify-attendance] --> B[Query Events<br/>(by --event, --site, --upcoming)]
B --> C[Instantiate EventSignupExportService]
C --> D[Wordpress::sendToWordpress]
D --> E[POST to {site_url}/wp-json/pn/v1/attendance]
- Command filters events via Eloquent.
- Service exports raw attendee or team‐player data arrays.
- Integration builds endpoint from
Website->url+/pn/v1/attendanceand sends HTTP POST. - Listener also triggers on live signup/team events for real-time sync.
🛠 NotifyAttendance Command
protected $signature = '
app:notify-attendance
{--event= : Event ID to push}
{--site= : WP site ID to filter by}
{--upcoming : Only upcoming events}
';
protected $description = 'Force push event attendance to WordPress';
- Filtering: by event ID, WordPress site ID, or upcoming events only.
- Execution: loops each event, logs progress, handles exceptions (Sentry capture).
- Example:
php artisan app:notify-attendance --site=2 --upcoming
📋 NotifyWordpressOfAttendance Listener
Listens for:
- AttendeeCreated → sends individual signup.
- EventTeamCreated / updated → sends full roster for tournament events.
Key behaviors (tested in NotifyWordpressOfAttendanceTest):
- Sends only when an event and WP site exist.
- Handles both “showcase” vs. “tournament” logic.
- Normalizes URLs with/without trailing slash.
- Continues on HTTP failures (no exceptions bubble up).
🔧 EventSignupExportService
public function export(Event $event): array
{
if ($event->isShowcase()) return $this->exportAttendees($event);
if ($event->isTournament()) return $this->exportTeams($event);
return [];
}
- exportAttendees: queries
Attendeewithplayerrelationship, maps each tomapPlayerData. - exportTeams: for tournaments, flattens each
EventTeam→ team players. - mapPlayerData builds payload fields:
return [
'player_id' => $player->id,
'wordpress_id' => $player->wordpress_id,
'class' => $this->getClassesFromEventAges($event),
'state' => $event->address_state ?? null,
'first_name' => $player->first_name,
'last_name' => $player->last_name,
'team_name' => $player->team?->name,
'event_id' => $event->id,
'event_name' => $event->title,
'event_date' => $event->start_date->toDateString(),
'city' => $event->address_city,
// …additional context as needed
];
🔐 Configuration
| Key | Description | Default / Env Variable |
|---|---|---|
services.wordpress.env |
WP env (local/staging/production) | WORDPRESS_ENV / APP_ENV |
services.wordpress.user |
WP REST user | WORDPRESS_USER |
services.wordpress.password |
WP REST password | WORDPRESS_PASSWORD |
📦 Example Payload
{
"event_id": 42,
"attendees": [
{
"player_id": 101,
"wordpress_id": 5001,
"class": ["2025", "2026"],
"state": "CA",
"first_name": "Alice",
"last_name": "Smith",
"team_name": "Eagles",
"event_name": "West Showcase",
"event_date": "2025-06-15",
"city": "San Diego"
},
{ /* …more records… */ }
]
}
🧪 Testing & Quality
- Feature Tests in
tests/Feature/Listeners/NotifyWordpressOfAttendanceTest.phpcover:- Attendee and team events for both event types.
- URL normalization (with/without trailing slash).
- HTTP failure resilience.
- Command Tests not yet implemented but follow similar patterns.
💡 Tip: Schedule the artisan command via cron or pipeline in your Ops tool, passing
--upcomingnightly to keep all WP sites in sync.