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

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