Spin Wheel

⌘K
  1. Home
  2. Spin Wheel
  3. Hooks & Filters (Deve...
  4. After email send attempt (uspw_email_sent_result)

After email send attempt (uspw_email_sent_result)

After Email Send Attempt (uspw_email_sent_result)

The uspw_email_sent_result action fires immediately after Ultimate Spin Wheel attempts to send a winner’s reward email, passing the boolean result of wp_mail(). Use it to log delivery outcomes, implement retry logic, or trigger fallback notifications. It is an action hook (return value is ignored) and has existed since version 1.0.0.

Important (Pro required): Like every uspw_* developer hook, this action only fires when the separate Ultimate Spin Wheel Pro plugin is active. In the free plugin the entire hook is wrapped in apply_filters( 'ultimate_spin_wheel_pro_init', false ), so your callback will never run on a free-only site. The winner email itself is still sent in free — only the hook is gated.

When It Fires

The action runs inside the entry-save routine in class-spin-wheel.php, but only after several conditions are all met:

  • The Pro plugin is active (ultimate_spin_wheel_pro_init is true).
  • The spin result is a win (status === 'won') and both an email address and a coupon code are present.
  • The campaign’s Behavior settings have coupon email delivery enabled (emailDelivery === 'yes'). If email delivery is off, no send is attempted and the hook does not fire.

The $email_sent value is whatever wp_mail() returned. It is also false when the uspw_before_send_winner_email filter blanks the to address to deliberately skip a send.

Parameters

Register with add_action( 'uspw_email_sent_result', 'my_handler', 10, 3 ). Your callback receives three arguments:

  • bool $email_sent — whether wp_mail() accepted the message (handoff to the mail server, not proof of inbox delivery).
  • array $data — the entry data for this lead (see fields below).
  • int $campaign_id — the ID of the spin wheel campaign.

What Is Inside $data

The $data array is the saved entry record. Its top-level keys are campaign_id, campaign_title, name, email, phone, campaign_type, user_data, and others_data.

  • The coupon code and title are not top-level keys. They live inside $data['others_data'], a JSON string. Decode it with json_decode( $data['others_data'], true ) to read coupon_code, coupon_title, status, and phone.
  • user_data is also a JSON string holding ip_address, device_id, and user_agent.
  • $data['phone'] is only populated when the phone input field was captured, which is a Pro feature. On many sites it will be empty.

Common Use Cases

Log Delivery Status

Insert a row into your own log table with the campaign ID, recipient, and a sent/failed status derived from $email_sent. Because the hook also passes the full entry, you can store the recipient email from $data['email'] and pull the coupon code out of the decoded others_data. Track a per-campaign failure counter (for example with a transient) and alert the admin when failures spike.

Retry Failed Sends

When $email_sent is false, schedule a retry with wp_schedule_single_event() using an exponential backoff, capping the number of attempts (for example three) via a transient keyed on the email and campaign. In your retry handler, resend with wp_mail() and re-fire do_action( 'uspw_email_sent_result', $sent, $data, $campaign_id ) so the same logging path applies. After the final attempt, notify the admin to contact the winner manually.

SMS Fallback

If email delivery fails and a phone number is available, send the coupon by SMS through a provider such as Twilio via wp_remote_post(). Guard the callback so it exits early when $email_sent is true or $data['phone'] is empty. Remember that phone capture requires the Pro phone input field, so this path is only reachable on Pro sites that collect a number.

Track Metrics or Sync a CRM

On a successful send, generate a tracking ID and store a metrics row, then schedule a later check for opens/clicks. Or push the delivery status into a CRM such as HubSpot with wp_remote_post() — updating a contact by $data['email'] and, on failure, creating a follow-up task for your team. These are ordinary integrations built entirely from the three hook arguments; they are not built-in plugin features.

Notes

  • The hook fires right after wp_mail(), with the boolean result — success here means the message was handed to the mail server, not that it reached an inbox.
  • For true delivery, open, and click tracking, route mail through a transactional service (SendGrid, Mailgun, Postmark) and consume its webhooks separately.
  • To customize the email content before it is sent, use the companion filter uspw_before_send_winner_email (also Pro-gated).

Related Documentation

Conclusion

The uspw_email_sent_result action gives Pro sites a clean place to react to winner-email outcomes — logging, retries, SMS fallbacks, or CRM updates. Remember that it only runs when Ultimate Spin Wheel Pro is active and the campaign has coupon email delivery enabled, and that the coupon code lives inside $data['others_data'] rather than at the top level. For more help, visit the wowDevs support center.

How can we help?