admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'acquis_public_nonce' ), 'delivery_mode' => get_option( 'acquis_delivery_mode', 'both' ), 'i18n' => array( 'submitting' => __( 'Please wait…', 'acquisitionsuite' ), 'submit' => __( 'Get My Download', 'acquisitionsuite' ), 'pay_now' => __( 'Continue to Payment', 'acquisitionsuite' ), 'error_gen' => __( 'Something went wrong. Please try again.', 'acquisitionsuite' ), 'email_sent' => __( '📧 Check your inbox we\'ve sent the download link!', 'acquisitionsuite' ), 'loading' => __( 'Loading form…', 'acquisitionsuite' ), 'load_error' => __( 'Could not load the form. Please try again.', 'acquisitionsuite' ), ), ) ); } /** * AJAX endpoint returns rendered HTML for a custom form. * Called by acquis-public.js whenever a button carries data-form-id > 0. */ public function ajax_get_form() { $nonce = isset( $_POST['nonce'] ) ? sanitize_text_field( wp_unslash( $_POST['nonce'] ) ) : ''; if ( ! wp_verify_nonce( $nonce, 'acquis_public_nonce' ) && ! wp_verify_nonce( $nonce, 'acquis_nonce' ) ) { wp_send_json_error( array( 'message' => 'Security check failed.' ), 403 ); } $form_id = absint( $_POST['form_id'] ?? 0 ); if ( ! $form_id ) { wp_send_json_error( array( 'message' => 'No form ID.' ), 400 ); } if ( ! class_exists( 'ACQUIS_Form_Renderer' ) || ! class_exists( 'ACQUIS_P3_DB' ) ) { wp_send_json_error( array( 'message' => 'Form system unavailable.' ), 500 ); } $form = ACQUIS_P3_DB::get_form( $form_id ); if ( ! $form ) { wp_send_json_error( array( 'message' => 'Form not found.' ), 404 ); } $html = ACQUIS_Form_Renderer::render( $form_id ); $settings = is_array( $form->settings ) ? $form->settings : array(); // Per-form header settings (fall back to empty = use global defaults) $modal_title = sanitize_text_field( $settings['modal_title'] ?? '' ); $modal_subtitle = sanitize_text_field( $settings['modal_subtitle'] ?? '' ); $header_bg = sanitize_text_field( $settings['header_bg'] ?? '' ); $title_color = sanitize_text_field( $settings['title_color'] ?? '' ); $subtitle_color = sanitize_text_field( $settings['subtitle_color'] ?? '' ); // Field mapping keys (which field_key acts as name / email for lead record) $name_field = sanitize_key( $settings['name_field'] ?? '' ); $email_field = sanitize_key( $settings['email_field'] ?? '' ); wp_send_json_success( array( 'html' => $html, 'steps' => absint( $form->steps ), 'title' => esc_html( $form->title ), 'modal_title' => $modal_title, 'modal_subtitle' => $modal_subtitle, 'header_bg' => $header_bg, 'title_color' => $title_color, 'subtitle_color' => $subtitle_color, 'name_field' => $name_field, 'email_field' => $email_field, ) ); } /** * Phase 4: lightweight page-visit beacon. Fires the 'page_visit' * automation trigger for known leads (identified by the long-lived * 'acquis_lead' cookie set at capture time). Anonymous visitors are * intentionally ignored here there's no lead to attribute the * visit to. */ public function ajax_track_visit() { if ( ! check_ajax_referer( 'acquis_nonce', 'nonce', false ) ) { wp_send_json_error( null, 403 ); } $lead_id = isset( $_COOKIE['acquis_lead'] ) ? absint( $_COOKIE['acquis_lead'] ) : 0; if ( ! $lead_id ) { wp_send_json_success(); // nothing to attribute to; not an error } $url = isset( $_POST['url'] ) ? esc_url_raw( wp_unslash( $_POST['url'] ) ) : ''; if ( class_exists( 'ACQUIS_P3_DB' ) ) { ACQUIS_P3_DB::track_event( 'page_visit', array( 'lead_id' => $lead_id, 'source_url' => $url ) ); } if ( class_exists( 'ACQUIS_Automation_Engine' ) ) { $context = array( 'source_url' => $url, 'lead_score' => class_exists( 'ACQUIS_Lead_Scorer' ) ? ACQUIS_Lead_Scorer::current_total( $lead_id ) : 0, ); ACQUIS_Automation_Engine::run( 'page_visit', $lead_id, $context ); } wp_send_json_success(); } public function render_modal() { $delivery_mode = get_option( 'acquis_delivery_mode', 'both' ); $email_only = ( $delivery_mode === 'email' ); ?>