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

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