| 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 |
$general_settings = get_option('_wpfunnels_general_settings', []); |
| 142 |
$funnel_type = isset($general_settings['funnel_type']) ? $general_settings['funnel_type'] : 'sales'; |
| 143 |
|
| 144 |
if ('lead' === $funnel_type) { |
| 145 |
$banner_title = esc_html__('Let’s launch your first lead funnel in 5 minutes!', 'wpfnl'); |
| 146 |
$banner_description = esc_html__('Finish setting up your first lead funnel and start collecting more leads with better conversions.', 'wpfnl'); |
| 147 |
} else { |
| 148 |
$banner_title = esc_html__('Let’s launch your first WooCommerce funnel in 5 minutes!', 'wpfnl'); |
| 149 |
$banner_description = esc_html__('Finish setting up your first funnel and start increasing your WooCommerce revenue with upsells, order bumps & better conversions.', 'wpfnl'); |
| 150 |
} |
| 151 |
?> |
| 152 |
<div class="notice wpfnl-setup-reminder-notice" data-notice-id="<?php echo esc_attr($this->banner_id); ?>"> |
| 153 |
<div class="wpfnl-notice-icon"> |
| 154 |
<svg width="36" height="28" viewBox="0 0 38 28" fill="none" xmlns="http://www.w3.org/2000/svg"> |
| 155 |
<path d="M7.01532 18H31.9847L34 11H5L7.01532 18Z" fill="#EE8134"></path> |
| 156 |
<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> |
| 157 |
<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> |
| 158 |
</svg> |
| 159 |
</div> |
| 160 |
<div class="wpfnl-notice-content"> |
| 161 |
<h3 class="wpfnl-notice-title"><?php echo $banner_title; ?></h3> |
| 162 |
<p class="wpfnl-notice-description"><?php echo $banner_description; ?></p> |
| 163 |
<div class="wpfnl-notice-actions"> |
| 164 |
<a href="<?php echo esc_url($create_funnel_url); ?>" class="wpfnl-notice-btn wpfnl-notice-btn-primary"> |
| 165 |
<?php echo esc_html__('Resume setup', 'wpfnl'); ?> |
| 166 |
</a> |
| 167 |
<a href="<?php echo esc_url($learn_more_url); ?>" class="wpfnl-notice-btn wpfnl-notice-btn-secondary" target="_blank"> |
| 168 |
<?php echo esc_html__('Show me how', 'wpfnl'); ?> |
| 169 |
</a> |
| 170 |
</div> |
| 171 |
</div> |
| 172 |
<button type="button" class="wpfnl-notice-dismiss" aria-label="<?php echo esc_attr__('Dismiss this notice', 'wpfnl'); ?>"> |
| 173 |
<span class="dashicons dashicons-no-alt"></span> |
| 174 |
</button> |
| 175 |
</div> |
| 176 |
|
| 177 |
<script> |
| 178 |
jQuery(document).ready(function($) { |
| 179 |
$(document).on('click', '.wpfnl-notice-dismiss', function() { |
| 180 |
$(this).closest('.wpfnl-setup-reminder-notice').fadeOut(200); |
| 181 |
wp.ajax.send('dismiss_first_funnel_setup_reminder_banner', { |
| 182 |
data: { |
| 183 |
nonce: '<?php echo esc_js($dismiss_nonce); ?>', |
| 184 |
payload: {} |
| 185 |
} |
| 186 |
}); |
| 187 |
}); |
| 188 |
}); |
| 189 |
</script> |
| 190 |
<?php |
| 191 |
} |
| 192 |
|
| 193 |
/** |
| 194 |
* Adds internal CSS styles for the setup reminder banner. |
| 195 |
* |
| 196 |
* @since 3.9.3 |
| 197 |
*/ |
| 198 |
public function add_styles() |
| 199 |
{ |
| 200 |
// Only add styles if banner should be shown |
| 201 |
if (!$this->should_show_banner()) { |
| 202 |
return; |
| 203 |
} |
| 204 |
?> |
| 205 |
<style type="text/css"> |
| 206 |
.notice.wpfnl-setup-reminder-notice { |
| 207 |
display: flex; |
| 208 |
align-items: flex-start; |
| 209 |
gap: 16px; |
| 210 |
background: #fff; |
| 211 |
border: 1px solid #e0e0e0; |
| 212 |
border-left: 4px solid #6E42D3; |
| 213 |
border-radius: 4px; |
| 214 |
padding: 16px 20px; |
| 215 |
margin: 5px 0 15px; |
| 216 |
position: relative; |
| 217 |
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04); |
| 218 |
} |
| 219 |
|
| 220 |
.wpfnl-setup-reminder-notice .wpfnl-notice-icon { |
| 221 |
flex-shrink: 0; |
| 222 |
width: 40px; |
| 223 |
height: 40px; |
| 224 |
display: flex; |
| 225 |
align-items: center; |
| 226 |
justify-content: center; |
| 227 |
} |
| 228 |
|
| 229 |
.wpfnl-setup-reminder-notice .wpfnl-notice-icon svg { |
| 230 |
width: 36px; |
| 231 |
height: auto; |
| 232 |
} |
| 233 |
|
| 234 |
.wpfnl-setup-reminder-notice .wpfnl-notice-content { |
| 235 |
flex: 1; |
| 236 |
} |
| 237 |
|
| 238 |
.wpfnl-setup-reminder-notice .wpfnl-notice-title { |
| 239 |
font-size: 14px; |
| 240 |
font-weight: 600; |
| 241 |
color: #1e1e1e; |
| 242 |
margin: 0 0 4px 0; |
| 243 |
padding: 0; |
| 244 |
line-height: 1.4; |
| 245 |
} |
| 246 |
|
| 247 |
.wpfnl-setup-reminder-notice .wpfnl-notice-description { |
| 248 |
font-size: 13px; |
| 249 |
color: #50575e; |
| 250 |
margin: 0 0 12px 0; |
| 251 |
padding: 0; |
| 252 |
line-height: 1.5; |
| 253 |
} |
| 254 |
|
| 255 |
.wpfnl-setup-reminder-notice .wpfnl-notice-actions { |
| 256 |
display: flex; |
| 257 |
gap: 10px; |
| 258 |
flex-wrap: wrap; |
| 259 |
} |
| 260 |
|
| 261 |
.wpfnl-setup-reminder-notice .wpfnl-notice-btn { |
| 262 |
display: inline-flex; |
| 263 |
align-items: center; |
| 264 |
padding: 8px 16px; |
| 265 |
font-size: 13px; |
| 266 |
font-weight: 500; |
| 267 |
line-height: 1; |
| 268 |
text-decoration: none; |
| 269 |
border-radius: 4px; |
| 270 |
cursor: pointer; |
| 271 |
transition: all 0.2s ease; |
| 272 |
} |
| 273 |
|
| 274 |
.wpfnl-setup-reminder-notice .wpfnl-notice-btn-primary { |
| 275 |
background: #6E42D3; |
| 276 |
color: #fff; |
| 277 |
border: 1px solid #6E42D3; |
| 278 |
} |
| 279 |
|
| 280 |
.wpfnl-setup-reminder-notice .wpfnl-notice-btn-primary:hover { |
| 281 |
background: #5a35b0; |
| 282 |
border-color: #5a35b0; |
| 283 |
color: #fff; |
| 284 |
} |
| 285 |
|
| 286 |
.wpfnl-setup-reminder-notice .wpfnl-notice-btn-secondary { |
| 287 |
background: #fff; |
| 288 |
color: #6E42D3; |
| 289 |
border: 1px solid #6E42D3; |
| 290 |
} |
| 291 |
|
| 292 |
.wpfnl-setup-reminder-notice .wpfnl-notice-btn-secondary:hover { |
| 293 |
background: #f3f0fa; |
| 294 |
color: #5a35b0; |
| 295 |
} |
| 296 |
|
| 297 |
.wpfnl-setup-reminder-notice .wpfnl-notice-dismiss { |
| 298 |
position: absolute; |
| 299 |
top: 12px; |
| 300 |
right: 12px; |
| 301 |
background: none; |
| 302 |
border: none; |
| 303 |
padding: 0; |
| 304 |
cursor: pointer; |
| 305 |
color: #787c82; |
| 306 |
line-height: 1; |
| 307 |
} |
| 308 |
|
| 309 |
.wpfnl-setup-reminder-notice .wpfnl-notice-dismiss:hover { |
| 310 |
color: #1e1e1e; |
| 311 |
} |
| 312 |
|
| 313 |
.wpfnl-setup-reminder-notice .wpfnl-notice-dismiss .dashicons { |
| 314 |
font-size: 20px; |
| 315 |
width: 20px; |
| 316 |
height: 20px; |
| 317 |
} |
| 318 |
|
| 319 |
@media screen and (max-width: 782px) { |
| 320 |
.wpfnl-setup-reminder-notice { |
| 321 |
flex-direction: column; |
| 322 |
gap: 12px; |
| 323 |
margin: 10px; |
| 324 |
} |
| 325 |
|
| 326 |
.wpfnl-setup-reminder-notice .wpfnl-notice-actions { |
| 327 |
flex-direction: column; |
| 328 |
} |
| 329 |
|
| 330 |
.wpfnl-setup-reminder-notice .wpfnl-notice-btn { |
| 331 |
justify-content: center; |
| 332 |
} |
| 333 |
} |
| 334 |
</style> |
| 335 |
<?php |
| 336 |
} |
| 337 |
|
| 338 |
/** |
| 339 |
* AJAX handler to dismiss the banner. |
| 340 |
* |
| 341 |
* @param array $payload The AJAX payload. |
| 342 |
* @return array |
| 343 |
* @since 3.9.3 |
| 344 |
*/ |
| 345 |
public function dismiss_banner($payload) |
| 346 |
{ |
| 347 |
update_option($this->dismiss_option_key, 'yes'); |
| 348 |
return [ |
| 349 |
'success' => true, |
| 350 |
]; |
| 351 |
} |
| 352 |
} |
| 353 |
|