PluginProbe
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell / 3.13.2
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell v3.13.2
3.13.3 3.13.2 3.13.1 3.13.0 3.12.13 3.12.12 3.12.11 3.12.10 3.12.9 3.12.8 3.12.7 3.12.6 3.12.5 3.12.4 3.12.3 3.12.1 3.12.2 3.12.0 3.11.1 3.11.0 3.10.9 3.10.8 3.10.7 3.10.6 2.8.16 All 261 releases
wpfunnels / admin / class-wpfnl-setup-banner.php

class-wpfnl-setup-banner.php in WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell 3.13.2, at admin/class-wpfnl-setup-banner.php

350 lines 11.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WPFunnels\Admin\Banner;
4
5 /**
6 * SetupReminderBanner Class
7 *
8 * This class is responsible for displaying setup reminder banners in the WordPress admin
9 * based on user behavior events such as plugin installation without funnel creation.
10 *
11 * @package WPFunnels\Admin\Banner
12 * @since 3.9.3
13 */
14 class SetupReminderBanner{
15 /**
16 * The banner identifier.
17 *
18 * @var string
19 */
20 private $banner_id;
21
22 /**
23 * The option key for dismissing the banner.
24 *
25 * @var string
26 */
27 private $dismiss_option_key;
28
29 /**
30 * Hours to wait before showing the banner.
31 *
32 * @var int
33 */
34 private $hours_delay;
35
36 /**
37 * Constructor method for SetupReminderBanner class.
38 *
39 * @since 3.9.3
40 */
41 public function __construct()
42 {
43 $this->banner_id = 'no_funnel_48h';
44 $this->dismiss_option_key = '_wpfnl_dismiss_no_funnel_banner';
45 $this->hours_delay = 48;
46
47 // Register hooks - actual condition check happens in display_banner
48 add_action('admin_notices', [$this, 'display_banner']);
49 add_action('admin_head', [$this, 'add_styles']);
50
51 // Register AJAX handler for dismissing the banner
52 $validations = [
53 'logged_in' => true,
54 'user_can' => 'wpf_manage_funnels',
55 ];
56
57 wp_ajax_helper()->handle('dismiss_first_funnel_setup_reminder_banner')
58 ->with_callback([$this, 'dismiss_banner'])
59 ->with_validation($validations);
60 }
61
62 /**
63 * Check if the banner should be displayed.
64 *
65 * Conditions:
66 * 1. Banner has not been dismissed
67 * 2. At least 48 hours have passed since installation
68 * 3. No funnels have been created
69 *
70 * @return bool
71 * @since 3.9.3
72 */
73 private function should_show_banner(){
74 // Check if banner was dismissed
75 if ('yes' === get_option($this->dismiss_option_key, 'no')) {
76 return false;
77 }
78
79 // Check if 48 hours have passed since installation
80 $installed_time = get_option('wpfunnels_installed_time', 0);
81 if (!$installed_time) {
82 return false;
83 }
84
85 $hours_since_install = (time() - $installed_time) / 3600;
86 if ($hours_since_install < $this->hours_delay) {
87 return false;
88 }
89
90 // Check if any funnels exist
91 $funnel_count = $this->get_funnel_count();
92 if ($funnel_count > 0) {
93 return false;
94 }
95
96 return true;
97 }
98
99 /**
100 * Get the total count of funnels.
101 *
102 * @return int
103 * @since 3.9.3
104 */
105 private function get_funnel_count()
106 {
107 $counts = wp_count_posts('wpfunnels');
108 return (int) $counts->publish + (int) $counts->draft;
109 }
110
111 /**
112 * Displays the setup reminder banner.
113 *
114 * @since 3.9.3
115 */
116 public function display_banner(){
117 // Check conditions before displaying
118 if (!$this->should_show_banner()) {
119 return;
120 }
121
122 $screen = get_current_screen();
123 // Pages where the banner should NOT be displayed
124 $disabled_notice_pages = array(
125 'toplevel_page_wpfunnels',
126 'wpfunnels_page_wpfnl_settings',
127 'wpfunnels_page_wp_funnels',
128 'wpfunnels_page_wpf_templates',
129 'wpfunnels_page_trash_funnels',
130 );
131
132 if (in_array($screen->id, $disabled_notice_pages)) {
133 return;
134 }
135
136 // Get the URL to create a new funnel
137 $create_funnel_url = admin_url('admin.php?page=wp_funnels');
138 $learn_more_url = 'https://getwpfunnels.com/docs/getting-started-with-wpfunnels/create-your-first-sales-funnel/';
139 $dismiss_nonce = wp_create_nonce('dismiss_first_funnel_setup_reminder_banner');
140
141 if (!\WPFunnels\Wpfnl_functions::is_wc_active()) {
142 $banner_title = esc_html__('Let’s launch your first lead funnel in 5 minutes!', 'wpfnl');
143 $banner_description = esc_html__('Finish setting up your first lead funnel and start collecting more leads with better conversions.', 'wpfnl');
144 } else {
145 $banner_title = esc_html__('Let’s launch your first WooCommerce funnel in 5 minutes!', 'wpfnl');
146 $banner_description = esc_html__('Finish setting up your first funnel and start increasing your WooCommerce revenue with upsells, order bumps & better conversions.', 'wpfnl');
147 }
148 ?>
149 <div class="notice wpfnl-setup-reminder-notice" data-notice-id="<?php echo esc_attr($this->banner_id); ?>">
150 <div class="wpfnl-notice-icon">
151 <svg width="36" height="28" viewBox="0 0 38 28" fill="none" xmlns="http://www.w3.org/2000/svg">
152 <path d="M7.01532 18H31.9847L34 11H5L7.01532 18Z" fill="#EE8134"></path>
153 <path d="M11.9621 27.2975C12.0923 27.7154 12.4792 28 12.9169 28H26.0831C26.5208 28 26.9077 27.7154 27.0379 27.2975L29 21H10L11.9621 27.2975Z" fill="#6E42D3"></path>
154 <path d="M37.8161 0.65986C37.61 0.247888 37.2609 0 36.8867 0H1.11326C0.739128 0 0.390003 0.247888 0.183972 0.65986C-0.0220592 1.07193 -0.0573873 1.59277 0.0898627 2.04655L1.69781 7H36.3022L37.9102 2.04655C38.0574 1.59287 38.022 1.07193 37.8161 0.65986Z" fill="#6E42D3"></path>
155 </svg>
156 </div>
157 <div class="wpfnl-notice-content">
158 <h3 class="wpfnl-notice-title"><?php echo $banner_title; ?></h3>
159 <p class="wpfnl-notice-description"><?php echo $banner_description; ?></p>
160 <div class="wpfnl-notice-actions">
161 <a href="<?php echo esc_url($create_funnel_url); ?>" class="wpfnl-notice-btn wpfnl-notice-btn-primary">
162 <?php echo esc_html__('Resume setup', 'wpfnl'); ?>
163 </a>
164 <a href="<?php echo esc_url($learn_more_url); ?>" class="wpfnl-notice-btn wpfnl-notice-btn-secondary" target="_blank">
165 <?php echo esc_html__('Show me how', 'wpfnl'); ?>
166 </a>
167 </div>
168 </div>
169 <button type="button" class="wpfnl-notice-dismiss" aria-label="<?php echo esc_attr__('Dismiss this notice', 'wpfnl'); ?>">
170 <span class="dashicons dashicons-no-alt"></span>
171 </button>
172 </div>
173
174 <script>
175 jQuery(document).ready(function($) {
176 $(document).on('click', '.wpfnl-notice-dismiss', function() {
177 $(this).closest('.wpfnl-setup-reminder-notice').fadeOut(200);
178 wp.ajax.send('dismiss_first_funnel_setup_reminder_banner', {
179 data: {
180 nonce: '<?php echo esc_js($dismiss_nonce); ?>',
181 payload: {}
182 }
183 });
184 });
185 });
186 </script>
187 <?php
188 }
189
190 /**
191 * Adds internal CSS styles for the setup reminder banner.
192 *
193 * @since 3.9.3
194 */
195 public function add_styles()
196 {
197 // Only add styles if banner should be shown
198 if (!$this->should_show_banner()) {
199 return;
200 }
201 ?>
202 <style type="text/css">
203 .notice.wpfnl-setup-reminder-notice {
204 display: flex;
205 align-items: flex-start;
206 gap: 16px;
207 background: #fff;
208 border: 1px solid #e0e0e0;
209 border-left: 4px solid #6E42D3;
210 border-radius: 4px;
211 padding: 16px 20px;
212 margin: 5px 0 15px;
213 position: relative;
214 box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
215 }
216
217 .wpfnl-setup-reminder-notice .wpfnl-notice-icon {
218 flex-shrink: 0;
219 width: 40px;
220 height: 40px;
221 display: flex;
222 align-items: center;
223 justify-content: center;
224 }
225
226 .wpfnl-setup-reminder-notice .wpfnl-notice-icon svg {
227 width: 36px;
228 height: auto;
229 }
230
231 .wpfnl-setup-reminder-notice .wpfnl-notice-content {
232 flex: 1;
233 }
234
235 .wpfnl-setup-reminder-notice .wpfnl-notice-title {
236 font-size: 14px;
237 font-weight: 600;
238 color: #1e1e1e;
239 margin: 0 0 4px 0;
240 padding: 0;
241 line-height: 1.4;
242 }
243
244 .wpfnl-setup-reminder-notice .wpfnl-notice-description {
245 font-size: 13px;
246 color: #50575e;
247 margin: 0 0 12px 0;
248 padding: 0;
249 line-height: 1.5;
250 }
251
252 .wpfnl-setup-reminder-notice .wpfnl-notice-actions {
253 display: flex;
254 gap: 10px;
255 flex-wrap: wrap;
256 }
257
258 .wpfnl-setup-reminder-notice .wpfnl-notice-btn {
259 display: inline-flex;
260 align-items: center;
261 padding: 8px 16px;
262 font-size: 13px;
263 font-weight: 500;
264 line-height: 1;
265 text-decoration: none;
266 border-radius: 4px;
267 cursor: pointer;
268 transition: all 0.2s ease;
269 }
270
271 .wpfnl-setup-reminder-notice .wpfnl-notice-btn-primary {
272 background: #6E42D3;
273 color: #fff;
274 border: 1px solid #6E42D3;
275 }
276
277 .wpfnl-setup-reminder-notice .wpfnl-notice-btn-primary:hover {
278 background: #5a35b0;
279 border-color: #5a35b0;
280 color: #fff;
281 }
282
283 .wpfnl-setup-reminder-notice .wpfnl-notice-btn-secondary {
284 background: #fff;
285 color: #6E42D3;
286 border: 1px solid #6E42D3;
287 }
288
289 .wpfnl-setup-reminder-notice .wpfnl-notice-btn-secondary:hover {
290 background: #f3f0fa;
291 color: #5a35b0;
292 }
293
294 .wpfnl-setup-reminder-notice .wpfnl-notice-dismiss {
295 position: absolute;
296 top: 12px;
297 right: 12px;
298 background: none;
299 border: none;
300 padding: 0;
301 cursor: pointer;
302 color: #787c82;
303 line-height: 1;
304 }
305
306 .wpfnl-setup-reminder-notice .wpfnl-notice-dismiss:hover {
307 color: #1e1e1e;
308 }
309
310 .wpfnl-setup-reminder-notice .wpfnl-notice-dismiss .dashicons {
311 font-size: 20px;
312 width: 20px;
313 height: 20px;
314 }
315
316 @media screen and (max-width: 782px) {
317 .wpfnl-setup-reminder-notice {
318 flex-direction: column;
319 gap: 12px;
320 margin: 10px;
321 }
322
323 .wpfnl-setup-reminder-notice .wpfnl-notice-actions {
324 flex-direction: column;
325 }
326
327 .wpfnl-setup-reminder-notice .wpfnl-notice-btn {
328 justify-content: center;
329 }
330 }
331 </style>
332 <?php
333 }
334
335 /**
336 * AJAX handler to dismiss the banner.
337 *
338 * @param array $payload The AJAX payload.
339 * @return array
340 * @since 3.9.3
341 */
342 public function dismiss_banner($payload)
343 {
344 update_option($this->dismiss_option_key, 'yes');
345 return [
346 'success' => true,
347 ];
348 }
349 }
350