PluginProbe
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell / 3.13.0
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell v3.13.0
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-notices.php

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

598 lines 21.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * WPFunnels otics class
4 *
5 * @package
6 */
7
8 namespace WPFunnels\Admin\Notices;
9 use WPFunnels\Wpfnl_functions;
10
11 class Notice {
12
13 /**
14 * Stores notices.
15 *
16 * @var array
17 */
18 private static $notices = array();
19
20 /**
21 * Array of notices - name => callback.
22 *
23 * @var array
24 */
25 private static $core_notices = array(
26 'oxygen_capability' => 'oxygen_capability_notice',
27 'pro_compatability' => 'pro_compatability_notice',
28 'abtesing_pro_compatability' => 'abtesing_pro_compatability',
29 'gbf_compatability' => 'gbf_compatability_notice',
30 );
31
32 public function __construct() {
33 $validations = [
34 'logged_in' => true,
35 'user_can' => 'wpf_manage_funnels',
36 ];
37
38 add_action('admin_notices', [$this, 'show_admin_notices']);
39 add_filter( 'wpfunnels/funnel_window_admin_localize', array( $this, 'notice_for_oxygen_builder_compatibility' ) );
40 add_action( 'admin_head', array( $this,'hide_update_notice_on_builder' ), 1 );
41
42 wp_ajax_helper()->handle('wpfunnels-activate-plugin')
43 ->with_callback([$this, 'activate_plugin'])
44 ->with_validation($validations);
45
46 wp_ajax_helper()->handle('delete_promotional_banner')
47 ->with_callback([ $this, 'wpfnl_delete_promotional_banner' ])
48 ->with_validation($validations);
49
50 wp_ajax_helper()->handle('delete_new_ui_notice')
51 ->with_callback([ $this, 'wpfnl_delete_new_ui_notice' ])
52 ->with_validation($validations);
53 }
54
55 /**
56 * Get notices
57 *
58 * @return array
59 */
60 public static function get_notices() {
61 return apply_filters( 'wpfnl_notices', self::$core_notices );
62 }
63
64
65 public function show_admin_notices() {
66 foreach ( self::get_notices() as $namespace => $callback_function ) {
67 if( strpos( $namespace, '\\' ) ) {
68 $namespace::$callback_function();
69 }else {
70 self::$callback_function();
71 }
72 }
73
74 }
75
76
77 /**
78 * Print admin notices
79 *
80 * @param $options
81 *
82 * @return bool
83 * @since 2.0.0
84 */
85 public static function print_notice($options) {
86 if ( ! current_user_can( 'wpf_manage_funnels' ) ) {
87 return false;
88 }
89 $default_options = [
90 'id' => null,
91 'title' => '',
92 'description' => '',
93 'classes' => [ 'notice', 'wpfnl-notice' ], // We include WP's default notice class so it will be properly handled by WP's js handler
94 'type' => '',
95 'dismissible' => true,
96 'icon' => '',
97 'button' => [],
98 'button_secondary' => [],
99 ];
100 $options = array_replace_recursive( $default_options, $options );
101 $classes = $options['classes'];
102 if ( $options['dismissible'] ) {
103 $classes[] = 'is-dismissible';
104 }
105
106 if ( $options['type'] ) {
107 $classes[] = 'wpfnl-notice--' . $options['type'];
108 }
109
110 $wrapper_attributes = [
111 'class' => $classes,
112 ];
113 if ( $options['id'] ) {
114 $wrapper_attributes['data-notice_id'] = $options['id'];
115 }
116 ?>
117 <div <?php echo self::render_html_attributes( $wrapper_attributes ); ?> >
118 <div class="wpfnl-notice__content">
119 <?php if ( $options['description'] ) { ?>
120 <p><?php
121 echo $options['description'];
122 ?>
123 </p>
124 <!-- <p class="wpfnl-notice-message"></p> -->
125 <div class="wpfnl-notice__actions">
126 <?php
127 foreach ( $options['button'] as $index => $button_settings ) {
128 if ( empty( $button_settings['text'] ) ) {
129 continue;
130 }
131 self::print_button( $button_settings );
132 } ?>
133 </div>
134 <?php } ?>
135 </div>
136 </div>
137 <?php }
138
139
140 /**
141 * Show plugin dependency notices for elementor
142 */
143 public static function elementor_dependency_notice() {
144 $settings = Wpfnl_functions::get_general_settings();
145 if ($settings['builder']== 'elementor') {
146 $plugin = 'elementor/elementor.php';
147 $show_notice_info = self::should_show_plugin_dependency_notice($plugin, 'elementor', "Elementor");
148 $status = $show_notice_info['action'] === 'inactive' ? 'inactive' : 'not installed';
149 $action = $show_notice_info['action'] === 'inactive' ? 'activate' : 'install';
150 if($show_notice_info['show_notice']) {
151 $text = sprintf( __( "It seems Elementor is %1s on your site. As you have selected Elementor as builder option, you need to %2s Elementor.", "wpfnl" ), $status, $action ); // phpcs:ignore
152 $options = array(
153 'id' => 'elementor',
154 'title' => 'Elementor',
155 'description' => $text,
156 'classes' => [ 'notice', 'wpfnl-notice' ], // We include WP's default notice class so it will be properly handled by WP's js handler
157 'type' => 'install-plugin',
158 'dismissible' => true,
159 'icon' => '',
160 'slug' => $plugin,
161 'button' => array(
162 array(
163 'classes' => [ "wpfnl-notice-button", sprintf( __( "wpfnl-%s-plugin","wpfnl" ), $action ) ], // phpcs:ignore
164 'icon' => '',
165 'new_tab' => false,
166 'text' => $show_notice_info['action_label'],
167 'type' => '',
168 'url' => $show_notice_info['action_url'],
169 'variant' => '',
170 'before' => '',
171 'data-slug' => 'elementor',
172 'id' => 'wpfnl-'.$action.'-plugin'
173 )
174 ),
175 'button_secondary' => [],
176 );
177 self::print_notice($options);
178 }
179 }
180 }
181
182
183 /**
184 * Show plugin dependency notices for WooCommerce
185 */
186 public static function woocommerce_dependency_notice() {
187 $settings = Wpfnl_functions::get_general_settings();
188
189 $plugin = 'woocommerce/woocommerce.php';
190 $show_notice_info = self::should_show_plugin_dependency_notice($plugin, 'woocommerce', "WooCommerce");
191 $status = $show_notice_info['action'] === 'inactive' ? 'inactive' : 'not installed';
192 $action = $show_notice_info['action'] === 'inactive' ? 'activate' : 'install';
193
194 if($show_notice_info['show_notice']) {
195 $text = sprintf( __( "Opps.. Looks like WooCommerce is not activated on your website. WPFunnels requires WooCommerce to work properly. Please %s WooCommerce if you want to continue creating sales funnels using WPFunnels.", "wpfnl" ), $action ); // phpcs:ignore
196 $options = array(
197 'id' => 'woocommerce',
198 'title' => 'WooCommerce',
199 'description' => $text,
200 'classes' => [ 'notice', 'wpfnl-notice' ], // We include WP's default notice class so it will be properly handled by WP's js handler
201 'type' => 'install-plugin',
202 'dismissible' => true,
203 'icon' => '',
204 'slug' => $plugin,
205 'button' => array(
206 array(
207 'classes' => [ 'wpfnl-notice-button', sprintf( __( "wpfnl-%s-plugin","wpfnl" ), $action ) ], // phpcs:ignore
208 'icon' => '',
209 'new_tab' => false,
210 'text' => $show_notice_info['action_label'],
211 'type' => '',
212 'url' => $show_notice_info['action_url'],
213 'variant' => '',
214 'before' => '',
215 'data-slug' => 'woocommerce',
216 'id' => 'wpfnl-'.$action.'-plugin'
217 )
218 ),
219 'button_secondary' => [],
220 );
221 self::print_notice($options);
222 }
223 }
224
225 /**
226 * Show Plugin dependency notices for Guternburg
227 */
228 public static function gutenberg_dependency_notice() {
229 $settings = Wpfnl_functions::get_general_settings();
230 if ($settings['builder']== 'gutenberg') {
231 $plugin = 'qubely/qubely.php';
232 $show_notice_info = self::should_show_plugin_dependency_notice( $plugin, 'qubely', "Qubely" );
233 $status = $show_notice_info['action'] === 'inactive' ? 'inactive' : 'not installed';
234 $action = $show_notice_info['action'] === 'inactive' ? 'activate' : 'install';
235
236 if($show_notice_info['show_notice']) {
237 $text = sprintf( __( "It seems Qubely is %1s on your site. As you have selected Gutenberg as builder option, you need to %2s Qubely.", "wpfnl" ), $status, $action ); // phpcs:ignore
238 $options = array(
239 'id' => 'qubely',
240 'title' => 'Qubely',
241 'description' => $text,
242 'classes' => [ 'notice', 'wpfnl-notice' ], // We include WP's default notice class so it will be properly handled by WP's js handler
243 'type' => $action.'-plugin',
244 'dismissible' => true,
245 'icon' => '',
246 'slug' => $plugin,
247 'button' => array(
248 array(
249 'classes' => [ "wpfnl-notice-button", sprintf( __( "wpfnl-%s-plugin", "wpfnl" ), $action ) ], // phpcs:ignore
250 'icon' => '',
251 'new_tab' => false,
252 'text' => $show_notice_info['action_label'],
253 'type' => '',
254 'url' => $show_notice_info['action_url'],
255 'variant' => '',
256 'before' => '',
257 )
258 ),
259 'button_secondary' => [],
260 );
261 self::print_notice($options);
262 }
263 }
264 }
265
266 /**
267 * Show plugin dependency notices for oxygen
268 */
269 public static function oxygen_capability_notice(){
270 global $current_screen;
271 $oxygen_complability = Wpfnl_functions::oxygen_builder_version_capability();
272 $is_oxygen_installed = Wpfnl_functions::is_plugin_installed('oxygen/functions.php');
273 $is_oxygen_active = Wpfnl_functions::is_plugin_activated('oxygen/functions.php');
274 if ( $is_oxygen_active && $is_oxygen_installed ){
275 if (($oxygen_complability === false && $current_screen->parent_base === 'plugins') || ($oxygen_complability === false && 'wp_funnels' === $current_screen->parent_base)){
276 $options = array(
277 'id' => 'oxygen',
278 'title' => 'Oxygen',
279 'description' => __("You are using an older version of Oxygen Builder, which is not compatible with WPFunnels. You will need Oxygen Builder v3.2 or above to be able to use it to design funnel pages in WPFunnels. Please update your builder.", 'wpfnl'),
280 'classes' => [ 'notice', 'wpfnl-notice' ], // We include WP's default notice class so it will be properly handled by WP's js handler
281 'type' => 'install-plugin',
282 'dismissible' => true,
283 'icon' => '',
284 );
285 self::print_notice($options);
286 }
287 }
288 return false;
289 }
290
291 /**
292 * Pro compatability notice for update version to 2.4.15 or higher. If someone wants to update, he/she has to install 1.6.12 or higher version of WPFunnels Pro
293 */
294 public static function pro_compatability_notice(){
295 global $current_screen;
296 $is_pro_active = Wpfnl_functions::is_plugin_activated('wpfunnels-pro/wpfnl-pro.php');
297 if ( $is_pro_active ){
298
299 if ( version_compare(WPFNL_VERSION, '3.0.0', '>=') && version_compare(WPFNL_PRO_VERSION, '2.0.0', '<') ) {
300 if ( 'plugins' === $current_screen->parent_base || 'wp_funnels' === $current_screen->parent_base ){
301 $options = array(
302 'id' => '',
303 'title' => 'wpfunnels-basic',
304 'description' => __("Please update the WPFunnels Pro to version 2.0.0 or higher to use New UI properly. Ignore if already updated.", 'wpfnl'),
305 'classes' => [ 'notice', 'wpfnl-notice' ], // We include WP's default notice class so it will be properly handled by WP's js handler
306 'type' => 'update-plugin',
307 'dismissible' => true,
308 'icon' => '',
309 );
310 self::print_notice($options);
311 }
312
313 }elseif ( version_compare(WPFNL_VERSION, '2.4.15', '>=') && version_compare(WPFNL_PRO_VERSION, '1.6.12', '<') ) {
314 if ( 'plugins' === $current_screen->parent_base || 'wp_funnels' === $current_screen->parent_base ){
315 $options = array(
316 'id' => '',
317 'title' => 'wpfunnels-basic',
318 'description' => __("Please update the WPFunnels Pro to version 1.0.12 or higher. Ignore if already updated.", 'wpfnl'),
319 'classes' => [ 'notice', 'wpfnl-notice' ], // We include WP's default notice class so it will be properly handled by WP's js handler
320 'type' => 'update-plugin',
321 'dismissible' => true,
322 'icon' => '',
323 );
324 self::print_notice($options);
325 }
326
327 }elseif ( version_compare(WPFNL_VERSION, '2.6.1', '>=') && version_compare(WPFNL_PRO_VERSION, '1.7.1', '<') ) {
328 if ( 'plugins' === $current_screen->parent_base || 'wp_funnels' === $current_screen->parent_base ){
329 $options = array(
330 'id' => '',
331 'title' => 'wpfunnels-basic',
332 'description' => __("Please update the WPFunnels Pro to version 1.7.1 or higher. Ignore if already updated.", 'wpfnl'),
333 'classes' => [ 'notice', 'wpfnl-notice' ], // We include WP's default notice class so it will be properly handled by WP's js handler
334 'type' => 'update-plugin',
335 'dismissible' => true,
336 'icon' => '',
337 );
338 self::print_notice($options);
339 }
340
341 }
342
343 }
344 return false;
345 }
346
347
348
349 /**
350 * Pro compatability notice for update version to 1.7.3 or higher. If someone wants to use AB tesing, then needs to update
351 */
352 public static function abtesing_pro_compatability(){
353 global $current_screen;
354 $is_pro_active = Wpfnl_functions::is_plugin_activated('wpfunnels-pro/wpfnl-pro.php');
355 if ( $is_pro_active ){
356
357 if ( defined('WPFNL_PRO_VERSION') && version_compare(WPFNL_PRO_VERSION, '1.7.3', '<') ) {
358 if ( 'plugins' === $current_screen->parent_base || 'wp_funnels' === $current_screen->parent_base ){
359 $options = array(
360 'id' => '',
361 'title' => 'wpfunnels-basic',
362 'description' => __("Please update to WPFunnels Pro 1.7.3 or higher to use A/B split testing feature.", 'wpfnl'),
363 'classes' => [ 'notice', 'wpfnl-notice' ], // We include WP's default notice class so it will be properly handled by WP's js handler
364 'type' => 'update-plugin',
365 'dismissible' => true,
366 'icon' => '',
367 );
368 self::print_notice($options);
369 }
370
371 }
372
373 }
374 return false;
375 }
376
377
378 /**
379 * GBF compatibility notice — no longer needed as GBF is now built into WPFunnels Pro.
380 *
381 * Kept as a no-op to avoid breaking any callers.
382 *
383 * @since 2.9.1
384 */
385 public static function gbf_compatability_notice(){
386 return false;
387 }
388
389
390
391 /**
392 * Oxygen compatiblity notice
393 *
394 * @param $localize
395 *
396 * @return $localize
397 */
398 public function notice_for_oxygen_builder_compatibility($localize = array())
399 {
400 if( Wpfnl_functions::oxygen_builder_version_capability() === false) {
401 return $localize;
402 }
403 if (is_array($localize)){
404 $oxygen_complability = Wpfnl_functions::oxygen_builder_version_capability();
405 $is_oxygen_installed = Wpfnl_functions::is_plugin_installed('oxygen/functions.php');
406 $is_oxygen_active = Wpfnl_functions::is_plugin_activated('oxygen/functions.php');
407 if ( $is_oxygen_active && $is_oxygen_installed ){
408 if ($oxygen_complability === false){
409 $message = wp_sprintf( '%s',
410 __("You are using an older version of Oxygen Builder, which is not compatible with WPFunnels. You will need Oxygen Builder v3.2 or above to be able to use it to design funnel pages in WPFunnels. Please update your builder.", 'wpfnl')
411 );
412
413 $localize['notices'][] = array(
414 'type' => 'OxygenBuilderCompatibility',
415 'notice_type' => 'warning',
416 'notice_texts' => $message
417 );
418
419 }
420 }
421 if (!empty($localize)){
422 return $localize;
423 }
424 }
425 }
426
427 /**
428 * Should show plugin dependency notices or not
429 *
430 * @param $plugin
431 * @param $slug
432 * @param $plugin_name
433 *
434 * @return array
435 * @since 2.0.0
436 */
437 public static function should_show_plugin_dependency_notice( $plugin, $slug, $plugin_name ) {
438 $action_url = '';
439 $show_notice = false;
440 $action_label = '';
441 $action = 'inactive';
442 if ( Wpfnl_functions::is_plugin_installed($plugin) ) {
443 if ( ! Wpfnl_functions::is_plugin_activated($plugin) ) {
444 $url = sprintf('plugins.php?action=activate&plugin=%s&plugin_status=all&paged=1&s', $plugin);
445 $action_url = wp_nonce_url($url, sprintf( 'activate-plugin_%1s', $plugin));
446 $show_notice = true;
447 $action_label = sprintf(__("Activate %s", 'wpfnl'), $plugin); // phpcs:ignore
448 }
449 } else {
450 $show_notice = true;
451 $action = 'install-plugin';
452 $action_url = wp_nonce_url(
453 add_query_arg(
454 array(
455 'action' => $action,
456 'plugin' => $slug
457 ),
458 admin_url( 'update.php' )
459 ),
460 $action.'_'.$slug
461 );
462 $action_label = sprintf(__("Install %s", 'wpfnl'),$plugin_name); // phpcs:ignore
463 $action = 'not-installed';
464 }
465 return array(
466 'show_notice' => $show_notice,
467 'action_url' => $action_url,
468 'action_label' => $action_label,
469 'action' => $action,
470 );
471 }
472
473 /**
474 * Render html attributes
475 *
476 * @param array $attributes
477 *
478 * @return string
479 * @since 2.0.0
480 */
481 public static function render_html_attributes( array $attributes ) {
482
483 $rendered_attributes = [];
484 foreach ( $attributes as $attribute_key => $attribute_values ) {
485 if ( is_array( $attribute_values ) ) {
486 $attribute_values = implode( ' ', $attribute_values );
487 }
488 $rendered_attributes[] = sprintf( '%1$s="%2$s"', $attribute_key, esc_attr( $attribute_values ) );
489 }
490 return implode( ' ', $rendered_attributes );
491 }
492
493
494 /**
495 * Render button for admin notices
496 *
497 * @param $options
498 */
499 public static function print_button($options) {
500 $default_options = [
501 'classes' => [ 'wpfnl-notice-button' ],
502 'icon' => '',
503 'new_tab' => false,
504 'text' => '',
505 'type' => '',
506 'url' => '',
507 'variant' => '',
508 'before' => '',
509 'id' => '',
510 'data-slug' => '',
511 ];
512
513 $options = array_replace_recursive( $default_options, $options );
514
515 if ( empty( $options['text'] ) ) {
516 return;
517 }
518
519 $html_tag = ! empty( $options['url'] ) ? 'a' : 'button';
520 $before = '';
521 $icon = '';
522 $attributes = [];
523
524 if ( ! empty( $options['icon'] ) ) {
525 $icon = '<i class="' . $options['icon'] . '"></i>';
526 }
527
528 $classes = $options['classes'];
529
530 if ( ! empty( $options['type'] ) ) {
531 $classes[] = 'wpfnl-button--' . $options['type'];
532 }
533
534 if ( ! empty( $options['url'] ) ) {
535 $attributes['href'] = $options['url'];
536 if ( $options['new_tab'] ) {
537 $attributes['target'] = '_blank';
538 }
539 }
540 $attributes['class'] = $classes;
541 $attributes['id'] = $options['id'];
542 $attributes['data-slug'] = $options['data-slug'];
543 $attributes['href'] = '#';
544 $html = $before . '<' . $html_tag . ' ' . self::render_html_attributes( $attributes ) . '>';
545 $html .= $icon;
546 $html .= '<span>' . sanitize_text_field( $options['text'] ) . '</span>';
547 $html .= '<span class="notice-loader"></span>';
548 $html .= '</' . $html_tag . '>';
549 echo $html;
550 }
551
552
553 /**
554 * Delete promotional notice
555 *
556 * @param Array $payload
557 *
558 * @return Array
559 * @since 2.6.1
560 */
561 public function wpfnl_delete_promotional_banner( $payload ){
562 update_option('_is_show_us_banner', 'no' );
563 return [
564 'success' => true,
565 ];
566 }
567
568 /**
569 * Delete wpfunnels new UI notice
570 *
571 * @param Array $payload
572 *
573 * @return Array
574 * @since 2.6.1
575 */
576 public function wpfnl_delete_new_ui_notice( $payload ){
577
578 update_option( '_is_wpfnl_new_ui_notices', 'no' );
579 return [
580 'success' => true,
581 ];
582 }
583
584
585 /**
586 * Hide all notice in email builder
587 *
588 * @return void
589 * @since 2.8.7
590 */
591 public function hide_update_notice_on_builder(){
592 global $current_screen;
593 if( "wpfunnels_page_email-builder" === $current_screen->base || "toplevel_page_wpfunnels" === $current_screen->base || "wpfunnels_page_wpfnl_automations" === $current_screen->base || "wpfunnels_page_store_checkout" === $current_screen->base ){
594 remove_all_actions( 'admin_notices' );
595 }
596 }
597 }
598