PluginProbe
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce / 3.0.1
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce v3.0.1
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 / classes / class-cartflows-loader.php

class-cartflows-loader.php in CartFlows – Funnel Builder & Checkout Plugin for WooCommerce 3.0.1, at classes/class-cartflows-loader.php

756 lines 22.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * CartFlows Loader.
4 *
5 * @package CartFlows
6 */
7
8 // Exit if accessed directly.
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit;
11 }
12 if ( ! class_exists( 'Cartflows_Loader' ) ) {
13
14 /**
15 * Class Cartflows_Loader.
16 */
17 final class Cartflows_Loader {
18
19 /**
20 * Member Variable
21 *
22 * @var instance
23 */
24 private static $instance = null;
25
26 /**
27 * Member Variable
28 *
29 * @var utils
30 */
31 public $utils = null;
32
33 /**
34 * Member Variable
35 *
36 * @var logger
37 */
38 public $logger = null;
39
40 /**
41 * Member Variable
42 *
43 * @var options
44 */
45 public $options = null;
46
47 /**
48 * Member Variable
49 *
50 * @var meta
51 */
52 public $meta = null;
53
54 /**
55 * Member Variable
56 *
57 * @var Tracking_Data
58 */
59 public $alldata;
60
61 /**
62 * Member Variable
63 *
64 * @var flow
65 */
66 public $flow = null;
67
68 /**
69 * Member Variable
70 *
71 * @var wcf_step_objs
72 */
73
74 public $wcf_step_objs = array();
75
76 /**
77 * Member Variable
78 *
79 * @var assets_vars
80 */
81 public $assets_vars = null;
82
83 /**
84 * Member Variable
85 *
86 * @var assets_vars
87 */
88
89 public $is_woo_active = true;
90
91 /**
92 * Initiator
93 */
94 public static function get_instance() {
95 if ( is_null( self::$instance ) ) {
96
97 self::$instance = new self();
98
99 /**
100 * CartFlows loaded.
101 *
102 * Fires when Cartflows was fully loaded and instantiated.
103 *
104 * @since 1.0.0
105 */
106 do_action( 'cartflows_loaded' );
107 }
108
109 return self::$instance;
110 }
111
112 /**
113 * Constructor
114 */
115 public function __construct() {
116 $this->define_constants();
117
118 // Activation hook.
119 register_activation_hook( CARTFLOWS_FILE, array( $this, 'activation_reset' ) );
120
121 // deActivation hook.
122 register_deactivation_hook( CARTFLOWS_FILE, array( $this, 'deactivation_reset' ) );
123
124 // Need to add library before the plugin loaded. https://actionscheduler.org/usage/.
125 require_once CARTFLOWS_DIR . '/libraries/action-scheduler/action-scheduler.php';
126
127 add_action( 'plugins_loaded', array( $this, 'load_plugin' ), 99 );
128 add_action( 'init', array( $this, 'load_cf_textdomain' ) );
129
130 // Priority 5 mirrors Astra's init_bsf_analytics() pattern: set_entity() must
131 // run before BSF_Analytics_Loader::load_analytics() fires at priority 10.
132 add_action( 'init', array( $this, 'deactivation_survey_data_handler' ), 5 );
133 }
134
135 /**
136 * Defines all constants
137 *
138 * @since 1.0.0
139 */
140 public function define_constants() {
141
142 define( 'CARTFLOWS_BASE', plugin_basename( CARTFLOWS_FILE ) );
143 define( 'CARTFLOWS_DIR', plugin_dir_path( CARTFLOWS_FILE ) );
144 define( 'CARTFLOWS_URL', plugins_url( '/', CARTFLOWS_FILE ) );
145
146 define( 'CARTFLOWS_VER', '3.0.1' );
147 define( 'CARTFLOWS_SLUG', 'cartflows' );
148 define( 'CARTFLOWS_SETTINGS', 'cartflows_settings' );
149 define( 'CARTFLOWS_NAME', 'CartFlows' );
150
151 define( 'CARTFLOWS_REQ_CF_PRO_VER', '3.0.0' );
152
153 // Resolves to true for users upgrading from <3.0.0 (set by Cartflows_Update on first 3.0+ admin_init)
154 // and stays true until the user opts out via the Advanced-tab toggle or the legacy in-app switch.
155 // Fresh installs never see this option set, so they default to the new UI. The toggle saves
156 // 'enable'/'disable' strings; older code paths may have stored a boolean true — accept both.
157 $cartflows_legacy_admin_saved = get_option( 'cartflows-legacy-admin', false );
158 define( 'CARTFLOWS_LEGACY_ADMIN', in_array( $cartflows_legacy_admin_saved, array( true, 1, '1', 'enable', 'yes' ), true ) );
159
160 define( 'CARTFLOWS_ASSETS_VERSION', get_option( 'cartflows-assets-version', time() ) );
161
162 define( 'CARTFLOWS_FLOW_POST_TYPE', 'cartflows_flow' );
163 define( 'CARTFLOWS_STEP_POST_TYPE', 'cartflows_step' );
164
165 define( 'CARTFLOWS_FLOW_PERMALINK_SLUG', 'flow' );
166 define( 'CARTFLOWS_STEP_PERMALINK_SLUG', 'step' );
167
168 if ( ! defined( 'CARTFLOWS_SERVER_URL' ) ) {
169 define( 'CARTFLOWS_SERVER_URL', 'https://my.cartflows.com/' );
170 }
171 if ( ! defined( 'CARTFLOWS_DOMAIN_URL' ) ) {
172 define( 'CARTFLOWS_DOMAIN_URL', 'https://cartflows.com/' );
173 }
174 if ( ! defined( 'CARTFLOWS_TEMPLATES_URL' ) ) {
175 define( 'CARTFLOWS_TEMPLATES_URL', 'https://templates.cartflows.com/' );
176 }
177 define( 'CARTFLOWS_TAXONOMY_STEP_TYPE', 'cartflows_step_type' );
178 define( 'CARTFLOWS_TAXONOMY_STEP_FLOW', 'cartflows_step_flow' );
179
180 if ( ! defined( 'CARTFLOWS_TAXONOMY_STEP_PAGE_BUILDER' ) ) {
181 define( 'CARTFLOWS_TAXONOMY_STEP_PAGE_BUILDER', 'cartflows_step_page_builder' );
182 }
183 if ( ! defined( 'CARTFLOWS_TAXONOMY_FLOW_PAGE_BUILDER' ) ) {
184 define( 'CARTFLOWS_TAXONOMY_FLOW_PAGE_BUILDER', 'cartflows_flow_page_builder' );
185 }
186 if ( ! defined( 'CARTFLOWS_TAXONOMY_FLOW_CATEGORY' ) ) {
187 define( 'CARTFLOWS_TAXONOMY_FLOW_CATEGORY', 'cartflows_flow_category' );
188 }
189
190 if ( ! defined( 'CARTFLOWS_LOG_DIR' ) ) {
191
192 $upload_dir = wp_upload_dir( null, false );
193
194 define( 'CARTFLOWS_LOG_DIR', $upload_dir['basedir'] . '/cartflows-logs/' );
195 }
196
197 $cookie_prefix = '';
198
199 if ( defined( 'CARTFLOWS_COOKIE_PREFIX' ) ) {
200 $cookie_prefix = CARTFLOWS_COOKIE_PREFIX;
201 }
202
203 define( 'CARTFLOWS_ACTIVE_CHECKOUT', $cookie_prefix . 'wcf_active_checkout' );
204
205 define( 'CARTFLOWS_PINTEREST_CONSENT', $cookie_prefix . 'cartflows_pinterest_consent' );
206
207 if ( ! defined( 'CARTFLOWS_HTTPS' ) ) {
208 define( 'CARTFLOWS_HTTPS', is_ssl() ? true : false );
209 }
210
211 define( 'CARTFLOWS_NPS_WEBHOOK_URL', 'https://webhook.ottokit.com/ottokit/af2151cc-6fe3-40a4-a9d3-12859be4d602' );
212
213 $GLOBALS['wcf_step'] = null;
214 }
215
216 /**
217 * Get site slug
218 *
219 * @since 1.6.15
220 * @return string
221 */
222 public function get_site_slug() {
223 return Cartflows_Helper::get_common_setting( 'default_page_builder' );
224 }
225
226 /**
227 * Get site URL
228 *
229 * @since 1.6.15
230 * @param string $page_builder_slug Page builder slug.
231 * @return string
232 */
233 public function get_site_url( $page_builder_slug = '' ) {
234
235 $page_builder_slug = ( ! empty( $page_builder_slug ) ) ? $page_builder_slug : wcf()->get_site_slug();
236
237 if ( ! empty( $page_builder_slug ) ) {
238 return trailingslashit( CARTFLOWS_TEMPLATES_URL ) . $page_builder_slug . '/';
239 }
240
241 return CARTFLOWS_TEMPLATES_URL;
242 }
243
244 /**
245 * Loads plugin files.
246 *
247 * @since 1.0.0
248 *
249 * @return void
250 */
251 public function load_plugin() {
252 $this->load_helper_files_components();
253 $this->load_core_files();
254 $this->load_core_components();
255
256 add_action( 'wp_loaded', array( $this, 'initialize' ) );
257 add_action( 'cartflows_pro_init', array( $this, 'after_cartflows_pro_init' ) );
258
259 if ( ! $this->is_woo_active ) {
260 add_action( 'admin_notices', array( $this, 'fails_to_load' ) );
261 }
262
263 /**
264 * CartFlows Init.
265 *
266 * Fires when Cartflows is instantiated.
267 *
268 * @since 1.0.0
269 */
270 do_action( 'cartflows_init' );
271 }
272
273 /**
274 * After CartFlows Pro init.
275 *
276 * @since 1.1.19
277 *
278 * @return void
279 */
280 public function after_cartflows_pro_init() {
281 if ( ! is_admin() ) {
282 return;
283 }
284
285 if ( version_compare( CARTFLOWS_PRO_VER, CARTFLOWS_REQ_CF_PRO_VER, '<' ) ) {
286 add_action( 'admin_notices', array( $this, 'required_cartflows_pro_notice' ) );
287 }
288
289 if ( version_compare( CARTFLOWS_PRO_VER, '1.11.14', '=' ) && 'starter' === CARTFLOWS_PRO_PLUGIN_TYPE ) {
290 add_action( 'admin_notices', array( $this, 'show_upgrade_starter_plan_notice' ) );
291 }
292 }
293
294 /**
295 * Show CartFlows Pro: Starter plan update Notice.
296 *
297 * @since 1.11.14
298 *
299 * @return void
300 */
301 public function show_upgrade_starter_plan_notice() {
302
303 $class = 'notice notice-warning wcf-notice';
304 /* translators: %s: html tags */
305 $message = sprintf( __( 'The new version of %1$s%3$s%2$s is released. Please download the latest zip to install the new updates. Click here to %4$sdownload%5$s.', 'cartflows' ), '<strong>', '</strong>', CARTFLOWS_PRO_DISPLAY_TITLE, '<a href="https://my.cartflows.com/" target="_blank">', '</a>' );
306
307 printf( '<div class="%1$s"><p>%2$s</p></div>', esc_attr( $class ), wp_kses_post( $message ) );
308 }
309
310 /**
311 * Required CartFlows Pro Notice.
312 *
313 * @since 1.1.19
314 *
315 * @return void
316 */
317 public function required_cartflows_pro_notice() {
318 $required_pro_version = CARTFLOWS_REQ_CF_PRO_VER;
319
320 $class = 'notice notice-warning wcf-notice';
321 /* translators: %s: html tags */
322 $message = sprintf( __( 'You are using an older version of %1$s%3$s%2$s. Please update %1$s%3$s%2$s plugin to version %1$s%4$s%2$s or higher.', 'cartflows' ), '<strong>', '</strong>', CARTFLOWS_PRO_DISPLAY_TITLE, $required_pro_version );
323
324 printf( '<div class="%1$s"><p>%2$s</p></div>', esc_attr( $class ), wp_kses_post( $message ) );
325 }
326
327 /**
328 * Load Helper Files and Components.
329 *
330 * @since 1.0.0
331 *
332 * @return void
333 */
334 public function load_helper_files_components() {
335 $this->is_woo_active = function_exists( 'WC' );
336
337 /* Public Utils */
338 include_once CARTFLOWS_DIR . 'classes/class-cartflows-utils.php';
339
340 /* Public Global Name space Functions */
341 include_once CARTFLOWS_DIR . 'classes/class-cartflows-functions.php';
342
343 /* Admin Helper */
344 include_once CARTFLOWS_DIR . 'classes/class-cartflows-helper.php';
345
346 /* Factory objects */
347 include_once CARTFLOWS_DIR . 'classes/class-cartflows-step-factory.php';
348
349 /* Meta Default Values */
350 include_once CARTFLOWS_DIR . 'classes/class-cartflows-default-meta.php';
351
352 require_once CARTFLOWS_DIR . 'classes/class-cartflows-tracking.php';
353 require_once CARTFLOWS_DIR . 'classes/class-cartflows-rollback.php';
354
355 if ( is_admin() ) {
356 require_once CARTFLOWS_DIR . 'libraries/astra-notices/class-astra-notices.php';
357 }
358
359 if ( ! class_exists( 'BSF_Analytics_Loader' ) ) {
360 require_once CARTFLOWS_DIR . 'libraries/bsf-analytics/class-bsf-analytics-loader.php';
361 }
362
363 $this->utils = Cartflows_Utils::get_instance();
364 $this->options = Cartflows_Default_Meta::get_instance();
365
366 // Plugin major update notice.
367 if ( ! class_exists( 'Cartflows_Plugin_Update_Notifications' ) ) {
368 require_once CARTFLOWS_DIR . 'libraries/cartflows-plugin-update-notifications/class-cartflows-plugin-update-notifications.php';
369 }
370
371 // Load the NPS Survey library.
372 if ( ! class_exists( 'Cartflows_Nps_Survey' ) ) {
373 require_once CARTFLOWS_DIR . 'libraries/class-cartflows-nps-survey.php';
374 }
375
376 // Load the CartFlows Pointer library.
377 if ( ! class_exists( 'Cartflows_Pointer' ) ) {
378 require_once CARTFLOWS_DIR . 'libraries/cartflows-pointer/class-cartflows-pointer.php';
379 }
380 }
381
382 /**
383 * Deactivation Survey Data Handler
384 *
385 * @since 2.1.17
386 *
387 * @return void
388 */
389 public function deactivation_survey_data_handler() {
390 $bsf_analytics = BSF_Analytics_Loader::get_instance();
391
392 $bsf_analytics->set_entity(
393 array(
394 'cf' => array(
395 'hide_optin_checkbox' => true,
396 'product_name' => 'CartFlows',
397 'usage_doc_link' => 'https://my.cartflows.com/usage-tracking/',
398 'path' => CARTFLOWS_DIR . 'libraries/bsf-analytics',
399 'author' => 'CartFlows Inc',
400 'deactivation_survey' => apply_filters(
401 'cartflows_bsf_analytics_deactivation_survey_data',
402 array(
403 array(
404 'id' => 'deactivation-survey-cartflows',
405 'popup_logo' => CARTFLOWS_URL . 'admin-core/assets/images/cartflows-icon.svg',
406 'plugin_slug' => 'cartflows',
407 'plugin_version' => CARTFLOWS_VER,
408 'popup_title' => __( 'Quick Feedback', 'cartflows' ),
409 'support_url' => 'https://cartflows.com/contact/',
410 'popup_description' => __( 'If you have a moment, please share why you are deactivating CartFlows:', 'cartflows' ),
411 'show_on_screens' => array( 'plugins' ),
412 ),
413 )
414 ),
415 ),
416 )
417 );
418 }
419
420 /**
421 * Init hooked function.
422 *
423 * @since 1.0.0
424 *
425 * @return void
426 */
427 public function initialize() {
428 $this->assets_vars = $this->utils->get_assets_path();
429 }
430
431 /**
432 * Load Core Files.
433 *
434 * @since 1.0.0
435 *
436 * @return void
437 */
438 public function load_core_files() {
439 /* Update compatibility. */
440 require_once CARTFLOWS_DIR . 'classes/class-cartflows-update.php';
441
442 /* Page builder compatibilty class */
443 include_once CARTFLOWS_DIR . 'compatibilities/class-cartflows-compatibility.php';
444
445 /* Theme support */
446 if ( $this->is_woo_active ) {
447 /* Woo hooks */
448 include_once CARTFLOWS_DIR . 'classes/class-cartflows-woo-hooks.php';
449 }
450
451 /* Importer */
452 include_once CARTFLOWS_DIR . 'classes/importer/class-cartflows-importer-loader.php';
453
454 /* Admin Meta Fields*/
455 include_once CARTFLOWS_DIR . 'classes/fields/typography/class-cartflows-font-families.php';
456
457 // Analytics — BSF Analytics Events integration. Loaded on every request so the
458 // bsf_core_stats filter is registered for both frontend and admin transmissions.
459 include_once CARTFLOWS_DIR . 'classes/class-cartflows-analytics.php';
460
461 if ( is_admin() ) {
462
463 /* Admin helper */
464 include_once CARTFLOWS_DIR . 'classes/class-cartflows-admin.php';
465
466 }
467
468 /* Admin loader — fork between legacy (admin-legacy-core/) and current (admin-core/) UI. */
469 if ( defined( 'CARTFLOWS_LEGACY_ADMIN' ) && CARTFLOWS_LEGACY_ADMIN ) {
470 include_once CARTFLOWS_DIR . 'admin-legacy-loader.php';
471 } else {
472 include_once CARTFLOWS_DIR . 'admin-loader.php';
473 }
474
475 if ( class_exists( 'WP_CLI' ) ) {
476 /* WP-CLI registration follows the active UI tree. */
477 if ( defined( 'CARTFLOWS_LEGACY_ADMIN' ) && CARTFLOWS_LEGACY_ADMIN ) {
478 require_once CARTFLOWS_DIR . 'admin-legacy-core/inc/wp-cli.php';
479 } else {
480 require_once CARTFLOWS_DIR . 'admin-core/inc/wp-cli.php';
481 }
482 }
483
484 /* Logger */
485 include_once CARTFLOWS_DIR . 'classes/logger/class-cartflows-log-handler-interface.php';
486 include_once CARTFLOWS_DIR . 'classes/logger/class-cartflows-log-handler.php';
487 include_once CARTFLOWS_DIR . 'classes/logger/class-cartflows-log-handler-file.php';
488 include_once CARTFLOWS_DIR . 'classes/logger/class-cartflows-log-levels.php';
489 include_once CARTFLOWS_DIR . 'classes/logger/class-cartflows-logger-interface.php';
490 include_once CARTFLOWS_DIR . 'classes/logger/class-cartflows-wc-logger.php';
491
492 /* Core Modules */
493 include_once CARTFLOWS_DIR . 'classes/class-cartflows-logger.php';
494
495 /* Frontend Global */
496 include_once CARTFLOWS_DIR . 'classes/class-cartflows-frontend.php';
497 require_once CARTFLOWS_DIR . 'classes/class-cartflows-flow-frontend.php';
498
499 /* Modules */
500 include_once CARTFLOWS_DIR . 'modules/flow/class-cartflows-flow.php';
501 include_once CARTFLOWS_DIR . 'modules/landing/class-cartflows-landing.php';
502
503 if ( $this->is_woo_active ) {
504 include_once CARTFLOWS_DIR . 'modules/checkout/class-cartflows-checkout.php';
505 include_once CARTFLOWS_DIR . 'modules/thankyou/class-cartflows-thankyou.php';
506 include_once CARTFLOWS_DIR . 'modules/optin/class-cartflows-optin.php';
507 include_once CARTFLOWS_DIR . 'modules/woo-dynamic-flow/class-cartflows-woo-dynamic-flow.php';
508 include_once CARTFLOWS_DIR . 'modules/email-report/class-cartflows-admin-report-emails.php';
509 }
510
511 if ( class_exists( '\Elementor\Plugin' ) ) {
512 // Load the widgets.
513 include_once CARTFLOWS_DIR . 'modules/elementor/class-cartflows-el-widgets-loader.php';
514 }
515
516 if ( class_exists( 'FLBuilder' ) ) {
517
518 include_once CARTFLOWS_DIR . 'modules/beaver-builder/class-cartflows-bb-modules-loader.php';
519 }
520
521 include_once CARTFLOWS_DIR . 'classes/class-cartflows-admin-notices.php';
522
523 include_once CARTFLOWS_DIR . 'classes/deprecated/deprecated-hooks.php';
524
525 include_once CARTFLOWS_DIR . 'modules/gutenberg/classes/class-cartflows-block-loader.php';
526
527 // Abilities API (WordPress 6.9+).
528 require_once CARTFLOWS_DIR . 'abilities/class-cartflows-abilities-loader.php';
529 include_once CARTFLOWS_DIR . 'modules/webhook/class-cartflows-webhook-loader.php';
530 }
531
532 /**
533 * Load Core Components.
534 *
535 * @since 1.0.0
536 *
537 * @return void
538 */
539 public function load_core_components() {
540 $this->logger = Cartflows_Logger::get_instance();
541 $this->flow = Cartflows_Flow_Frontend::get_instance();
542 }
543
544 /**
545 * Create files/directories.
546 */
547 public function create_files() {
548 // Install files and folders for uploading files and prevent hotlinking.
549 $upload_dir = wp_upload_dir();
550
551 $files = array(
552 array(
553 'base' => CARTFLOWS_LOG_DIR,
554 'file' => '.htaccess',
555 'content' => 'deny from all',
556 ),
557 array(
558 'base' => CARTFLOWS_LOG_DIR,
559 'file' => 'index.html',
560 'content' => '',
561 ),
562 );
563
564 foreach ( $files as $file ) {
565 if ( wp_mkdir_p( $file['base'] ) && ! file_exists( trailingslashit( $file['base'] ) . $file['file'] ) ) {
566 $file_handle = @fopen( trailingslashit( $file['base'] ) . $file['file'], 'w' ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged, WordPress.WP.AlternativeFunctions.file_system_read_fopen
567 if ( $file_handle ) {
568 fwrite( $file_handle, $file['content'] ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_fwrite, WordPressVIPMinimum.Functions.RestrictedFunctions.file_ops_fwrite
569 fclose( $file_handle ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_fclose
570 }
571 }
572 }
573 }
574
575 /**
576 * Load CartFlows Pro Text Domain.
577 * This will load the translation textdomain depending on the file priorities.
578 * 1. Global Languages /wp-content/languages/cartflows/ folder
579 * 2. Local dorectory /wp-content/plugins/cartflows/languages/ folder
580 *
581 * @since 1.0.3
582 * @return void
583 */
584 public function load_cf_textdomain() {
585 // Default languages directory for CartFlows Pro.
586 $lang_dir = CARTFLOWS_DIR . 'languages/';
587
588 /**
589 * Filters the languages directory path to use for CartFlows Pro.
590 *
591 * @param string $lang_dir The languages directory path.
592 */
593 $lang_dir = apply_filters( 'cartflows_languages_directory', $lang_dir );
594
595 // Traditional WordPress plugin locale filter.
596 global $wp_version;
597
598 $get_locale = get_locale();
599
600 if ( $wp_version >= 4.7 ) {
601 $get_locale = get_user_locale();
602 }
603
604 /**
605 * Language Locale for CartFlows Pro
606 *
607 * @var $get_locale The locale to use.
608 * Uses get_user_locale()` in WordPress 4.7 or greater,
609 * otherwise uses `get_locale()`.
610 */
611 $locale = apply_filters( 'plugin_locale', $get_locale, 'cartflows' );
612 $mofile = sprintf( '%1$s-%2$s.mo', 'cartflows', $locale );
613
614 // Setup paths to current locale file.
615 $mofile_local = $lang_dir . $mofile;
616 $mofile_global = WP_LANG_DIR . '/plugins/' . $mofile;
617
618 if ( file_exists( $mofile_global ) ) {
619 // Look in global /wp-content/languages/cartflows/ folder.
620 load_textdomain( 'cartflows', $mofile_global );
621 } elseif ( file_exists( $mofile_local ) ) {
622 // Look in local /wp-content/plugins/cartflows/languages/ folder.
623 load_textdomain( 'cartflows', $mofile_local );
624 } else {
625 // Load the default language files.
626 load_plugin_textdomain( 'cartflows', false, $lang_dir );
627 }
628 }
629
630 /**
631 * Fires admin notice when Elementor is not installed and activated.
632 *
633 * @since 1.0.0
634 *
635 * @return void
636 */
637 public function fails_to_load() {
638 $screen = get_current_screen();
639
640 if ( ! wcf()->utils->is_step_post_type() ) {
641 return;
642 }
643
644 if ( ! wcf()->utils->check_is_woo_required_page() ) {
645 return;
646 }
647
648 $skip_notice = false;
649
650 wp_localize_script( 'wcf-global-admin', 'cartflows_woo', array( 'show_update_post' => $skip_notice ) );
651
652 $class = 'notice notice-warning';
653 /* translators: %s: html tags */
654 $message = sprintf( __( 'This %1$sCartFlows%2$s page requires %1$sWooCommerce%2$s plugin installed & activated.', 'cartflows' ), '<strong>', '</strong>' );
655
656 $plugin = 'woocommerce/woocommerce.php';
657
658 if ( _is_woo_installed() ) {
659 if ( ! current_user_can( 'activate_plugins' ) ) {
660 return;
661 }
662
663 $action_url = wp_nonce_url( 'plugins.php?action=activate&amp;plugin=' . $plugin . '&amp;plugin_status=all&amp;paged=1&amp;s', 'activate-plugin_' . $plugin );
664 $button_label = __( 'Activate WooCommerce', 'cartflows' );
665 } else {
666 if ( ! current_user_can( 'install_plugins' ) ) {
667 return;
668 }
669
670 $action_url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=woocommerce' ), 'install-plugin_woocommerce' );
671 $button_label = __( 'Install WooCommerce', 'cartflows' );
672 }
673
674 $button = '<p><a href="' . $action_url . '" class="button-primary">' . $button_label . '</a></p><p></p>';
675
676 printf( '<div class="%1$s"><p>%2$s</p>%3$s</div>', esc_attr( $class ), wp_kses_post( $message ), wp_kses_post( $button ) );
677 }
678
679 /**
680 * Activation Reset
681 */
682 public function activation_reset() {
683 if ( ! defined( 'CARTFLOWS_LOG_DIR' ) ) {
684
685 $upload_dir = wp_upload_dir( null, false );
686
687 define( 'CARTFLOWS_LOG_DIR', $upload_dir['basedir'] . '/cartflows-logs/' );
688 }
689
690 $this->create_files();
691 include_once CARTFLOWS_DIR . 'classes/class-cartflows-helper.php';
692 include_once CARTFLOWS_DIR . 'classes/class-cartflows-functions.php';
693 include_once CARTFLOWS_DIR . 'modules/flow/classes/class-cartflows-flow-post-type.php';
694 include_once CARTFLOWS_DIR . 'modules/flow/classes/class-cartflows-step-post-type.php';
695
696 Cartflows_Flow_Post_Type::get_instance()->flow_post_type();
697 Cartflows_Step_Post_Type::get_instance()->step_post_type();
698 // Required to flush rules while registering custom post type.
699 flush_rewrite_rules(); //phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.flush_rewrite_rules_flush_rewrite_rules
700
701 // Update the cartflows asset version when plugin activated.
702 update_option( 'cartflows-assets-version', time() );
703
704 update_option( 'wcf_start_onboarding', true );
705
706 // Record install time for time-to-value analytics (only on fresh install).
707 Cartflows_Helper::set_analytics_flag( 'usage_installed_time', time() );
708 }
709
710 /**
711 * Deactivation Reset
712 */
713 public function deactivation_reset() {
714 }
715
716 /**
717 * Logger Class Instance
718 */
719 public function logger() {
720 return Cartflows_Logger::get_instance();
721 }
722 }
723
724 /**
725 * Prepare if class 'Cartflows_Loader' exist.
726 * Kicking this off by calling 'get_instance()' method
727 */
728 Cartflows_Loader::get_instance();
729 }
730
731 /**
732 * Get global class.
733 *
734 * @return object
735 */
736 function wcf() { //phpcs:ignore Universal.Files.SeparateFunctionsFromOO.Mixed
737 return Cartflows_Loader::get_instance();
738 }
739
740 if ( ! function_exists( '_is_woo_installed' ) ) {
741
742 /**
743 * Is woocommerce plugin installed.
744 *
745 * @since 1.0.0
746 *
747 * @access public
748 */
749 function _is_woo_installed() {
750 $path = 'woocommerce/woocommerce.php';
751 $plugins = get_plugins();
752
753 return isset( $plugins[ $path ] );
754 }
755 }
756