Spin Wheel

⌘K
  1. Home
  2. Spin Wheel
  3. Hooks & Filters (Deve...
  4. After database insert (uspw_after_entry_saved)

After database insert (uspw_after_entry_saved)

After the Entry Is Saved (uspw_after_entry_saved)

The uspw_after_entry_saved action fires immediately after a spin entry is inserted into the database, once the new row’s auto-increment ID is available. It is the ideal place to run CRM synchronisation, webhook triggers, and other external integrations that need the saved entry’s ID. This is an action hook (it returns nothing), introduced in version 1.0.0.

Key facts:

  1. Pro-only hook (Pro): In the free plugin this hook is wrapped in if ( apply_filters( 'ultimate_spin_wheel_pro_init', false ) ), so it only fires when the separate Ultimate Spin Wheel Pro plugin is active. Your callback will never run on a free-only site.
  2. Fires after the insert: The row is already written to the custom table {prefix}_wdengage_entries before the hook runs, so $entry_id is a valid database ID.
  3. Runs during the spin AJAX request: The callback executes synchronously inside the visitor’s spin request, so keep slow work (external HTTP calls) non-blocking or deferred.

Availability

Ultimate Spin Wheel Pro is a separate plugin. In the free plugin every developer hook, including this one, is gated behind apply_filters( 'ultimate_spin_wheel_pro_init', false ), which only returns true when Pro is installed and active. If you register a callback on a free-only install it is simply never invoked. Confirm Pro is active before relying on this hook in production.

Parameters

The action passes three arguments, so register it with a priority and an accepted-args count of 3:

  • $entry_id (int): The auto-increment id of the new row in {prefix}_wdengage_entries.
  • $data (array): The entry data used for the insert (see the exact keys below).
  • $campaign_id (int): The ID of the spin wheel campaign the entry belongs to.

Register it like this: add_action( 'uspw_after_entry_saved', 'my_post_save_handler', 10, 3 ); with a matching signature function my_post_save_handler( $entry_id, $data, $campaign_id ) { … }.

What the $data Array Actually Contains

This is the most important correction for real integrations: the coupon, prize, and status details are not top-level keys. They live inside two JSON-encoded string columns. The $data array passed to the hook holds exactly these keys:

  • $data['campaign_id'] and $data['campaign_title']: The campaign ID and its title.
  • $data['name'], $data['email'], $data['phone']: The captured lead fields (name and email are free; the phone field is a Pro feature).
  • $data['campaign_type']: The layout type string, e.g. Spin Wheel.
  • $data['others_data']: A JSON string containing coupon_title, coupon_code, status (won or a lose status), and phone. Decode it with json_decode( $data['others_data'], true ) to read the prize and outcome.
  • $data['user_data']: A JSON string containing ip_address, device_id, and user_agent. Decode it the same way to read the visitor context.

There are no built-in prize_value, company, country, city, lead_score, or utm_* fields, and created_at is written by the database, not passed in $data. If you need extra fields, add them earlier with the uspw_before_save_entry filter (Pro) — any keys you add there are preserved in the $data array this hook receives.

Reading the Coupon and Outcome

Because the prize lives inside others_data, decode it first: $others = json_decode( $data['others_data'], true );. You can then read $others['coupon_code'] (the real, resolved code — for unique pools this is the specific code the visitor won), $others['coupon_title'], and $others['status']. For the visitor’s IP, use $ctx = json_decode( $data['user_data'], true ); and read $ctx['ip_address'].

Common Use Cases

Trigger a Webhook (Zapier, Make, n8n)

Send the entry to an automation service. Read your saved webhook URL, decode others_data for the prize, then post the payload with wp_remote_post( $url, [ 'blocking' => false, 'headers' => [ 'Content-Type' => 'application/json' ], 'body' => wp_json_encode( $payload ) ] ). Using 'blocking' => false is strongly recommended so the visitor’s spin is not delayed waiting for the remote server. Include $entry_id, $campaign_id, get_the_title( $campaign_id ), the lead fields, and the decoded coupon_code / status.

Sync a Lead to a CRM

Push winners into Salesforce, HubSpot, Pipedrive, or similar. Build the lead payload from $data['name'], $data['email'], $data['phone'], and the decoded coupon fields, then send it with wp_remote_post() to your CRM’s API. Store the returned CRM record ID somewhere durable — for example a WordPress option or the user’s meta — since this plugin does not provide a per-entry meta table (see the note below).

Create a WooCommerce Customer

On WooCommerce sites, auto-create an account for new winners. Guard the callback with if ( ! class_exists( 'WooCommerce' ) ) { return; }, skip empty emails, reuse an existing account via email_exists( $email ), otherwise create one with wc_create_new_customer(). You can then persist the winner details on the user with update_user_meta() — for instance the entry ID and the decoded coupon code — so the reward is linked to their account.

Queue Slow Work Asynchronously

Because this hook runs inside the visitor’s spin request, offload anything slow. Use wp_schedule_single_event( time() + 60, 'my_enrich_hook', [ $entry_id, $data['email'] ] ) to defer email enrichment, multi-CRM fan-out, or follow-up emails to WP-Cron, then register normal add_action() handlers for those custom hooks. This keeps the spin snappy for the user.

Notes & Best Practices

  • No entry-meta table exists. The plugin only creates {prefix}_wdengage_entries; there is no wdengage_entry_meta table. To attach extra data to an entry, store it in a WordPress option, in user meta, or in your external system keyed by $entry_id.
  • Prize data is nested. Always json_decode( $data['others_data'], true ) for the coupon and status, and json_decode( $data['user_data'], true ) for the IP and device — they are not top-level keys.
  • Keep it fast. Prefer 'blocking' => false for outbound requests or defer heavy work with wp_schedule_single_event() so the spin response is not delayed.
  • Add custom fields upstream. If you need data beyond the default keys, inject it with uspw_before_save_entry (Pro) — those additions flow through to $data here.

Related Documentation

Conclusion

The uspw_after_entry_saved action gives Pro developers a reliable, ID-in-hand entry point for CRM sync, webhooks, and account creation right after a spin is recorded. Remember that it only fires when Ultimate Spin Wheel Pro is active, that the coupon and outcome live inside the others_data JSON, and that there is no per-entry meta table — store extra data elsewhere. For help, visit the wowDevs support center.

How can we help?