'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 '