' . __('Deactivate', 'ai-content-wizard') . ''; } return $actions; } add_filter('plugin_action_links_' . plugin_basename(AI_CONTENT_WIZARD_PLUGIN_FILE), 'ai_content_wizard_modify_deactivate_link', 10, 4); /** * Print modal HTML (with inline CSS and JS) in footer of plugins page. */ function ai_content_wizard_print_modal_html() { ?>
$chat_id, 'text' => $message, 'parse_mode' => 'Markdown' ]; $args = [ 'body' => $params, 'timeout' => 10, ]; $response = wp_remote_post($url, $args); if (is_wp_error($response)) { error_log('Telegram message failed: ' . $response->get_error_message()); } } /** * Handle the feedback form submission. */ function ai_content_wizard_handle_feedback_submission() { if (!current_user_can('manage_options')) { wp_die(__('Access Denied', 'ai-content-wizard')); } check_admin_referer('ai_content_wizard_deactivation_feedback_nonce', 'ai_content_wizard_deactivation_feedback_nonce_field'); $skip_feedback = sanitize_text_field($_POST['skip_feedback'] ?? '0'); $domain = sanitize_text_field(home_url()); if ($skip_feedback === '1') { $feedback_reason = 'User skipped feedback form 📝'; $delete_tables = []; // No tables deletion if skipped. } else { $preset = sanitize_text_field($_POST['preset_feedback'] ?? ''); if ($preset && $preset !== 'other') { switch ($preset) { case 'trial_expired': $feedback_reason = 'Trial period ended.'; break; case 'not_useful': $feedback_reason = 'Trial did not meet my needs.'; break; case 'technical_issues': $feedback_reason = 'Encountered technical issues during trial.'; break; case 'prefer_alternative': $feedback_reason = 'I prefer another solution.'; break; default: $feedback_reason = 'Unspecified reason.'; break; } } else { $feedback_reason = sanitize_textarea_field($_POST['feedback_reason'] ?? ''); $feedback_reason = $feedback_reason ? $feedback_reason : 'No reason provided.'; } $delete_tables = isset($_POST['delete_tables']) ? array_map('sanitize_text_field', $_POST['delete_tables']) : []; } $plugin_file = sanitize_text_field($_POST['plugin'] ?? ''); // No license reset in Lite version. // Form Telegram message. $tables_text = $delete_tables ? implode(', ', $delete_tables) : 'None'; $telegram_message = "🔴 *Deactivation of AI Content Wizard Lite*\n\n" . "📅 *Date:* " . date('d.m.Y H:i') . "\n" . "🌐 *Domain:* " . $domain . "\n" . "📋 *Feedback:* " . $feedback_reason . "\n" . "🗑️ *Deleted tables:* " . $tables_text . "\n" . "👤 *User:* " . get_current_user_id(); ai_content_wizard_send_telegram_message($telegram_message); // Send email. $to = 'aiwizard@buyreadysite.com'; $subject = __('Plugin Deactivation Feedback', 'ai-content-wizard'); $message = __("User deactivated the plugin with the following feedback:\n", 'ai-content-wizard') . $feedback_reason . "\n\n" . __("Domain: ", 'ai-content-wizard') . $domain . "\n" . __("Tables requested for deletion: ", 'ai-content-wizard') . implode(', ', $delete_tables); wp_mail($to, $subject, $message); // Delete tables if selected and feedback was provided. if ($skip_feedback !== '1' && !empty($delete_tables)) { global $wpdb; if (in_array('settings', $delete_tables)) { $table = $wpdb->prefix . 'ai_content_wizard_settings'; $wpdb->query("DROP TABLE IF EXISTS $table"); } if (in_array('posts_logs', $delete_tables)) { $table = $wpdb->prefix . 'ai_content_wizard_posts_logs'; $wpdb->query("DROP TABLE IF EXISTS $table"); } if (in_array('content_plan_logs', $delete_tables)) { $table = $wpdb->prefix . 'ai_content_wizard_content_plan_logs'; $wpdb->query("DROP TABLE IF EXISTS $table"); } if (in_array('content_plan', $delete_tables)) { $table = $wpdb->prefix . 'ai_content_wizard_content_plan'; $wpdb->query("DROP TABLE IF EXISTS $table"); } } if (!function_exists('deactivate_plugins')) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } deactivate_plugins($plugin_file); wp_redirect(admin_url('plugins.php?deactivation=success')); exit; } add_action('admin_post_ai_content_wizard_deactivation_feedback', 'ai_content_wizard_handle_feedback_submission');