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

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