PluginProbe
Forumax – AI Powered Advanced Community Forum Plugin / 2.4.3
Forumax – AI Powered Advanced Community Forum Plugin v2.4.3
2.4.4 2.4.3 2.4.2 2.4.1 2.4.0 trunk 1.0.8 1.1.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 2.0.0 2.1.0 All 29 releases
bbp-core / includes / admin / notices / offer.php

offer.php in Forumax – AI Powered Advanced Community Forum Plugin 2.4.3, at includes/admin/notices/offer.php

341 lines 10.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Forumax Pro Upgrade Offer Notice
4 *
5 * A premium upgrade notice with improved UI/UX, countdown timer,
6 * feature highlights, and conversion-optimized copywriting.
7 *
8 * @package Forumax
9 */
10
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit;
13 }
14
15 /**
16 * Get the number of forums created by the user
17 *
18 * @return int Number of forums
19 */
20 function frmx_get_forums_count() {
21 $forums = wp_count_posts( 'forum' );
22 return isset( $forums->publish ) ? (int) $forums->publish : 0;
23 }
24
25 /**
26 * Get personalized message based on user's usage
27 *
28 * @return array Message data with headline and subheadline
29 */
30 function frmx_get_personalized_message() {
31 $forums_count = frmx_get_forums_count();
32 $install_days = frmx_get_install_days();
33
34 // Personalized messaging based on usage
35 if ( $forums_count >= 10 ) {
36 return array(
37 'headline' => sprintf(
38 /* translators: %d: number of forums */
39 esc_html__( 'You\'ve created %d forums! Ready to supercharge your community?', 'forumax' ),
40 $forums_count
41 ),
42 'subheadline' => esc_html__( 'Unlock advanced features like Private Forums, User Badges & Role-based Access', 'forumax' ),
43 'cta' => esc_html__( 'Upgrade & Save 45%', 'forumax' ),
44 );
45 } elseif ( $install_days >= 30 ) {
46 return array(
47 'headline' => esc_html__( 'You\'ve been with us for a month! Here\'s a special thank you.', 'forumax' ),
48 'subheadline' => esc_html__( 'Get 45% off Forumax Pro as our way of saying thanks!', 'forumax' ),
49 'cta' => esc_html__( 'Claim Your Reward', 'forumax' ),
50 );
51 } else {
52 return array(
53 'headline' => esc_html__( 'Unlock the Full Power of Forumax', 'forumax' ),
54 'subheadline' => esc_html__( 'Join 3,000+ happy customers who upgraded to Pro', 'forumax' ),
55 'cta' => esc_html__( 'Get 45% Off Now', 'forumax' ),
56 );
57 }
58 }
59
60 /**
61 * Get the number of days since plugin installation
62 *
63 * @return int Number of days
64 */
65 function frmx_get_install_days() {
66 $installed_time = get_option( 'bbpc_installed' );
67 if ( ! $installed_time ) {
68 return 0;
69 }
70 return (int) floor( ( time() - $installed_time ) / DAY_IN_SECONDS );
71 }
72
73 /**
74 * Check if the notice should be shown based on snooze
75 *
76 * @return bool Whether to show the notice
77 */
78 function frmx_should_show_offer_notice() {
79 $user_id = get_current_user_id();
80 $snooze_until = get_user_meta( $user_id, 'bbpc_offer_snooze_until', true );
81
82 if ( $snooze_until && time() < (int) $snooze_until ) {
83 return false;
84 }
85
86 return true;
87 }
88
89 /**
90 * Display the upgrade offer notice
91 */
92 function forumax_offer_notice() {
93 $is_dev_mode = defined( 'DEVELOPER_MODE' ) && DEVELOPER_MODE;
94
95 if ( is_user_logged_in() && ! $is_dev_mode ) {
96 $user_id = get_current_user_id();
97 $dismissed = get_user_meta( $user_id, 'bbpc_offer_dismissed', true );
98
99 if ( '1' === $dismissed ) {
100 return;
101 }
102
103 if ( ! frmx_should_show_offer_notice() ) {
104 return;
105 }
106 }
107
108 $message = frmx_get_personalized_message();
109 $coupon_code = 'DASH45';
110 $pricing_url = 'https://forumax.spider-themes.net/pricing/';
111
112 // Pro features to highlight
113 $pro_features = array(
114 array(
115 'icon' => 'dashicons-chart-bar',
116 'title' => esc_html__( 'Advanced Analytics', 'forumax' ),
117 'desc' => esc_html__( 'Track forum activity, user engagement & content performance in real-time', 'forumax' ),
118 ),
119 array(
120 'icon' => 'dashicons-lock',
121 'title' => esc_html__( 'Access Control', 'forumax' ),
122 'desc' => esc_html__( 'Restrict forum access by user roles & membership levels', 'forumax' ),
123 ),
124 array(
125 'icon' => 'dashicons-groups',
126 'title' => esc_html__( 'Private Forums', 'forumax' ),
127 'desc' => esc_html__( 'Create exclusive private forums for specific user groups & teams', 'forumax' ),
128 ),
129 array(
130 'icon' => 'dashicons-awards',
131 'title' => esc_html__( 'User Badges', 'forumax' ),
132 'desc' => esc_html__( 'Reward active members with custom badges & reputation points', 'forumax' ),
133 ),
134 );
135 ?>
136 <div class="frmx-offer-notice" id="frmx-offer-notice">
137 <!-- Decorative Background Elements -->
138 <div class="frmx-offer-bg-pattern"></div>
139 <div class="frmx-offer-glow"></div>
140
141 <!-- Close & Snooze Buttons -->
142 <div class="frmx-offer-actions">
143 <button type="button" class="frmx-offer-snooze" data-action="snooze" title="<?php esc_attr_e( 'Remind me in 3 days', 'forumax' ); ?>">
144 <span class="dashicons dashicons-clock"></span>
145 <span class="frmx-offer-snooze-text"><?php esc_html_e( 'Later', 'forumax' ); ?></span>
146 </button>
147 <button type="button" class="frmx-offer-dismiss" data-action="dismiss" title="<?php esc_attr_e( 'Dismiss forever', 'forumax' ); ?>">
148 <span class="dashicons dashicons-no-alt"></span>
149 </button>
150 </div>
151
152 <div class="frmx-offer-container">
153 <!-- Left: Badge & Headline -->
154 <div class="frmx-offer-header">
155 <div class="frmx-offer-badge">
156 <span class="frmx-offer-badge-icon">🎉</span>
157 <span class="frmx-offer-badge-text"><?php esc_html_e( 'Limited Time Offer', 'forumax' ); ?></span>
158 </div>
159 <h3 class="frmx-offer-headline"><?php echo esc_html( $message['headline'] ); ?></h3>
160 <p class="frmx-offer-subheadline"><?php echo esc_html( $message['subheadline'] ); ?></p>
161 </div>
162
163 <!-- Center: Pro Features -->
164 <div class="frmx-offer-features">
165 <?php foreach ( $pro_features as $feature ) : ?>
166 <div class="frmx-offer-feature">
167 <span class="dashicons <?php echo esc_attr( $feature['icon'] ); ?>"></span>
168 <div class="frmx-offer-feature-text">
169 <strong><?php echo esc_html( $feature['title'] ); ?></strong>
170 <span><?php echo esc_html( $feature['desc'] ); ?></span>
171 </div>
172 </div>
173 <?php endforeach; ?>
174 </div>
175
176 <!-- Right: Discount & CTA -->
177 <div class="frmx-offer-cta-section">
178 <div class="frmx-offer-discount">
179 <span class="frmx-offer-discount-value">45%</span>
180 <span class="frmx-offer-discount-label"><?php esc_html_e( 'OFF', 'forumax' ); ?></span>
181 </div>
182
183 <div class="frmx-offer-coupon">
184 <span class="frmx-offer-coupon-label"><?php esc_html_e( 'Use code:', 'forumax' ); ?></span>
185 <div class="frmx-offer-coupon-box">
186 <code class="frmx-offer-coupon-code" id="frmx-coupon-code"><?php echo esc_html( $coupon_code ); ?></code>
187 <button type="button" class="frmx-offer-copy-btn" id="frmx-copy-btn" title="<?php esc_attr_e( 'Copy coupon code', 'forumax' ); ?>">
188 <span class="dashicons dashicons-admin-page"></span>
189 </button>
190 <span class="frmx-offer-copy-success" id="frmx-copy-success">
191 <span class="dashicons dashicons-yes-alt"></span>
192 <?php esc_html_e( 'Copied!', 'forumax' ); ?>
193 </span>
194 </div>
195 </div>
196
197 <a href="<?php echo esc_url( add_query_arg( 'coupon', $coupon_code, $pricing_url ) ); ?>"
198 class="frmx-offer-cta-btn"
199 target="_blank"
200 rel="noopener noreferrer">
201 <?php echo esc_html( $message['cta'] ); ?>
202 <span class="dashicons dashicons-arrow-right-alt"></span>
203 </a>
204
205 <p class="frmx-offer-guarantee">
206 <span class="dashicons dashicons-shield"></span>
207 <?php esc_html_e( '30-day money-back guarantee', 'forumax' ); ?>
208 </p>
209 </div>
210 </div>
211 </div>
212
213 <script>
214 document.addEventListener('DOMContentLoaded', function() {
215 const notice = document.getElementById('frmx-offer-notice');
216 const copyBtn = document.getElementById('frmx-copy-btn');
217 const couponCode = document.getElementById('frmx-coupon-code');
218 const copySuccess = document.getElementById('frmx-copy-success');
219 const snoozeBtn = notice.querySelector('.frmx-offer-snooze');
220 const dismissBtn = notice.querySelector('.frmx-offer-dismiss');
221
222 // Copy coupon code
223 if (copyBtn && couponCode) {
224 copyBtn.addEventListener('click', function() {
225 /**
226 * Copy text to clipboard with fallback
227 *
228 * navigator.clipboard API requires HTTPS (secure context).
229 * On HTTP local sites it is undefined, so we must check
230 * before calling and use execCommand fallback otherwise.
231 */
232 function copyToClipboard(text) {
233 var textArea = document.createElement('textarea');
234 textArea.value = text;
235 textArea.style.position = 'fixed';
236 textArea.style.left = '-9999px';
237 document.body.appendChild(textArea);
238 textArea.select();
239 document.execCommand('copy');
240 document.body.removeChild(textArea);
241 }
242
243 function showCopyFeedback() {
244 copySuccess.classList.add('show');
245 copyBtn.classList.add('copied');
246 setTimeout(function() {
247 copySuccess.classList.remove('show');
248 copyBtn.classList.remove('copied');
249 }, 2000);
250 }
251
252 if (navigator.clipboard && window.isSecureContext) {
253 navigator.clipboard.writeText(couponCode.textContent).then(function() {
254 showCopyFeedback();
255 }).catch(function() {
256 copyToClipboard(couponCode.textContent);
257 showCopyFeedback();
258 });
259 } else {
260 copyToClipboard(couponCode.textContent);
261 showCopyFeedback();
262 }
263 });
264 }
265
266 // Handle dismiss/snooze actions
267 function handleAction(action) {
268 notice.style.opacity = '0';
269 notice.style.transform = 'translateY(-20px)';
270
271 setTimeout(function() {
272 notice.style.display = 'none';
273 }, 300);
274
275 fetch('<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>', {
276 method: 'POST',
277 credentials: 'same-origin',
278 headers: {
279 'Content-Type': 'application/x-www-form-urlencoded'
280 },
281 body: 'action=bbpc_handle_offer_notice&notice_action=' + action + '&nonce=<?php echo esc_js( wp_create_nonce( 'bbpc-offer-notice' ) ); ?>'
282 });
283 }
284
285 if (snoozeBtn) {
286 snoozeBtn.addEventListener('click', function() {
287 handleAction('snooze');
288 });
289 }
290
291 if (dismissBtn) {
292 dismissBtn.addEventListener('click', function() {
293 handleAction('dismiss');
294 });
295 }
296
297 // Animate in on load
298 setTimeout(function() {
299 notice.classList.add('frmx-offer-visible');
300 }, 100);
301 });
302 </script>
303 <?php
304 }
305
306 /**
307 * Handle offer notice AJAX actions (dismiss/snooze)
308 */
309 add_action( 'wp_ajax_bbpc_handle_offer_notice', 'forumax_handle_offer_notice_ajax' );
310
311 /**
312 * Process the dismiss or snooze action
313 */
314 function forumax_handle_offer_notice_ajax() {
315 check_ajax_referer( 'bbpc-offer-notice', 'nonce' );
316
317 if ( ! is_user_logged_in() ) {
318 wp_send_json_error( array( 'message' => 'User not logged in.' ) );
319 }
320
321 $user_id = get_current_user_id();
322 $action = isset( $_POST['notice_action'] ) ? sanitize_text_field( wp_unslash( $_POST['notice_action'] ) ) : '';
323
324 if ( 'dismiss' === $action ) {
325 update_user_meta( $user_id, 'bbpc_offer_dismissed', '1' );
326 wp_send_json_success( array( 'message' => 'Notice dismissed permanently.' ) );
327 } elseif ( 'snooze' === $action ) {
328 // Snooze for 3 days
329 $snooze_until = time() + ( 3 * DAY_IN_SECONDS );
330 update_user_meta( $user_id, 'bbpc_offer_snooze_until', $snooze_until );
331 wp_send_json_success( array( 'message' => 'Notice snoozed for 3 days.' ) );
332 } else {
333 wp_send_json_error( array( 'message' => 'Invalid action.' ) );
334 }
335
336 wp_die();
337 }
338
339 // Keep backward compatibility - remove old action if it exists
340 remove_action( 'wp_ajax_bbpc_dismiss_offer_notice', 'forumax_dismiss_offer_notice' );
341