PluginProbe
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell / 2.8.16
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell v2.8.16
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 2.8.16, at admin/class-wpfnl-notices.php

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