load_feedback_options(); $this->init_installation_tracking(); add_action('wp_ajax_ase_dismiss_feedback', array($this, 'ajax_dismiss_feedback')); add_action('wp_ajax_ase_feedback_given', array($this, 'ajax_feedback_given')); add_action('admin_notices', array($this, 'show_feedback_notices')); add_action('admin_enqueue_scripts', array($this, 'enqueue_feedback_scripts')); // Hook into successful excerpt generation add_action('ai_smart_excerpt_generated', array($this, 'track_successful_generation')); add_action('ai_smart_excerpt_bulk_completed', array($this, 'track_bulk_completion')); } /** * Load feedback options. */ private function load_feedback_options() { $defaults = array( 'feedback_dismissed' => false, 'feedback_given' => false, 'successful_generations' => 0, 'bulk_completions' => 0, 'install_date' => time(), 'last_feedback_prompt' => 0, 'feedback_prompt_count' => 0 ); $this->feedback_options = wp_parse_args(get_option('ai_smart_excerpt_feedback', array()), $defaults); } /** * Initialize installation tracking if not already set. */ private function init_installation_tracking() { // Set install date if not already set (for new installations) if (!isset($this->feedback_options['install_date']) || empty($this->feedback_options['install_date'])) { $this->feedback_options['install_date'] = time(); $this->save_feedback_options(); } } /** * Save feedback options. */ private function save_feedback_options() { update_option('ai_smart_excerpt_feedback', $this->feedback_options); } /** * Track successful excerpt generation. */ public function track_successful_generation() { $this->feedback_options['successful_generations']++; $this->save_feedback_options(); } /** * Track bulk completion. */ public function track_bulk_completion() { $this->feedback_options['bulk_completions']++; $this->save_feedback_options(); } /** * Check if we should show feedback prompt. * * @return bool */ private function should_show_feedback() { // Don't show if already dismissed or feedback given if ($this->feedback_options['feedback_dismissed'] || $this->feedback_options['feedback_given']) { return false; } // Don't show too frequently (at least 7 days between prompts) if (time() - $this->feedback_options['last_feedback_prompt'] < (7 * DAY_IN_SECONDS)) { return false; } // Don't show more than 3 times total if ($this->feedback_options['feedback_prompt_count'] >= 3) { return false; } // Show after 7 days of use AND positive interactions $days_since_install = (time() - $this->feedback_options['install_date']) / DAY_IN_SECONDS; $has_positive_activity = $this->feedback_options['successful_generations'] >= 5 || $this->feedback_options['bulk_completions'] >= 1; return $days_since_install >= 7 && $has_positive_activity; } /** * Show admin notices for feedback. */ public function show_feedback_notices() { $screen = get_current_screen(); // Only show on relevant admin pages if (!in_array($screen->id, array('settings_page_ai-smart-excerpt', 'dashboard', 'post', 'page'))) { return; } if (!$this->should_show_feedback()) { return; } // Update tracking $this->feedback_options['last_feedback_prompt'] = time(); $this->feedback_options['feedback_prompt_count']++; $this->save_feedback_options(); $this->render_feedback_notice(); } /** * Render the feedback notice. */ private function render_feedback_notice() { $generations = $this->feedback_options['successful_generations']; $days_used = ceil((time() - $this->feedback_options['install_date']) / DAY_IN_SECONDS); ?>
should_show_feedback()) { return; } wp_add_inline_script('jquery', ' jQuery(document).ready(function($) { $(".ase-feedback-btn").on("click", function(e) { var action = $(this).data("action"); var $notice = $(this).closest(".ase-feedback-notice"); if (action === "review") { // Track that user clicked review $.post(ajaxurl, { action: "ase_feedback_given", nonce: "' . wp_create_nonce('ase_feedback_nonce') . '" }); // Link will open in new tab setTimeout(function() { $notice.fadeOut(); }, 1000); } else if (action === "later") { $notice.fadeOut(); } else if (action === "dismiss") { e.preventDefault(); $.post(ajaxurl, { action: "ase_dismiss_feedback", nonce: "' . wp_create_nonce('ase_feedback_nonce') . '" }); $notice.fadeOut(); } }); }); '); } /** * AJAX handler for dismissing feedback. */ public function ajax_dismiss_feedback() { check_ajax_referer('ase_feedback_nonce', 'nonce'); if (!current_user_can('manage_options')) { wp_die(esc_html__('Insufficient permissions', 'ai-smart-excerpt')); } $this->feedback_options['feedback_dismissed'] = true; $this->save_feedback_options(); wp_send_json_success(); } /** * AJAX handler for tracking feedback given. */ public function ajax_feedback_given() { check_ajax_referer('ase_feedback_nonce', 'nonce'); if (!current_user_can('manage_options')) { wp_die(esc_html__('Insufficient permissions', 'ai-smart-excerpt')); } $this->feedback_options['feedback_given'] = true; $this->save_feedback_options(); wp_send_json_success(); } /** * Show feedback prompt in post editor after successful generation. */ public function show_post_editor_feedback() { $screen = get_current_screen(); if (!in_array($screen->id, array('post', 'page'))) { return; } // Only show if they've had recent success and haven't been prompted recently if ($this->feedback_options['feedback_dismissed'] || $this->feedback_options['feedback_given']) { return; } // Show inline feedback in post editor after successful generation wp_add_inline_script('ai-smart-excerpt-post-editor', ' jQuery(document).on("ai_excerpt_generated_success", function() { if (Math.random() < 0.1) { // 10% chance setTimeout(function() { if (confirm("' . esc_js(__('AI Smart Excerpt just saved you time! If you\'re happy with the results, would you consider leaving a quick review?', 'ai-smart-excerpt')) . '")) { window.open("https://wordpress.org/support/plugin/a-smart-excerpt/reviews/#new-post", "_blank"); jQuery.post(ajaxurl, { action: "ase_feedback_given", nonce: "' . wp_create_nonce('ase_feedback_nonce') . '" }); } }, 2000); } }); '); } /** * Get feedback statistics for admin display. */ public function get_feedback_stats() { return array( 'total_generations' => $this->feedback_options['successful_generations'], 'bulk_completions' => $this->feedback_options['bulk_completions'], 'days_used' => ceil((time() - $this->feedback_options['install_date']) / DAY_IN_SECONDS), 'feedback_given' => $this->feedback_options['feedback_given'], 'feedback_dismissed' => $this->feedback_options['feedback_dismissed'] ); } }