$name, 'timestamp' => Helper::now_iso(), 'site' => wp_parse_url( home_url(), PHP_URL_HOST ), ], $payload ); /** * Mirror the viewer's contact fields to the top level. * * `subject` stays exactly as it was (nothing here is removed), but most * receivers — CRMs, Zapier, Make — map a flat `email` and reject a * payload that only nests it. Promoting them here covers every emit * site at once instead of each caller remembering to do it. */ foreach ( [ 'email', 'name' ] as $field ) { if ( ! isset( $payload[ $field ] ) && ! empty( $payload['subject'][ $field ] ) ) { $payload[ $field ] = $payload['subject'][ $field ]; } } return $payload; } public static function emit( $name, array $payload = [] ) { $payload = self::shape( $name, $payload ); /** * Generic hook (all events) + specific hook (per event name). */ do_action( 'trueplayer/event', $name, $payload ); do_action( "trueplayer/event/{$name}", $payload ); } }