PluginProbe
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce / 1.1.19
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce v1.1.19
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.19, at classes/class-cartflows-admin.php

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