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-admin.php

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

491 lines 13.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * CartFlows Admin.
4 *
5 * @package CartFlows
6 */
7
8 /**
9 * Class Cartflows_Admin.
10 */
11 class Cartflows_Admin {
12
13 /**
14 * Calls on initialization
15 *
16 * @since 1.0.0
17 */
18 public static function init() {
19
20 self::initialise_plugin();
21 self::init_hooks();
22 }
23
24 /**
25 * Init Hooks.
26 *
27 * @since 1.0.0
28 * @return void
29 */
30 static public function init_hooks() {
31
32 if ( ! is_admin() ) {
33 return;
34 }
35
36 include_once CARTFLOWS_DIR . 'classes/class-cartflows-admin-fields.php';
37
38 // Add CARTFLOWS menu option to admin.
39 add_action( 'network_admin_menu', __CLASS__ . '::menu' );
40 add_action( 'admin_menu', __CLASS__ . '::menu' );
41 add_action( 'admin_menu', __CLASS__ . '::submenu', 999 );
42
43 add_action( 'cartflows_render_admin_content', __CLASS__ . '::render_content' );
44
45 add_action( 'init', __CLASS__ . '::settings_admin_scripts' );
46
47 /* Global Addmin Script */
48 add_action( 'admin_enqueue_scripts', __CLASS__ . '::global_admin_scripts', 20 );
49
50 add_action( 'admin_footer', __CLASS__ . '::global_admin_data', 9555 );
51
52 /* Add lite version class to body */
53 add_action( 'admin_body_class', __CLASS__ . '::add_admin_body_class' );
54 }
55
56
57 /**
58 * Initialize after Cartflows pro get loaded.
59 */
60 static public function settings_admin_scripts() {
61 // Enqueue admin scripts.
62 if ( isset( $_REQUEST['page'] ) && CARTFLOWS_SETTINGS == $_REQUEST['page'] ) {
63 add_action( 'admin_enqueue_scripts', __CLASS__ . '::styles_scripts' );
64
65 self::save_settings();
66 }
67 }
68 /**
69 * Initialises the Plugin Name.
70 *
71 * @since 1.0.0
72 * @return void
73 */
74 static public function initialise_plugin() {
75
76 $name = 'Cartflows';
77 $short_name = 'Cflows';
78
79 define( 'CARTFLOWS_PLUGIN_NAME', $name );
80 define( 'CARTFLOWS_PLUGIN_SHORT_NAME', $short_name );
81 }
82
83 /**
84 * Renders the admin settings menu.
85 *
86 * @since 1.0.0
87 * @return void
88 */
89 static public function menu() {
90
91 if ( ! current_user_can( 'manage_options' ) ) {
92 return;
93 }
94
95 add_menu_page(
96 'CartFlows',
97 'CartFlows',
98 'manage_options',
99 CARTFLOWS_SLUG,
100 __CLASS__ . '::render',
101 'data:image/svg+xml;base64,' . base64_encode( file_get_contents( CARTFLOWS_DIR . 'assets/images/cartflows-icon.svg' ) ),
102 39.7
103 );
104
105 }
106
107 /**
108 * Add submenu to admin menu.
109 *
110 * @since 1.0.0
111 */
112 static function submenu() {
113
114 $parent_slug = CARTFLOWS_SLUG;
115 $page_title = __( 'Settings', 'cartflows' );
116 $menu_title = __( 'Settings', 'cartflows' );
117 $capability = 'manage_options';
118 $menu_slug = 'cartflows_settings';
119 $callback = __CLASS__ . '::render';
120
121 add_submenu_page(
122 $parent_slug,
123 $page_title,
124 $menu_title,
125 $capability,
126 $menu_slug,
127 $callback
128 );
129 }
130
131 /**
132 * Renders the admin settings.
133 *
134 * @since 1.0.0
135 * @return void
136 */
137 static public function render() {
138 $action = ( isset( $_GET['action'] ) ) ? sanitize_text_field( $_GET['action'] ) : '';
139 $action = ( ! empty( $action ) && '' != $action ) ? $action : 'general';
140 $action = str_replace( '_', '-', $action );
141
142 // Enable header icon filter below.
143 $header_wrapper_class = apply_filters( 'cartflows_header_wrapper_class', array( $action ) );
144
145 include_once CARTFLOWS_DIR . 'includes/admin/cartflows-admin.php';
146 }
147
148 /**
149 * Renders the admin settings content.
150 *
151 * @since 1.0.0
152 * @return void
153 */
154 static public function render_content() {
155
156 $action = ( isset( $_GET['action'] ) ) ? sanitize_text_field( $_GET['action'] ) : '';
157 $action = ( ! empty( $action ) && '' != $action ) ? $action : 'general';
158 $action = str_replace( '_', '-', $action );
159 $action = 'general';
160
161 $header_wrapper_class = apply_filters( 'cartflows_header_wrapper_class', array( $action ) );
162
163 include_once CARTFLOWS_DIR . 'includes/admin/cartflows-general.php';
164 }
165
166 /**
167 * Save Global Setting options.
168 *
169 * @since 1.0.0
170 */
171 static public function save_common_settings() {
172
173 if ( isset( $_POST['cartflows-common-settings-nonce'] ) && wp_verify_nonce( $_POST['cartflows-common-settings-nonce'], 'cartflows-common-settings' ) ) {
174
175 $url = $_SERVER['REQUEST_URI'];
176 $input_settings = array();
177 $new_settings = array();
178
179 if ( isset( $_POST['_cartflows_common'] ) ) {
180
181 $input_settings = $_POST['_cartflows_common'];
182
183 // Loop through the input and sanitize each of the values.
184 foreach ( $input_settings as $key => $val ) {
185
186 if ( is_array( $val ) ) {
187 foreach ( $val as $k => $v ) {
188 $new_settings[ $key ][ $k ] = ( isset( $val[ $k ] ) ) ? sanitize_text_field( $v ) : '';
189 }
190 } else {
191 $new_settings[ $key ] = ( isset( $input_settings[ $key ] ) ) ? sanitize_text_field( $val ) : '';
192 }
193 }
194 }
195
196 Cartflows_Helper::update_admin_settings_option( '_cartflows_common', $new_settings, true );
197
198 $query = array(
199 'message' => 'saved',
200 );
201
202 $redirect_to = add_query_arg( $query, $url );
203
204 wp_redirect( $redirect_to );
205 exit;
206 } // End if statement.
207 }
208
209 /**
210 * Save Debug Setting options.
211 *
212 * @since 1.1.14
213 */
214 static public function save_debug_settings() {
215
216 if ( isset( $_POST['cartflows-debug-settings-nonce'] ) && wp_verify_nonce( $_POST['cartflows-debug-settings-nonce'], 'cartflows-debug-settings' ) ) {
217
218 $url = $_SERVER['REQUEST_URI'];
219 $input_settings = array();
220 $new_settings = array();
221
222 if ( isset( $_POST['_cartflows_debug_data'] ) ) {
223
224 $input_settings = $_POST['_cartflows_debug_data'];
225
226 // Loop through the input and sanitize each of the values.
227 foreach ( $input_settings as $key => $val ) {
228
229 if ( is_array( $val ) ) {
230 foreach ( $val as $k => $v ) {
231 $new_settings[ $key ][ $k ] = ( isset( $val[ $k ] ) ) ? sanitize_text_field( $v ) : '';
232 }
233 } else {
234 $new_settings[ $key ] = ( isset( $input_settings[ $key ] ) ) ? sanitize_text_field( $val ) : '';
235 }
236 }
237 }
238
239 Cartflows_Helper::update_admin_settings_option( '_cartflows_debug_data', $new_settings, true );
240
241 $query = array(
242 'message' => 'saved',
243 );
244
245 $redirect_to = add_query_arg( $query, $url );
246
247 wp_redirect( $redirect_to );
248 exit;
249
250 }
251 }
252
253 /**
254 * Check is cartflows admin.
255 *
256 * @since 1.0.0
257 * @return boolean
258 */
259 static public function is_global_admin() {
260
261 $current_screen = get_current_screen();
262
263 if (
264 is_object( $current_screen ) &&
265 isset( $current_screen->post_type ) &&
266 ( CARTFLOWS_FLOW_POST_TYPE === $current_screen->post_type ||
267 CARTFLOWS_STEP_POST_TYPE === $current_screen->post_type
268 )
269 ) {
270 return true;
271 }
272 return false;
273 }
274
275 /**
276 * Check is flow admin.
277 *
278 * @since 1.0.0
279 * @return boolean
280 */
281 static public function is_flow_edit_admin() {
282
283 $current_screen = get_current_screen();
284
285 if (
286 is_object( $current_screen ) &&
287 isset( $current_screen->post_type ) &&
288 ( CARTFLOWS_FLOW_POST_TYPE === $current_screen->post_type ) &&
289 isset( $current_screen->base ) &&
290 ( 'post' === $current_screen->base )
291 ) {
292 return true;
293 }
294 return false;
295 }
296
297 /**
298 * Global Admin Scripts.
299 *
300 * @since 1.0.0
301 */
302 static public function global_admin_scripts() {
303
304 $localize = array(
305 'ajaxurl' => admin_url( 'admin-ajax.php' ),
306 'ajax_nonce' => wp_create_nonce( 'cartflows-nonce' ),
307 );
308
309 wp_localize_script( 'jquery', 'cartflows_admin', apply_filters( 'cartflows_admin_js_localize', $localize ) );
310
311 if ( self::is_global_admin() ) {
312
313 // Styles.
314 wp_enqueue_style( 'cartflows-global-admin', CARTFLOWS_URL . 'admin/assets/css/global-admin.css', array(), CARTFLOWS_VER );
315 wp_style_add_data( 'cartflows-global-admin', 'rtl', 'replace' );
316
317 wp_enqueue_script(
318 'wcf-global-admin',
319 CARTFLOWS_URL . 'admin/assets/js/global-admin.js',
320 array( 'jquery' ),
321 CARTFLOWS_VER,
322 true
323 );
324
325 do_action( 'cartflows_global_admin_scripts' );
326 }
327 }
328
329 /**
330 * Global Admin Data.
331 *
332 * @since 1.0.0
333 */
334 static public function global_admin_data() {
335
336 $current_screen = get_current_screen();
337
338 if ( ! $current_screen ) {
339 return;
340 }
341
342 if ( 'edit-' . CARTFLOWS_FLOW_POST_TYPE != $current_screen->id ) {
343 return;
344 }
345
346 $default_page_builder = Cartflows_Helper::get_common_setting( 'default_page_builder' );
347 ?>
348
349 <div id="wcf-remote-flow-importer" class="wcf-templates-popup-overlay">
350 <div class="wcf-templates-popup-content">
351 <div class="spinner"></div>
352 <div class="wcf-templates-wrap wcf-templates-wrap-flows">
353
354 <div id="wcf-remote-flow-actions" class="wcf-template-header">
355 <div class="wcf-template-logo-wrap">
356 <span class="wcf-cartflows-logo-img">
357 <span class="cartflows-logo-icon"></span>
358 </span>
359 <span class="wcf-cartflows-title"><?php _e( 'Flows Library', 'cartflows' ); ?></span>
360 </div>
361 <div class="wcf-tab-wrapper">
362 <?php if ( 'other' !== $default_page_builder ) { ?>
363 <div id="wcf-get-started-steps">
364 <ul class="filter-links ">
365 <li>
366 <a href="#" class="current" data-slug="ready-templates" data-title="<?php _e( 'Ready Templates', 'cartflows' ); ?>"><?php _e( 'Ready Templates', 'cartflows' ); ?></a>
367 </li>
368 <li>
369 <a href="#" data-slug="canvas" data-title="<?php _e( 'Create Your Own', 'cartflows' ); ?>"><?php _e( 'Create Your Own', 'cartflows' ); ?></a>
370 </li>
371 </ul>
372 </div>
373 <?php } ?>
374 </div>
375 <div class="wcf-popup-close-wrap">
376 <span class="close-icon"><span class="wcf-cartflow-icons dashicons dashicons-no"></span></span>
377 </div>
378 </div>
379 <!-- <div class="wcf-search-form">
380 <label class="screen-reader-text" for="wp-filter-search-input"><?php _e( 'Search Sites', 'cartflows' ); ?> </label>
381 <input placeholder="<?php _e( 'Search Flow...', 'cartflows' ); ?>" type="text" aria-describedby="live-search-desc" class="wcf-flow-search-input">
382 </div> -->
383
384 <div id="wcf-remote-content">
385 <?php if ( 'other' !== $default_page_builder ) { ?>
386 <div id="wcf-ready-templates">
387 <div id="wcf-remote-filters">
388 <div id="wcf-page-builders"></div>
389 <div id="wcf-categories"></div>
390 </div>
391 <div class="wcf-page-builder-notice"></div>
392 <div id="wcf-remote-flow-list" class="wcf-remote-list wcf-template-list-wrap"><span class="spinner is-active"></span></div>
393 <div id="wcf-upcoming-page-builders" style="display: none;" class="wcf-remote-list wcf-template-list-wrap"></div>
394 </div>
395 <?php } ?>
396 <div id="wcf-start-from-scratch" style="<?php echo ( 'other' !== $default_page_builder ) ? 'display: none;' : ''; ?>">
397 <div class="inner">
398 <a href="#" class="button button-hero button-primary cartflows-flow-import-blank"><?php _e( 'Design Your Flow', 'cartflows' ); ?></a>
399 <p class="wcf-learn-how"><a href="https://cartflows.com/docs/cartflows-step-types/" target="_blank"><?php _e( 'Learn How', 'cartflows' ); ?> <i class="dashicons dashicons-external"></i></a></p>
400 </div>
401 </div>
402 </div>
403 </div>
404 </div>
405 </div>
406
407 <?php
408 }
409
410 /**
411 * Enqueues the needed CSS/JS for the builder's admin settings page.
412 *
413 * @since 1.0.0
414 */
415 static public function styles_scripts() {
416
417 // Styles.
418 wp_enqueue_style( 'cartflows-admin-settings', CARTFLOWS_URL . 'admin/assets/css/admin-menu-settings.css', array(), CARTFLOWS_VER );
419 wp_style_add_data( 'cartflows-admin-settings', 'rtl', 'replace' );
420
421 // Script.
422 wp_enqueue_script( 'cartflows-admin-settings', CARTFLOWS_URL . 'admin/assets/js/admin-menu-settings.js', array( 'jquery', 'wp-util', 'updates' ), CARTFLOWS_VER );
423
424 $localize = array(
425 'ajax_nonce' => wp_create_nonce( 'cartflows-widget-nonce' ),
426 );
427
428 wp_localize_script( 'cartflows-admin-settings', 'cartflows', apply_filters( 'cartflows_js_localize', $localize ) );
429
430 do_action( 'cartflows_admin_settings_after_enqueue_scripts' );
431 }
432
433 /**
434 * Save All admin settings here
435 */
436 static public function save_settings() {
437
438 // Only admins can save settings.
439 if ( ! current_user_can( 'manage_options' ) ) {
440 return;
441 }
442
443 self::save_common_settings();
444 self::save_debug_settings();
445
446 // Let extensions hook into saving.
447 do_action( 'cartflows_admin_settings_save' );
448 }
449
450 /**
451 * Get and return page URL
452 *
453 * @param string $menu_slug Menu name.
454 * @since 1.0.0
455 * @return string page url
456 */
457 static public function get_page_url( $menu_slug ) {
458
459 $parent_page = self::$default_menu_position;
460
461 if ( strpos( $parent_page, '?' ) !== false ) {
462 $query_var = '&page=' . self::$plugin_slug;
463 } else {
464 $query_var = '?page=' . self::$plugin_slug;
465 }
466
467 $parent_page_url = admin_url( $parent_page . $query_var );
468
469 $url = $parent_page_url . '&action=' . $menu_slug;
470
471 return esc_url( $url );
472 }
473
474 /**
475 * Admin body classes.
476 *
477 * Body classes to be added to <body> tag in admin page
478 *
479 * @param String $classes body classes returned from the filter.
480 * @return String body classes to be added to <body> tag in admin page
481 */
482 static public function add_admin_body_class( $classes ) {
483
484 $classes .= ' cartflows-' . CARTFLOWS_VER;
485
486 return $classes;
487 }
488 }
489
490 Cartflows_Admin::init();
491