getTotalDocumentsCount(); if ($total_documents <= self::MIN_DOCUMENTS) { return false; } // Check if we should reshow (if user clicked "Maybe Later" and 7 days passed) // IMPORTANT: Only respect LAST_SHOWN_OPTION if user actually interacted (clicked a button) // This prevents old auto-set values from blocking the notice $user_interacted = get_user_meta($user_id, self::USER_INTERACTED_OPTION, true); $last_shown = get_user_meta($user_id, self::LAST_SHOWN_OPTION, true); // Only check LAST_SHOWN_OPTION if user has actually interacted with a button // If LAST_SHOWN_OPTION exists but user_interacted is false, it means the old code set it // In that case, we ignore it and show the notice (since user never clicked a button) if ($user_interacted && $last_shown && (int)$last_shown > 0) { $reshow_date = strtotime('+' . self::RESHOW_AFTER_DAYS . ' days', (int)$last_shown); // Only block if it's been less than 7 days since user clicked "Maybe Later" if (time() < $reshow_date) { return false; } } elseif ($last_shown && !$user_interacted) { // LAST_SHOWN_OPTION exists but user never interacted - this was set by old code // Clear it silently and show the notice delete_user_meta($user_id, self::LAST_SHOWN_OPTION); } // All checks passed - show the notice return true; } /** * Get total count of invoices and quotes * * @return int */ private function getTotalDocumentsCount(): int { global $wpdb; // Count ALL invoices including drafts, published, pending, etc. // Query directly to get accurate count of all post statuses $invoice_count = (int) $wpdb->get_var($wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->posts} WHERE post_type = %s AND post_status != 'trash'", \EasyInvoice\Constants\PostTypes::EASY_INVOICE_POST_TYPE )); // Count ALL quotes including drafts, published, pending, etc. $quote_count = (int) $wpdb->get_var($wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->posts} WHERE post_type = %s AND post_status != 'trash'", \EasyInvoice\Constants\PostTypes::EASY_INVOICE_QUOTE_POST_TYPE )); return $invoice_count + $quote_count; } /** * Display admin notice (WordPress admin UI) * Shows on ALL WordPress admin pages (Dashboard, Posts, Pages, etc.) */ public function displayAdminNotice() { if (!$this->shouldDisplayNotice()) { return; } // Show on all WordPress admin pages $this->renderNotice(); // DO NOT update LAST_SHOWN_OPTION here - only update when user clicks a button } /** * Display custom notice (plugin's custom UI) * * @param string $page Current page slug */ public function displayCustomNotice($page = '') { if (!$this->shouldDisplayNotice()) { return; } // Add wrapper div for proper spacing echo '