save() )` branch — i.e. only after the * entry has already been confirmed saved to Hustle's "local_list" * integration. $field_data_array is a list of {name, value} pairs (the * same shape the plugin uses internally for hustle_ip/active_integrations), * flattened below into a plain map plus best-effort 'email', 'first_name' * and 'last_name' fields. * * Hustle popups/embeds are individual modules with no simple enumerable * "form" picker exposed as a public API, so — same reasoning as the * Jetpack/Otter Forms triggers — this is a single site-wide trigger rather * than a per-module picker; $module_id is still exposed as a field so * users can filter by it downstream if they have multiple optins. * * @link https://plugins.trac.wordpress.org/browser/wordpress-popup/trunk/inc/front/hustle-module-front-ajax.php */ add_action( 'plugins_loaded', 'adfoin_hustle_register_hooks', 20 ); function adfoin_hustle_register_hooks() { if ( ! class_exists( 'Hustle_Module_Model' ) ) { return; } add_action( 'hustle_form_submit_before_set_fields', 'adfoin_hustle_handle_submission', 10, 3 ); } // Get Hustle Triggers function adfoin_hustle_get_forms( $form_provider ) { if ( $form_provider !== 'hustle' ) { return; } return array( 'optinSubmitted' => __( 'Optin/Popup Form Submitted (site-wide)', 'advanced-form-integration' ), ); } // Get Hustle Fields function adfoin_hustle_get_form_fields( $form_provider, $form_id ) { if ( $form_provider !== 'hustle' || $form_id !== 'optinSubmitted' ) { return; } return array( 'module_id' => __( 'Module ID (which popup/embed was submitted)', 'advanced-form-integration' ), 'first_name' => __( 'First Name', 'advanced-form-integration' ), 'last_name' => __( 'Last Name', 'advanced-form-integration' ), 'email' => __( 'Email', 'advanced-form-integration' ), 'all_fields_json' => __( 'All Submitted Fields (JSON, for fields not listed above)', 'advanced-form-integration' ), ); } // Handle Optin Submitted function adfoin_hustle_handle_submission( $entry, $module_id, $field_data_array ) { $integration = new Advanced_Form_Integration_Integration(); $saved_records = $integration->get_by_trigger( 'hustle', 'optinSubmitted' ); if ( empty( $saved_records ) ) { return; } $all_fields = array(); $email = ''; $first_name = ''; $last_name = ''; if ( is_array( $field_data_array ) ) { foreach ( $field_data_array as $field ) { if ( ! is_array( $field ) || empty( $field['name'] ) ) { continue; } $value = isset( $field['value'] ) ? $field['value'] : ''; $all_fields[ $field['name'] ] = $value; if ( 'email' === $field['name'] && ! is_array( $value ) ) { $email = $value; } elseif ( 'first_name' === $field['name'] && ! is_array( $value ) ) { $first_name = $value; } elseif ( 'last_name' === $field['name'] && ! is_array( $value ) ) { $last_name = $value; } } } $posted_data = array( 'module_id' => $module_id, 'first_name' => $first_name, 'last_name' => $last_name, 'email' => $email, 'all_fields_json' => wp_json_encode( $all_fields ), ); adfoin_dispatch_integrations( $saved_records, $posted_data ); }