$entries Stored values. */ public function on_submission_created( int $submission_id, int $form_id, array $entries ): void { $form = $this->forms->find( $form_id ); if ( ! $form instanceof Form ) { return; } $values = array(); foreach ( $entries as $entry ) { $key = (string) ( $entry['key'] ?? '' ); if ( '' === $key ) { continue; } $values[ $key ] = $entry['value'] ?? ''; } $notifications = $this->builder->build( $form, $this->fields->for_form( $form_id ), $values, $submission_id ); foreach ( $notifications as $notification ) { if ( ! $notification instanceof Notification ) { continue; } $this->queue()->push( $notification ); } } /** * Delivers the notifications waiting in the cron queue. * * Always the cron queue, whatever {@see Notifier::queue()} settled on: this * runs to drain notifications that were *stored* earlier, and those are in * the option whether or not the site still defers delivery. * * Hooked to {@see CronQueue::HOOK}. */ public function process_queue(): void { $this->cron->process(); } /** * Returns the queue notifications are handed to. * * Resolved once, on first use rather than at construction, so a site can * still register the filter below on `init` or on a late `plugins_loaded`. */ public function queue(): NotificationQueue { if ( $this->queue instanceof NotificationQueue ) { return $this->queue; } $default = 'cron' === Settings::text( 'queue' ) ? $this->cron : $this->immediate; /** * Filters the queue notifications are delivered through. * * Return a {@see CronQueue} to move delivery out of the submission * request, or any other implementation of the interface to hand mail to * Action Scheduler or an external worker. * * @since 1.0.0 * * @param NotificationQueue $queue Delivery queue. */ $queue = apply_filters( 'formpilot_notification_queue', $default ); $this->queue = $queue instanceof NotificationQueue ? $queue : $default; return $this->queue; } }