'advajra/advajra.php', 'ajaxUrl' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'advajra_deactivation_feedback' ), 'userEmail' => $current_user->user_email ?? '', 'siteUrl' => home_url(), 'supportUrl' => 'https://advajra.com/support?utm_source=advajra-plugin&utm_medium=deactivation-survey&utm_campaign=support', 'featureUrl' => 'https://advajra.com/feature-request?utm_source=advajra-plugin&utm_medium=deactivation-survey&utm_campaign=feature-request', 'logoUrl' => ADVAJRA_URL . 'assets/images/logo.png', ] ); } /** * Handle AJAX feedback submission, send email, then pass back the deactivation URL. */ public function handle_feedback(): void { check_ajax_referer( 'advajra_deactivation_feedback', 'nonce' ); if ( ! current_user_can( 'manage_options' ) ) { wp_send_json_error( 'Unauthorized', 403 ); } $reason = sanitize_text_field( wp_unslash( $_POST['reason'] ?? '' ) ); $detail = sanitize_textarea_field( wp_unslash( $_POST['detail'] ?? '' ) ); $email = sanitize_email( wp_unslash( $_POST['email'] ?? '' ) ); $site_url = home_url(); $wp_version = get_bloginfo( 'version' ); $plugin_ver = ADVAJRA_VERSION; // Reason labels for the email body. $reason_labels = [ 'bug' => 'πŸ› Found a bug / Something is broken', 'missing_feature'=> 'πŸ”§ Missing a feature I need', 'conflict' => '🧩 Plugin conflict / Compatibility issue', 'too_complex' => '🀷 Too complex or hard to set up', 'no_revenue' => 'πŸ“‰ Not seeing ad revenue improvement', 'too_expensive' => 'πŸ’° Too expensive / Switching to free alternative', 'switching' => 'πŸ”„ Switching to a different plugin', 'temporary' => '⏸️ Temporarily deactivating', 'no_longer_ads' => '🚫 No longer running ads on this site', 'other' => 'πŸ’¬ Other reason', ]; $reason_label = $reason_labels[ $reason ] ?? $reason; // Build a clean, formatted HTML email body. $body = $this->build_email_html( $reason_label, $detail, $email, $site_url, $wp_version, $plugin_ver ); $headers = [ 'Content-Type: text/html; charset=UTF-8', ]; // Set reply-to as user's email if we have it, so you can reply directly. if ( $email && is_email( $email ) ) { $current_user = wp_get_current_user(); $name = $current_user->display_name ?? ''; $headers[] = 'Reply-To: ' . ( $name ? "$name <$email>" : $email ); } wp_mail( 'support@advajra.com', '[AdVajra Uninstall] ' . $reason_label . ' β€” ' . $site_url, $body, $headers ); wp_send_json_success( [ 'sent' => true ] ); } /** * Build the HTML email body. * * @param string $reason_label Human-readable reason. * @param string $detail Optional user message. * @param string $email User email. * @param string $site_url Site URL. * @param string $wp_version WordPress version. * @param string $plugin_ver AdVajra version. * @return string */ private function build_email_html( string $reason_label, string $detail, string $email, string $site_url, string $wp_version, string $plugin_ver ): string { $detail_html = $detail ? '

' . esc_html( $detail ) . '

' : '

No additional message provided.

'; return '

AdVajra Plugin

A user just left πŸ‘‹

' . esc_html( $site_url ) . '

Reason

' . esc_html( $reason_label ) . '

Their Message

' . $detail_html . '

Site Info

Email ' . esc_html( $email ?: 'β€”' ) . '
WordPress ' . esc_html( $wp_version ) . '
AdVajra Version ' . esc_html( $plugin_ver ) . '
'; } }