PluginProbe
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce / 3.3.0
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce v3.3.0
3.3.0 3.2.1 3.2.0 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.1 trunk 1.0.4 1.1.0 1.1.0.1 1.1.1 1.1.10 1.1.11 1.1.12 1.1.13 1.1.14 1.1.15 1.1.16 1.1.17 1.1.18 1.1.19 1.1.2 All 162 releases
cartflows / wizard / inc / wizard-core.php

wizard-core.php in CartFlows – Funnel Builder & Checkout Plugin for WooCommerce 3.3.0, at wizard/inc/wizard-core.php

482 lines 14.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * CartFlows Admin Menu.
4 *
5 * @package CartFlows
6 */
7
8 namespace CartflowsAdmin\Wizard\Inc;
9
10 // Exit if accessed directly.
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit;
13 }
14
15 /**
16 * Class Admin_Menu.
17 */
18 class WizardCore {
19
20 /**
21 * Instance
22 *
23 * @access private
24 * @var object Class object.
25 * @since 1.0.0
26 */
27 private static $instance;
28
29 /**
30 * Initiator
31 *
32 * @since 1.0.0
33 * @return object initialized object of class.
34 */
35 public static function get_instance() {
36 if ( ! isset( self::$instance ) ) {
37 self::$instance = new self();
38 }
39 return self::$instance;
40 }
41
42 /**
43 * Constructor.
44 */
45 public function __construct() {
46
47 if ( apply_filters( 'cartflows_enable_setup_wizard', true ) && current_user_can( 'manage_options' ) ) {
48
49 add_action( 'admin_menu', array( $this, 'admin_menus' ) );
50 add_action( 'admin_init', array( $this, 'setup_wizard' ) );
51 add_action( 'admin_init', array( $this, 'hide_notices' ) );
52 add_action( 'admin_notices', array( $this, 'show_setup_wizard' ) );
53 add_action( 'woocommerce_installed', array( $this, 'disable_woo_setup_redirect' ) );
54 // We are hiding admin bar intentionally, only on the setup wizard page. This
55 // constructor runs on every is_admin() request, so an unscoped filter removed
56 // the toolbar from the whole of wp-admin.
57 if ( isset( $_GET['page'] ) && 'cartflow-setup' === $_GET['page'] ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
58 add_filter( 'show_admin_bar', '__return_false', 1 ); //phpcs:ignore WordPressVIPMinimum.UserExperience.AdminBarRemoval.RemovalDetected, WordPressVIPMinimum.UserExperience.AdminBarRemoval.HidingDetected
59 }
60
61 add_action( 'init', array( $this, 'load_scripts' ) );
62 add_action( 'admin_print_styles', array( $this, 'load_admin_media_styles' ) );
63
64 add_action( 'admin_init', array( $this, 'redirect_to_onboarding' ) );
65 add_filter( 'before_cp_load_popup', array( $this, 'hide_convert_pro_popups' ), 10, 1 ); // Disable the render of Convert Pro popups in onboarding wizard.
66 }
67 }
68
69 /**
70 * Redirect to onboarding if required.
71 *
72 * @return void
73 * @since 2.0.0
74 */
75 public function redirect_to_onboarding() {
76
77 if ( ! get_option( 'wcf_start_onboarding', false ) ) {
78 return;
79 }
80
81 if ( '1' === get_option( 'wcf_setup_complete', false ) || '1' === get_option( 'wcf_setup_skipped', false ) ) {
82 return;
83 }
84
85 delete_option( 'wcf_start_onboarding' );
86 wp_safe_redirect( esc_url_raw( admin_url( 'index.php?page=cartflow-setup' ) ) );
87 exit();
88 }
89
90
91 /**
92 * Load styles.
93 */
94 public function load_admin_media_styles() {
95
96 $ary_libs = array(
97 'common',
98 'forms',
99 );
100 $admin_media_styles_url = add_query_arg(
101 array(
102 'c' => 0,
103 'dir' => ! is_rtl() ? 'ltr' : 'rtl',
104 'load[]' => implode( ',', $ary_libs ),
105 'ver' => 'you_wp_version',
106 ),
107 admin_url() . 'load-styles.php'
108 );
109 echo "<link rel='stylesheet' id='admin_styles_for_media-css' href='" . esc_url( $admin_media_styles_url ) . "' type='text/css' media='all' />";
110 }
111
112 /**
113 * Load media.
114 */
115 public function load_scripts() {
116
117 add_action( 'wp_enqueue_scripts', array( $this, 'load_media_script' ) );
118 }
119
120 /**
121 * Load WP media script on init.
122 */
123 public function load_media_script() {
124 wp_enqueue_media();
125 }
126
127 /**
128 * Hide a notice if the GET variable is set.
129 */
130 public function hide_notices() {
131
132 if ( ! isset( $_GET['wcf-hide-notice'] ) ) {
133 return;
134 }
135
136 $wcf_hide_notice = isset( $_GET['wcf-hide-notice'] ) ? sanitize_text_field( wp_unslash( $_GET['wcf-hide-notice'] ) ) : '';
137 $_wcf_notice_nonce = isset( $_GET['_wcf_notice_nonce'] ) ? sanitize_text_field( wp_unslash( $_GET['_wcf_notice_nonce'] ) ) : '';
138
139 if ( $wcf_hide_notice && $_wcf_notice_nonce && wp_verify_nonce( sanitize_text_field( wp_unslash( $_wcf_notice_nonce ) ), 'wcf_hide_notices_nonce' ) ) {
140 update_option( 'wcf_setup_skipped', true );
141 }
142 }
143
144 /**
145 * Disable the woo redirect for new setup.
146 */
147 public function disable_woo_setup_redirect() {
148
149 delete_transient( '_wc_activation_redirect' );
150 }
151
152 /**
153 * Show action links on the plugin screen.
154 *
155 * @since 1.0.0
156 * @return void
157 */
158 public function show_setup_wizard() {
159
160 $screen = get_current_screen();
161 $screen_id = $screen ? $screen->id : '';
162 $allowed_screens = array(
163 'cartflows_page_cartflows_settings',
164 'edit-cartflows_flow',
165 'dashboard',
166 'plugins',
167 );
168
169 if ( ! in_array( $screen_id, $allowed_screens, true ) ) {
170 return;
171 }
172
173 $status = get_option( 'wcf_setup_complete', false );
174 $skip_setup = get_option( 'wcf_setup_skipped', false );
175
176 if ( false === $status && ! $skip_setup ) { ?>
177 <div class="notice notice-info wcf-notice">
178 <p><b><?php esc_html_e( 'Thanks for installing and using CartFlows!', 'cartflows' ); ?></b></p>
179 <p><?php esc_html_e( 'It is easy to use the CartFlows. Please use the setup wizard to quick start setup.', 'cartflows' ); ?></p>
180 <p>
181 <a href="<?php echo esc_url( admin_url( 'index.php?page=cartflow-setup' ) ); ?>" class="button button-primary"> <?php esc_html_e( 'Start Wizard', 'cartflows' ); ?></a>
182 <a class="button-secondary" href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'wcf-hide-notice', 'install' ), 'wcf_hide_notices_nonce', '_wcf_notice_nonce' ) ); ?>"><?php esc_html_e( 'Skip Setup', 'cartflows' ); ?></a>
183 </p>
184 </div>
185 <?php
186 }
187 }
188
189 /**
190 * Add admin menus/screens.
191 */
192 public function admin_menus() {
193
194 // Ignoring phpcs nonce rule as we are calling this function on admin action.
195 if ( empty( $_GET['page'] ) || 'cartflow-setup' !== $_GET['page'] ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
196 return;
197 }
198
199 add_dashboard_page( '', '', 'manage_options', 'cartflow-setup', '' );
200 }
201
202 /**
203 * Show the setup wizard.
204 */
205 public function setup_wizard() {
206
207 // Ignoring phpcs nonce rule as we are calling this function on admin action.
208 if ( empty( $_GET['page'] ) || 'cartflow-setup' !== $_GET['page'] ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
209 return;
210 }
211 $this->load_required_scripts();
212 $this->localize_vars();
213
214 // Diable loading of Query Monitor in footer.
215 add_filter( 'qm/dispatch/html', '__return_false' );
216
217 ob_start();
218 include_once CARTFLOWS_DIR . 'wizard/views/wizard-base.php';
219 }
220
221 /**
222 * Load scripts.
223 */
224 public function load_required_scripts() {
225 $handle = 'cartflows-wizard';
226 $build_path = CARTFLOWS_DIR . 'wizard/assets/build/';
227 $build_url = CARTFLOWS_URL . 'wizard/assets/build/';
228 $script_asset_path = $build_path . 'wizard-app.asset.php';
229 $script_info = file_exists( $script_asset_path )
230 ? include $script_asset_path
231 : array(
232 'dependencies' => array(),
233 'version' => CARTFLOWS_VER,
234 );
235
236 $script_dep = array_merge( $script_info['dependencies'], array( 'updates' ) );
237
238 wp_register_script(
239 $handle,
240 $build_url . 'wizard-app.js',
241 $script_dep,
242 $script_info['version'],
243 true
244 );
245
246 wp_register_style(
247 $handle,
248 $build_url . 'wizard-app.css',
249 array(),
250 CARTFLOWS_VER
251 );
252
253 wp_enqueue_script( $handle );
254 wp_enqueue_style( $handle );
255 wp_style_add_data( $handle, 'rtl', 'replace' );
256
257 wp_register_script(
258 'cartflows-setup-helper',
259 CARTFLOWS_URL . 'wizard/assets/js/helper.js',
260 array( 'jquery', 'wp-util', 'updates', 'media-upload' ),
261 CARTFLOWS_VER,
262 true
263 );
264 wp_enqueue_script( 'cartflows-setup-helper' );
265 wp_enqueue_media();
266 wp_enqueue_script( 'jquery-ui' );
267 }
268
269 /**
270 * Save usage tracking Settings.
271 */
272 public function save_usage_tracking_option() {
273
274 if ( ! current_user_can( 'manage_options' ) ) {
275 return;
276 }
277
278 check_ajax_referer( 'wcf-usage-tracking-option', 'security' );
279
280 $allow_usage_tracking = isset( $_POST['allow_usage_tracking'] ) && 'true' == $_POST['allow_usage_tracking'] ? 'yes' : 'no';
281
282 $usage_tracking = get_site_option( 'cf_usage_optin' );
283
284 if ( ( false === $usage_tracking ) || $allow_usage_tracking !== $usage_tracking ) {
285 update_site_option( 'cf_usage_optin', $allow_usage_tracking );
286 }
287
288 wp_send_json_success( get_site_option( 'cf_usage_optin' ) );
289 }
290
291 /**
292 * Redirect the user to create his first flow depending on which UI he is using.
293 */
294 public function get_final_page_link() {
295
296 $default_url = add_query_arg(
297 array(
298 'page' => CARTFLOWS_SLUG,
299 'path' => 'flows',
300 ),
301 admin_url()
302 );
303
304 return $default_url;
305 }
306
307
308 /**
309 * Localize variables in admin.
310 */
311 public function localize_vars() {
312
313 $vars = array();
314
315 $plugins = array(
316 array(
317 'name' => 'WooCommerce',
318 'slug' => 'woocommerce',
319 'status' => $this->get_plugin_status( 'woocommerce/woocommerce.php' ),
320 ),
321 array(
322 'name' => 'Cart Abandonment Recovery for WooCommerce',
323 'slug' => 'woo-cart-abandonment-recovery',
324 'status' => $this->get_plugin_status( 'woo-cart-abandonment-recovery/woo-cart-abandonment-recovery.php' ),
325 ),
326 array(
327 'name' => 'Modern cart',
328 'slug' => 'modern-cart',
329 'status' => $this->get_plugin_status( 'modern-cart/modern-cart.php' ),
330 ),
331 array(
332 'name' => 'WooCommerce Payments',
333 'slug' => 'woocommerce-payments',
334 'status' => $this->get_plugin_status( 'woocommerce-payments/woocommerce-payments.php' ),
335 ),
336 array(
337 'name' => 'Spectra',
338 'slug' => 'ultimate-addons-for-gutenberg',
339 'status' => $this->get_plugin_status( 'ultimate-addons-for-gutenberg/ultimate-addons-for-gutenberg.php' ),
340 ),
341 );
342
343 $installed_plugins = get_plugins();
344
345 $page_builders = array(
346 'elementor' => array(
347 'slug' => 'elementor',
348 'init' => 'elementor/elementor.php',
349 'active' => is_plugin_active( 'elementor/elementor.php' ) ? 'yes' : 'no',
350 'install' => isset( $installed_plugins['elementor/elementor.php'] ) ? 'yes' : 'no',
351 ),
352 'beaver-builder' => array(
353 'slug' => 'beaver-builder-lite-version',
354 'init' => 'beaver-builder-lite-version/fl-builder.php',
355 'active' => is_plugin_active( 'beaver-builder-lite-version/fl-builder.php' ) ? 'yes' : 'no',
356 'install' => isset( $installed_plugins['beaver-builder-lite-version/fl-builder.php'] ) ? 'yes' : 'no',
357 ),
358 'divi' => array(
359 'slug' => 'divi',
360 'init' => 'divi',
361 'active' => 'yes',
362 'install' => 'NA', // Removed the Support of DIVI theme that is why it is set as NA.
363 ),
364 'gutenberg' => array(
365 'slug' => 'ultimate-addons-for-gutenberg',
366 'init' => 'ultimate-addons-for-gutenberg/ultimate-addons-for-gutenberg.php',
367 'active' => is_plugin_active( 'ultimate-addons-for-gutenberg/ultimate-addons-for-gutenberg.php' ) ? 'yes' : 'no',
368 'install' => isset( $installed_plugins['ultimate-addons-for-gutenberg/ultimate-addons-for-gutenberg.php'] ) ? 'yes' : 'no',
369 ),
370 'bricks-builder' => array(
371 'slug' => 'bricks',
372 'init' => 'bricks',
373 'active' => 'yes',
374 'install' => 'NA', // Bricks is an paid theme that is why, the install option is set to NA. As this will be enabled on the user's website before the CartFlows Install.
375 ),
376 // Intentionally installing the GB plugin when the other option is selected.
377 'other' => array(
378 'slug' => 'ultimate-addons-for-gutenberg',
379 'init' => 'ultimate-addons-for-gutenberg/ultimate-addons-for-gutenberg.php',
380 'active' => is_plugin_active( 'ultimate-addons-for-gutenberg/ultimate-addons-for-gutenberg.php' ) ? 'yes' : 'no',
381 'install' => isset( $installed_plugins['ultimate-addons-for-gutenberg/ultimate-addons-for-gutenberg.php'] ) ? 'yes' : 'no',
382 ),
383 );
384
385 $current_user = wp_get_current_user();
386
387 $vars = array(
388 'current_user_name' => ! empty( $current_user->user_firstname ) ? $current_user->user_firstname : $current_user->display_name,
389 'current_user_email' => ! empty( $current_user->user_email ) ? $current_user->user_email : '',
390 'plugins' => $plugins,
391 'page_builders' => $page_builders,
392 'active_page_builder' => WizardHelper::get_active_supported_builder( $page_builders ),
393 'ajax_url' => admin_url( 'admin-ajax.php' ),
394 'admin_url' => admin_url( 'admin.php' ),
395 'admin_base_url' => admin_url(),
396 'admin_index_url' => admin_url( 'index.php' ),
397 'default_page_builder' => \Cartflows_Helper::get_common_settings()['default_page_builder'],
398 'site_logo' => $this->get_site_logo_url(),
399 'template_import_errors' => array(
400 'api_errors' => array(
401 'title' => __( 'Oops!! Unexpected error occoured', 'cartflows' ),
402 'msg' => __( 'Import template API call failed. Please reload the page and try again!', 'cartflows' ),
403 ),
404 ),
405 'is_pro' => _is_cartflows_pro(),
406 'cf_pro_type' => defined( 'CARTFLOWS_PRO_PLUGIN_TYPE' ) ? CARTFLOWS_PRO_PLUGIN_TYPE : 'free',
407 'woocommerce_status' => $this->get_plugin_status( 'woocommerce/woocommerce.php' ),
408 );
409
410 $vars = apply_filters( 'cartflows_admin_wizard_localized_vars', $vars );
411
412 wp_localize_script( 'cartflows-wizard', 'cartflows_wizard', $vars );
413 }
414
415 /**
416 * Get customizer/site logo URL.
417 *
418 * @since 1.10.0
419 *
420 * @return $image_url Site logo URL
421 */
422 public function get_site_logo_url() {
423
424 $logo = get_theme_mod( 'custom_logo' );
425 $site_logo = '';
426
427 if ( ! empty( $logo ) ) {
428
429 $image = wp_get_attachment_image_src( $logo, 'full' );
430
431 $site_logo = array(
432 'id' => $logo,
433 'url' => $image[0] ? $image[0] : '',
434 'width' => $image[1] ? $image[1] : '',
435 'height' => $image[2] ? $image[2] : '',
436 );
437 }
438
439 return $site_logo;
440 }
441
442 /**
443 * Get plugin status
444 *
445 * @since 1.1.4
446 *
447 * @param string $plugin_init_file Plguin init file.
448 * @return mixed
449 */
450 public function get_plugin_status( $plugin_init_file ) {
451
452 $installed_plugins = get_plugins();
453
454 if ( ! isset( $installed_plugins[ $plugin_init_file ] ) ) {
455 return 'not-installed';
456 } elseif ( is_plugin_active( $plugin_init_file ) ) {
457 return 'active';
458 } else {
459 return 'inactive';
460 }
461 }
462
463 /**
464 * Function to hide Convert Pro popups during the onboarding wizard process.
465 *
466 * This function checks if the current page is the CartFlows setup page and if so, it sets the load parameter to false, effectively hiding the Convert Pro popups.
467 *
468 * @param bool $load The initial load state of the Convert Pro popups.
469 * @return bool The modified load state of the Convert Pro popups.
470 */
471 public function hide_convert_pro_popups( $load ) {
472
473 if ( ! empty( $_GET['page'] ) && 'cartflow-setup' === $_GET['page'] ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
474 $load = false;
475 }
476
477 return $load;
478 }
479 }
480
481 WizardCore::get_instance();
482