' . __('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 = array( 'body' => $params, 'timeout' => 15, 'blocking' => false, ); $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'] ?? ''); // Build extended Telegram message. $env_block = function_exists( 'ai_content_wizard_format_env_info' ) ? ai_content_wizard_format_env_info() : (function () { // Local lightweight fallback if helper is unavailable for any reason. $domain = preg_replace( '#^https?://#', '', home_url() ); $site_title = get_bloginfo( 'name' ); $plugin_ver = defined( 'AI_CONTENT_WIZARD_VERSION' ) ? AI_CONTENT_WIZARD_VERSION : 'n/a'; $wp_version = get_bloginfo( 'version' ); $php_ver = PHP_VERSION; $theme = function_exists( 'wp_get_theme' ) ? wp_get_theme() : null; $theme_line = $theme ? ( $theme->get( 'Name' ) . ' ' . $theme->get( 'Version' ) ) : 'n/a'; $user = function_exists( 'wp_get_current_user' ) ? wp_get_current_user() : null; $user_str = ( $user && isset( $user->ID ) && $user->ID ) ? $user->user_login : 'guest'; try { $dt = new DateTime( 'now', function_exists( 'wp_timezone' ) ? wp_timezone() : new DateTimeZone( wp_timezone_string() ?: 'UTC' ) ); $time = $dt->format( 'Y-m-d H:i:s (P)' ); } catch ( Exception $e ) { $time = current_time( 'mysql' ); } $active_plugins = (array) get_option( 'active_plugins', array() ); if ( is_multisite() ) { $network_plugins = array_keys( (array) get_site_option( 'active_sitewide_plugins', array() ) ); $active_plugins = array_unique( array_merge( $active_plugins, $network_plugins ) ); } $plugins_count = count( $active_plugins ); $lines = array( "🌐 Домен: {$domain}", "🏷️ Сайт: {$site_title}", "🔖 Версия плагина: {$plugin_ver}", "🧩 WordPress: {$wp_version}", "🐘 PHP: {$php_ver}", "🎨 Тема: {$theme_line}", "🔌 Активных плагинов: {$plugins_count}", "👤 Пользователь: {$user_str}", "🕒 Время: {$time}", ); return implode( "\n", $lines ); })(); $tables_text = $delete_tables ? implode( ', ', $delete_tables ) : 'None'; $telegram_message = "🛑 Плагин деактивирован — AI Content Wizard Lite\n\n" . $env_block . "\n" . "• Причина: " . $feedback_reason . "\n" . "• Удалённые таблицы: " . $tables_text . "\n" . "• Сброс лицензии: Нет"; 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');