should_show_notice()) { add_action('admin_notices', [$this, 'render_notice']); } } /** * Enqueue CSS and JS assets */ public function enqueue_assets(): void { if (!$this->should_show_notice()) { return; } wp_enqueue_style( 'king-addons-rating-notice', KING_ADDONS_URL . 'includes/admin/css/rating-notice.css', [], KING_ADDONS_VERSION ); wp_enqueue_script( 'king-addons-rating-notice', KING_ADDONS_URL . 'includes/admin/js/rating-notice.js', ['jquery'], KING_ADDONS_VERSION, true ); wp_localize_script('king-addons-rating-notice', 'KingAddonsRating', [ 'ajaxurl' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('king-addons-rating-nonce'), 'wpOrgUrl' => 'https://wordpress.org/support/plugin/king-addons/reviews/?filter=5#new-post', ]); } /** * Check if notice should be displayed * * Priority logic: * 1. Never show if already dismissed or rated * 2. If "Maybe Later" was clicked - wait 7 days from that time * 3. Premium users - show immediately (they paid, they're happy!) * 4. If user dismissed upgrade notice (active free user) - can show after 3 days * 5. Otherwise - wait 14 days from plugin activation */ private function should_show_notice(): bool { // Already dismissed or rated - never show if (!empty(get_option(self::OPTION_DISMISS)) || !empty(get_option(self::OPTION_RATED))) { return false; } $later_time = get_option(self::OPTION_LATER_TIME); $activation_time = get_option(self::OPTION_ACTIVATION_TIME); $user_id = get_current_user_id(); // Case 1: User clicked "Maybe Later" - check 7 days from that time if ($later_time) { $past_date = strtotime("-" . self::DAYS_REMIND_LATER . " days"); return $past_date >= $later_time; } // Case 2: Premium users - show immediately // They already paid, they're clearly happy with the plugin! if (function_exists('king_addons_freemius') && king_addons_freemius()->can_use_premium_code__premium_only()) { return true; } // Case 3: Check if user previously dismissed the upgrade notice (active free user) // This means they've been using the plugin actively $upgrade_notice_dismissed_time = get_user_meta($user_id, 'king_addons_premium_notice_dismissed_time', true); if ($upgrade_notice_dismissed_time) { // Active user who dismissed upgrade notice - can show rating notice // But let's give them at least 3 days after dismissing upgrade notice $grace_period = strtotime("-3 days"); return $grace_period >= $upgrade_notice_dismissed_time; } // Case 4: Standard check - 14 days from activation if (false === $activation_time) { return false; } $past_date = strtotime("-" . self::DAYS_BEFORE_SHOW . " days"); return $past_date >= $activation_time; } /** * Render the rating notice HTML */ public function render_notice(): void { $logo_url = KING_ADDONS_URL . 'includes/admin/img/icon-for-admin.svg'; ?>