admin_url( 'admin-ajax.php' ), 'action' => DISCO_AC_AJAX_ACTION, 'nonce' => wp_create_nonce( DISCO_AC_NONCE_ACTION ), 'show_email_field' => ! disco_activecampaign_has_subscriber(), ); } /** * AJAX handler: mark the email as collected. * * Called by the React app after it has submitted the email to * ActiveCampaign. Stores the flag so the opt-in field stays hidden. * * @return void */ function disco_activecampaign_handle_subscribed() { check_ajax_referer( DISCO_AC_NONCE_ACTION, 'nonce' ); if ( ! current_user_can( 'manage_options' ) && ! current_user_can( 'manage_woocommerce' ) ) { wp_send_json_error( array( 'message' => __( 'You are not allowed to do this.', 'disco' ) ), 403 ); } update_option( DISCO_AC_OPTION_KEY, true, false ); wp_send_json_success( array( 'message' => __( 'Thanks! You are subscribed.', 'disco' ), ) ); } add_action( 'wp_ajax_' . DISCO_AC_AJAX_ACTION, 'disco_activecampaign_handle_subscribed' );