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

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