PluginProbe
Easy Invoice – Invoice Generator, PDF Quotes & Payments / 2.2.0
Easy Invoice – Invoice Generator, PDF Quotes & Payments v2.2.0
2.4.0 2.4.1 2.3.8 2.3.7 2.3.6 2.3.5 2.3.4 2.3.3 2.3.2 2.3.1 2.2.0 2.1.21 2.1.20 2.1.19 2.1.18 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 2.1.14 2.1.15 2.1.16 2.1.2 All 57 releases
easy-invoice / includes / Services / PromotionService.php

PromotionService.php in Easy Invoice – Invoice Generator, PDF Quotes & Payments 2.2.0, at includes/Services/PromotionService.php

381 lines 15.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Promotion Service
4 *
5 * @package EasyInvoice
6 * @subpackage Services
7 */
8
9 namespace EasyInvoice\Services;
10
11 /**
12 * PromotionService Class
13 *
14 * Handles promotional banner display logic for Easy Invoice Pro upgrades
15 */
16 class PromotionService {
17
18 /**
19 * Promotion banner dismissed option key
20 */
21 const DISMISSED_OPTION = 'easy_invoice_promotion_dismissed';
22
23 /**
24 * Promotion banner last shown timestamp option key
25 */
26 const LAST_SHOWN_OPTION = 'easy_invoice_promotion_last_shown';
27
28 /**
29 * Promotion banner permanently hidden option key
30 */
31 const PERMANENTLY_HIDDEN_OPTION = 'easy_invoice_promotion_permanently_hidden';
32
33 /**
34 * Minimum invoices required to show promotion
35 */
36 const MIN_INVOICES = 1;
37
38 /**
39 * Days to wait before showing again if dismissed once
40 */
41 const RESHOW_AFTER_DAYS = 15;
42
43 /**
44 * Easy Invoice Pro pricing URL
45 */
46 const PRO_PRICING_URL = 'https://matrixaddons.com/plugins/easy-invoice#pricing';
47
48 /**
49 * Initialize the promotion service
50 */
51 public static function init() {
52 add_action('admin_notices', [__CLASS__, 'maybeShowPromotionBanner']);
53 add_action('wp_ajax_easy_invoice_dismiss_promotion', [__CLASS__, 'handleDismissPromotion']);
54 add_action('admin_enqueue_scripts', [__CLASS__, 'enqueueScripts']);
55 add_action('admin_menu', [__CLASS__, 'addUpgradeToProMenu']);
56
57 // Add plugin row action
58 add_filter('plugin_action_links_' . plugin_basename(EASY_INVOICE_PLUGIN_FILE), [__CLASS__, 'addPluginRowAction']);
59 }
60
61 /**
62 * Enqueue admin scripts for promotion functionality
63 */
64 public static function enqueueScripts() {
65 wp_enqueue_script('easy-invoice-promotion', EASY_INVOICE_PLUGIN_URL . 'assets/js/promotion.js', ['jquery'], EASY_INVOICE_VERSION, true);
66 wp_localize_script('easy-invoice-promotion', 'easyInvoicePromotion', [
67 'ajaxUrl' => admin_url('admin-ajax.php'),
68 'nonce' => wp_create_nonce('easy_invoice_promotion_nonce')
69 ]);
70
71 // Add plain text CSS for plugin row action
72 wp_add_inline_style('easy-invoice-promotion', '
73 .plugin-action-links a[href*="easy-invoice#pricing"] {
74 color: #ff9500 !important;
75 font-weight: 600 !important;
76 text-decoration: none !important;
77 font-size: 12px !important;
78 transition: all 0.3s ease !important;
79 }
80
81 .plugin-action-links a[href*="easy-invoice#pricing"]:hover {
82 color: #e67e00 !important;
83 text-decoration: underline !important;
84 }
85 ');
86 }
87
88 /**
89 * Check if Easy Invoice Pro is active
90 */
91 public static function isProActive() {
92 if (!function_exists('is_plugin_active')) {
93 require_once ABSPATH . 'wp-admin/includes/plugin.php';
94 }
95 return is_plugin_active('easy-invoice-pro/easy-invoice-pro.php');
96 }
97
98 /**
99 * Get the count of invoices created by the user
100 */
101 public static function getInvoiceCount() {
102 $args = [
103 'post_type' => 'easy_invoice',
104 'post_status' => ['publish', 'draft', 'pending'],
105 'posts_per_page' => -1,
106 'fields' => 'ids'
107 ];
108
109 $query = new \WP_Query($args);
110 return $query->found_posts;
111 }
112
113 /**
114 * Check if promotion should be shown
115 */
116 public static function shouldShowPromotion() {
117 // Don't show if Pro is active
118 if (self::isProActive()) {
119 return false;
120 }
121
122 // Don't show if permanently hidden
123 if (get_option(self::PERMANENTLY_HIDDEN_OPTION)) {
124 return false;
125 }
126
127 // Check if user has created enough invoices
128 $invoice_count = self::getInvoiceCount();
129 if ($invoice_count < self::MIN_INVOICES) {
130 return false;
131 }
132
133 // Check if banner was dismissed
134 $dismissed = get_option(self::DISMISSED_OPTION);
135 if ($dismissed) {
136 // Check if enough time has passed to show again
137 $last_shown = get_option(self::LAST_SHOWN_OPTION);
138 if ($last_shown) {
139 $days_since_shown = (current_time('timestamp') - strtotime($last_shown)) / DAY_IN_SECONDS;
140 if ($days_since_shown < self::RESHOW_AFTER_DAYS) {
141 return false;
142 }
143 }
144 }
145
146 return true;
147 }
148
149 /**
150 * Display the promotion banner if conditions are met
151 */
152 public static function maybeShowPromotionBanner() {
153 if (!self::shouldShowPromotion()) {
154 return;
155 }
156
157 // Update last shown timestamp
158 update_option(self::LAST_SHOWN_OPTION, current_time('mysql'));
159
160 $invoice_count = self::getInvoiceCount();
161 ?>
162 <div id="easy-invoice-promotion-notice" class="notice is-dismissible" style="background: linear-gradient(135deg, #fdf6f0 0%, #f8f9fa 50%, #fff5ee 100%); border: 1px solid #f0e6d8; border-left: 4px solid #ff9500; border-radius: 6px; margin: 15px 0; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08); position: relative;">
163 <div style="position: absolute; top: 8px; right: 80px; background: #ff9500; color: white; padding: 2px 8px; border-radius: 10px; font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.3px;">
164 Limited Time
165 </div>
166 <div class="easy-invoice-promotion-content" style="padding: 18px;">
167 <div style="display: flex; align-items: flex-start; gap: 15px;">
168 <div style="flex: 1;">
169 <h3 style="margin: 0 0 10px 0; color: #2c3e50; font-size: 17px; font-weight: 600;">
170 🚀 Upgrade to Easy Invoice Pro - Save 20%!
171 </h3>
172 <p style="margin: 0 0 12px 0; font-size: 14px; line-height: 1.5; color: #495057;">
173 You've created <strong style="color: #ff9500;"><?php echo esc_html($invoice_count); ?></strong> invoice(s)!
174 Get <strong style="color: #ff9500;">20% OFF</strong> on Easy Invoice Pro. Unlock recurring invoices, advanced reporting, multiple payment gateways, and priority support.
175 </p>
176 <div style="background: rgba(255, 149, 0, 0.08); padding: 10px; border-radius: 4px; margin-bottom: 15px; border-left: 3px solid #ff9500;">
177 <p style="margin: 0; font-size: 13px; color: #495057; font-weight: 600;">
178 🎉 <strong>Special Offer:</strong> Save 20% on your Pro upgrade with advanced features and priority support!
179 </p>
180 </div>
181 <div style="display: flex; align-items: center; gap: 12px;">
182 <a href="<?php echo esc_url(self::PRO_PRICING_URL); ?>"
183 target="_blank"
184 class="button button-primary"
185 style="background-color: #ff9500; border-color: #ff9500; color: white; padding: 8px 20px; font-weight: 600; font-size: 14px; border-radius: 4px; text-decoration: none; box-shadow: 0 2px 6px rgba(255, 149, 0, 0.3); transition: all 0.3s ease;">
186 ⚡ Save 20% - Upgrade to Pro
187 </a>
188 <a href="#"
189 id="easy-invoice-promotion-dismiss"
190 style="color: #6c757d; text-decoration: none; font-size: 13px; transition: color 0.3s ease;">
191 Maybe later
192 </a>
193 </div>
194 </div>
195 </div>
196 </div>
197 </div>
198
199 <style>
200 #easy-invoice-promotion-notice .button:hover {
201 background-color: #e67e00 !important;
202 border-color: #e67e00 !important;
203 transform: translateY(-1px);
204 box-shadow: 0 4px 10px rgba(255, 149, 0, 0.4) !important;
205 }
206
207 #easy-invoice-promotion-dismiss:hover {
208 color: #495057 !important;
209 }
210
211 @media (max-width: 768px) {
212 #easy-invoice-promotion-notice .easy-invoice-promotion-content {
213 padding: 15px !important;
214 }
215 #easy-invoice-promotion-notice .easy-invoice-promotion-content > div {
216 flex-direction: column !important;
217 align-items: flex-start !important;
218 }
219 #easy-invoice-promotion-notice .button {
220 width: 100% !important;
221 text-align: center !important;
222 }
223 }
224 </style>
225 <?php
226 }
227
228 /**
229 * Handle AJAX request to dismiss promotion
230 */
231 public static function handleDismissPromotion() {
232 check_ajax_referer('easy_invoice_promotion_nonce', 'nonce');
233
234 if (!current_user_can('manage_options')) {
235 wp_die(__('You do not have sufficient permissions to access this page.', 'easy-invoice'));
236 }
237
238 $dismiss_count = get_option('easy_invoice_promotion_dismiss_count', 0);
239 $dismiss_count++;
240
241 update_option('easy_invoice_promotion_dismiss_count', $dismiss_count);
242 update_option(self::DISMISSED_OPTION, true);
243
244 // If dismissed more than once, hide permanently
245 if ($dismiss_count >= 2) {
246 update_option(self::PERMANENTLY_HIDDEN_OPTION, true);
247 }
248
249 wp_send_json_success();
250 }
251
252 /**
253 * Add "Upgrade to Pro" action in plugin row
254 */
255 public static function addPluginRowAction($links) {
256 // Don't show if Pro is active
257 if (self::isProActive()) {
258 return $links;
259 }
260
261 $upgrade_link = sprintf(
262 '<a href="%s" target="_blank" style="color: #ff9500; font-weight: 600; text-decoration: none; font-size: 12px; transition: all 0.3s ease;">%s</a>',
263 esc_url(self::PRO_PRICING_URL),
264 __('Upgrade to Pro', 'easy-invoice')
265 );
266
267 // Add to the beginning of the links array
268 array_unshift($links, $upgrade_link);
269
270 return $links;
271 }
272
273 /**
274 * Add "Upgrade to Pro" menu item to main admin menu
275 */
276 public static function addUpgradeToProMenu() {
277 // Only show if Pro is not active
278 if (self::isProActive()) {
279 return;
280 }
281
282 global $submenu;
283
284 // Add the submenu item directly to the submenu array
285 $submenu['easy-invoice'][] = array(
286 __('Upgrade to Pro', 'easy-invoice'),
287 'manage_options',
288 self::PRO_PRICING_URL,
289 __('Upgrade to Pro', 'easy-invoice'),
290 999
291 );
292
293 // Add inline style to the submenu
294 add_action('admin_head', function() {
295 ?>
296 <style>
297 .wp-submenu a[href*="matrixaddons.com"] {
298 color: #fff !important;
299 font-weight: 700 !important;
300 background: linear-gradient(45deg, #ff6b35, #ff9500) !important;
301 border-radius: 4px !important;
302 margin: 2px 8px 2px 0 !important;
303 transition: all 0.3s ease !important;
304 text-shadow: 0 1px 2px rgba(0,0,0,0.2) !important;
305 box-shadow: 0 2px 6px rgba(255, 107, 53, 0.3) !important;
306 display: inline-block !important;
307 padding: 6px 12px !important;
308 }
309
310 .wp-submenu a[href*="matrixaddons.com"]:hover {
311 background: linear-gradient(45deg, #e55a2b, #e67e00) !important;
312 transform: translateX(2px) !important;
313 box-shadow: 0 4px 12px rgba(255, 107, 53, 0.5) !important;
314 }
315 </style>
316 <?php
317 });
318 }
319
320 /**
321 * Display the Upgrade to Pro page
322 */
323 public static function displayUpgradeToProPage() {
324 ?>
325 <div class="wrap">
326 <h1 style="color: #ff9500; margin-bottom: 20px;">
327 🚀 Upgrade to Easy Invoice Pro
328 </h1>
329
330 <div style="background: linear-gradient(135deg, #fdf6f0 0%, #f8f9fa 50%, #fff5ee 100%); border: 1px solid #f0e6d8; border-left: 4px solid #ff9500; border-radius: 6px; padding: 25px; margin-bottom: 25px; box-shadow: 0 2px 8px rgba(255, 149, 0, 0.15);">
331 <h2 style="color: #2c3e50; margin-bottom: 15px;">Get 20% OFF Your Pro Upgrade!</h2>
332 <p style="font-size: 16px; line-height: 1.6; color: #495057; margin-bottom: 20px;">
333 Unlock powerful features including recurring invoices, advanced reporting, multiple payment gateways, and priority support.
334 </p>
335
336 <div style="background: rgba(255, 149, 0, 0.08); padding: 15px; border-radius: 4px; margin-bottom: 20px; border-left: 3px solid #ff9500;">
337 <p style="margin: 0; font-size: 14px; color: #495057; font-weight: 600;">
338 🎉 <strong>Special Offer:</strong> Save 20% on your Pro upgrade with advanced features and priority support!
339 </p>
340 </div>
341
342 <div style="text-align: center; margin: 30px 0;">
343 <a href="<?php echo esc_url(self::PRO_PRICING_URL); ?>"
344 target="_blank"
345 class="button button-primary"
346 style="background: linear-gradient(45deg, #ff9500, #ffaa00); border: none; color: white; padding: 12px 30px; font-weight: 700; font-size: 16px; border-radius: 6px; text-decoration: none; box-shadow: 0 3px 10px rgba(255, 149, 0, 0.4); transition: all 0.3s ease;">
347 Save 20% - Upgrade to Pro Now
348 </a>
349 </div>
350 </div>
351
352 <div style="background: white; border: 1px solid #e1e5e9; border-radius: 6px; padding: 25px;">
353 <h3 style="color: #2c3e50; margin-bottom: 15px;">Why Upgrade to Pro?</h3>
354 <ul style="list-style: none; padding: 0;">
355 <li style="margin-bottom: 12px; padding-left: 25px; position: relative;">
356 <span style="position: absolute; left: 0; color: #28a745;"></span>
357 <strong>Recurring Invoices</strong> - Set up automatic recurring billing
358 </li>
359 <li style="margin-bottom: 12px; padding-left: 25px; position: relative;">
360 <span style="position: absolute; left: 0; color: #28a745;"></span>
361 <strong>Advanced Reporting</strong> - Detailed financial reports and analytics
362 </li>
363 <li style="margin-bottom: 12px; padding-left: 25px; position: relative;">
364 <span style="position: absolute; left: 0; color: #28a745;"></span>
365 <strong>Multiple Payment Gateways</strong> - Stripe, PayPal, and more
366 </li>
367 <li style="margin-bottom: 12px; padding-left: 25px; position: relative;">
368 <span style="position: absolute; left: 0; color: #28a745;"></span>
369 <strong>Invoice & Quote Builder</strong> - Advanced drag-and-drop builder
370 </li>
371 <li style="margin-bottom: 12px; padding-left: 25px; position: relative;">
372 <span style="position: absolute; left: 0; color: #28a745;"></span>
373 <strong>Priority Support</strong> - Faster response times for help
374 </li>
375 </ul>
376 </div>
377 </div>
378 <?php
379 }
380 }
381