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

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

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