PluginProbe
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce / 1.1.15
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce v1.1.15
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 1.1.15, at classes/class-cartflows-loader.php

438 lines 10.7 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 if ( ! class_exists( 'Cartflows_Loader' ) ) {
9
10 /**
11 * Class Cartflows_Loader.
12 */
13 final class Cartflows_Loader {
14
15 /**
16 * Member Variable
17 *
18 * @var instance
19 */
20 private static $instance = null;
21
22 /**
23 * Member Variable
24 *
25 * @var utils
26 */
27 public $utils = null;
28
29 /**
30 * Member Variable
31 *
32 * @var logger
33 */
34 public $logger = null;
35
36 /**
37 * Member Variable
38 *
39 * @var session
40 */
41 public $session = null;
42
43
44 /**
45 * Member Variable
46 *
47 * @var options
48 */
49 public $options = null;
50
51 /**
52 * Member Variable
53 *
54 * @var meta
55 */
56 public $meta = null;
57
58 /**
59 * Member Variable
60 *
61 * @var flow
62 */
63 public $flow = null;
64
65 /**
66 * Member Variable
67 *
68 * @var assets_vars
69 */
70 public $assets_vars = null;
71
72 /**
73 * Initiator
74 */
75 public static function get_instance() {
76
77 if ( is_null( self::$instance ) ) {
78
79 self::$instance = new self;
80
81 /**
82 * CartFlows loaded.
83 *
84 * Fires when Cartflows was fully loaded and instantiated.
85 *
86 * @since 1.0.0
87 */
88 do_action( 'cartflows_loaded' );
89 }
90
91 return self::$instance;
92 }
93
94 /**
95 * Constructor
96 */
97 public function __construct() {
98
99 $this->define_constants();
100
101 // Activation hook.
102 register_activation_hook( CARTFLOWS_FILE, array( $this, 'activation_reset' ) );
103
104 // deActivation hook.
105 register_deactivation_hook( CARTFLOWS_FILE, array( $this, 'deactivation_reset' ) );
106
107 add_action( 'plugins_loaded', array( $this, 'load_plugin' ), 99 );
108 add_action( 'plugins_loaded', array( $this, 'load_cf_textdomain' ) );
109
110 // Update compatibility.
111 require_once CARTFLOWS_DIR . 'classes/class-cartflows-update.php';
112 }
113
114 /**
115 * Defines all constants
116 *
117 * @since 1.0.0
118 */
119 public function define_constants() {
120
121 define( 'CARTFLOWS_BASE', plugin_basename( CARTFLOWS_FILE ) );
122 define( 'CARTFLOWS_DIR', plugin_dir_path( CARTFLOWS_FILE ) );
123 define( 'CARTFLOWS_URL', plugins_url( '/', CARTFLOWS_FILE ) );
124 define( 'CARTFLOWS_VER', '1.1.15' );
125 define( 'CARTFLOWS_SLUG', 'cartflows' );
126 define( 'CARTFLOWS_SETTINGS', 'cartflows_settings' );
127
128 define( 'CARTFLOWS_FLOW_POST_TYPE', 'cartflows_flow' );
129 define( 'CARTFLOWS_STEP_POST_TYPE', 'cartflows_step' );
130
131 if ( ! defined( 'CARTFLOWS_SERVER_URL' ) ) {
132 define( 'CARTFLOWS_SERVER_URL', 'https://my.cartflows.com/' );
133 }
134 define( 'CARTFLOWS_DOMAIN_URL', 'https://cartflows.com/' );
135 define( 'CARTFLOWS_TEMPLATES_URL', 'https://templates.cartflows.com/' );
136 define( 'CARTFLOWS_TAXONOMY_STEP_TYPE', 'cartflows_step_type' );
137 define( 'CARTFLOWS_TAXONOMY_STEP_FLOW', 'cartflows_step_flow' );
138
139 if ( ! defined( 'CARTFLOWS_TAXONOMY_STEP_PAGE_BUILDER' ) ) {
140 define( 'CARTFLOWS_TAXONOMY_STEP_PAGE_BUILDER', 'cartflows_step_page_builder' );
141 }
142 if ( ! defined( 'CARTFLOWS_TAXONOMY_FLOW_PAGE_BUILDER' ) ) {
143 define( 'CARTFLOWS_TAXONOMY_FLOW_PAGE_BUILDER', 'cartflows_flow_page_builder' );
144 }
145 if ( ! defined( 'CARTFLOWS_TAXONOMY_FLOW_CATEGORY' ) ) {
146 define( 'CARTFLOWS_TAXONOMY_FLOW_CATEGORY', 'cartflows_flow_category' );
147 }
148 }
149
150 /**
151 * Loads plugin files.
152 *
153 * @since 1.0.0
154 *
155 * @return void
156 */
157 function load_plugin() {
158
159 if ( ! function_exists( 'WC' ) ) {
160 add_action( 'admin_notices', array( $this, 'fails_to_load' ) );
161 return;
162 }
163
164 $this->load_helper_files_components();
165 $this->load_core_files();
166 $this->load_core_components();
167
168 add_action( 'wp_loaded', array( $this, 'initialize' ) );
169
170 /**
171 * CartFlows Init.
172 *
173 * Fires when Cartflows is instantiated.
174 *
175 * @since 1.0.0
176 */
177 do_action( 'cartflows_init' );
178 }
179
180 /**
181 * Load Helper Files and Components.
182 *
183 * @since 1.0.0
184 *
185 * @return void
186 */
187 function load_helper_files_components() {
188
189 /* Public Utils */
190 include_once CARTFLOWS_DIR . 'classes/class-cartflows-utils.php';
191
192 /* Public Session */
193 include_once CARTFLOWS_DIR . 'classes/class-cartflows-session.php';
194
195 /* Public Global namespace functions */
196 include_once CARTFLOWS_DIR . 'classes/class-cartflows-functions.php';
197
198 /* Admin Helper */
199 include_once CARTFLOWS_DIR . 'classes/class-cartflows-helper.php';
200
201 /* Meta Default Values */
202 include_once CARTFLOWS_DIR . 'classes/class-cartflows-default-meta.php';
203
204 $this->utils = Cartflows_Utils::get_instance();
205 $this->session = Cartflows_Session::get_instance();
206 $this->options = Cartflows_Default_Meta::get_instance();
207 }
208
209 /**
210 * Init hooked function.
211 *
212 * @since 1.0.0
213 *
214 * @return void
215 */
216 function initialize() {
217 $this->assets_vars = $this->utils->get_assets_path();
218 }
219
220 /**
221 * Load Core Files.
222 *
223 * @since 1.0.0
224 *
225 * @return void
226 */
227 function load_core_files() {
228
229 /* Page builder compatibilty class */
230 include_once CARTFLOWS_DIR . 'classes/class-cartflows-compatibility.php';
231
232 /* Admin Meta Fields*/
233 include_once CARTFLOWS_DIR . 'classes/fields/typography/class-cartflows-font-families.php';
234 include_once CARTFLOWS_DIR . 'classes/class-cartflows-meta-fields.php';
235 include_once CARTFLOWS_DIR . 'classes/class-cartflows-meta.php';
236
237 /* Cloning */
238 include_once CARTFLOWS_DIR . 'classes/class-cartflows-cloning.php';
239
240 /* Admin Settings */
241 include_once CARTFLOWS_DIR . 'classes/class-cartflows-admin.php';
242
243 /* Core Modules */
244 include_once CARTFLOWS_DIR . 'classes/class-cartflows-logger.php';
245
246 /* Frontend Global */
247 include_once CARTFLOWS_DIR . 'classes/class-cartflows-frontend.php';
248 require_once CARTFLOWS_DIR . 'classes/class-cartflows-flow-frontend.php';
249
250 /* Modules */
251 include_once CARTFLOWS_DIR . 'modules/flow/class-cartflows-flow.php';
252 include_once CARTFLOWS_DIR . 'modules/landing/class-cartflows-landing.php';
253 include_once CARTFLOWS_DIR . 'modules/checkout/class-cartflows-checkout.php';
254 include_once CARTFLOWS_DIR . 'modules/thankyou/class-cartflows-thankyou.php';
255
256 include_once CARTFLOWS_DIR . 'classes/class-cartflows-api.php';
257 include_once CARTFLOWS_DIR . 'classes/class-cartflows-importer-core.php';
258
259 include_once CARTFLOWS_DIR . 'classes/batch-process/class-cartflows-batch-process.php';
260 include_once CARTFLOWS_DIR . 'classes/class-cartflows-importer.php';
261 }
262
263 /**
264 * Load Core Components.
265 *
266 * @since 1.0.0
267 *
268 * @return void
269 */
270 function load_core_components() {
271
272 $this->meta = Cartflows_Meta_Fields::get_instance();
273 $this->logger = Cartflows_Logger::get_instance();
274 $this->flow = Cartflows_Flow_Frontend::get_instance();
275 }
276
277 /**
278 * Load CartFlows Pro Text Domain.
279 * This will load the translation textdomain depending on the file priorities.
280 * 1. Global Languages /wp-content/languages/cartflows/ folder
281 * 2. Local dorectory /wp-content/plugins/cartflows/languages/ folder
282 *
283 * @since 1.0.3
284 * @return void
285 */
286 public function load_cf_textdomain() {
287
288 // Default languages directory for CartFlows Pro.
289 $lang_dir = CARTFLOWS_DIR . 'languages/';
290
291 /**
292 * Filters the languages directory path to use for CartFlows Pro.
293 *
294 * @param string $lang_dir The languages directory path.
295 */
296 $lang_dir = apply_filters( 'cartflows_languages_directory', $lang_dir );
297
298 // Traditional WordPress plugin locale filter.
299 global $wp_version;
300
301 $get_locale = get_locale();
302
303 if ( $wp_version >= 4.7 ) {
304 $get_locale = get_user_locale();
305 }
306
307 /**
308 * Language Locale for CartFlows Pro
309 *
310 * @var $get_locale The locale to use.
311 * Uses get_user_locale()` in WordPress 4.7 or greater,
312 * otherwise uses `get_locale()`.
313 */
314 $locale = apply_filters( 'plugin_locale', $get_locale, 'cartflows' );
315 $mofile = sprintf( '%1$s-%2$s.mo', 'cartflows', $locale );
316
317 // Setup paths to current locale file.
318 $mofile_local = $lang_dir . $mofile;
319 $mofile_global = WP_LANG_DIR . '/plugins/' . $mofile;
320
321 if ( file_exists( $mofile_global ) ) {
322 // Look in global /wp-content/languages/cartflows/ folder.
323 load_textdomain( 'cartflows', $mofile_global );
324 } elseif ( file_exists( $mofile_local ) ) {
325 // Look in local /wp-content/plugins/cartflows/languages/ folder.
326 load_textdomain( 'cartflows', $mofile_local );
327 } else {
328 // Load the default language files.
329 load_plugin_textdomain( 'cartflows', false, $lang_dir );
330 }
331 }
332
333 /**
334 * Fires admin notice when Elementor is not installed and activated.
335 *
336 * @since 1.0.0
337 *
338 * @return void
339 */
340 public function fails_to_load() {
341
342 $screen = get_current_screen();
343
344 if ( isset( $screen->parent_file ) && 'plugins.php' === $screen->parent_file && 'update' === $screen->id ) {
345 return;
346 }
347
348 $class = 'notice notice-error';
349 /* translators: %s: html tags */
350 $message = sprintf( __( 'The %1$sCartFlows%2$s plugin requires %1$sWooCommerce%2$s plugin installed & activated.', 'cartflows' ), '<strong>', '</strong>' );
351
352 $plugin = 'woocommerce/woocommerce.php';
353
354 if ( _is_woo_installed() ) {
355 if ( ! current_user_can( 'activate_plugins' ) ) {
356 return;
357 }
358
359 $action_url = wp_nonce_url( 'plugins.php?action=activate&amp;plugin=' . $plugin . '&amp;plugin_status=all&amp;paged=1&amp;s', 'activate-plugin_' . $plugin );
360 $button_label = __( 'Activate WooCommerce', 'cartflows' );
361
362 } else {
363 if ( ! current_user_can( 'install_plugins' ) ) {
364 return;
365 }
366
367 $action_url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=woocommerce' ), 'install-plugin_woocommerce' );
368 $button_label = __( 'Install WooCommerce', 'cartflows' );
369 }
370
371 $button = '<p><a href="' . $action_url . '" class="button-primary">' . $button_label . '</a></p><p></p>';
372
373 printf( '<div class="%1$s"><p>%2$s</p>%3$s</div>', esc_attr( $class ), $message, $button );
374 }
375
376 /**
377 * Activation Reset
378 */
379 function activation_reset() {
380
381 include_once CARTFLOWS_DIR . 'modules/flow/classes/class-cartflows-flow-post-type.php';
382 include_once CARTFLOWS_DIR . 'modules/flow/classes/class-cartflows-step-post-type.php';
383
384 Cartflows_Flow_Post_Type::get_instance()->flow_post_type();
385 Cartflows_Step_Post_Type::get_instance()->step_post_type();
386 flush_rewrite_rules();
387 }
388
389 /**
390 * Deactivation Reset
391 */
392 function deactivation_reset() {
393 }
394
395 /**
396 * Logger Class Instance
397 */
398 function logger() {
399 return Cartflows_Logger::get_instance();
400 }
401
402
403 }
404
405 /**
406 * Prepare if class 'Cartflows_Loader' exist.
407 * Kicking this off by calling 'get_instance()' method
408 */
409 Cartflows_Loader::get_instance();
410 }
411
412 /**
413 * Get global class.
414 *
415 * @return object
416 */
417 function wcf() {
418 return Cartflows_Loader::get_instance();
419 }
420
421 if ( ! function_exists( '_is_woo_installed' ) ) {
422
423 /**
424 * Is woocommerce plugin installed.
425 *
426 * @since 1.0.0
427 *
428 * @access public
429 */
430 function _is_woo_installed() {
431
432 $path = 'woocommerce/woocommerce.php';
433 $plugins = get_plugins();
434
435 return isset( $plugins[ $path ] );
436 }
437 }
438