PluginProbe
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce / 1.1.15
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce v1.1.15
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-wizard.php

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

448 lines 14.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Schema Pro - Schema Wizard
4 *
5 * @package Schema Pro
6 */
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit;
10 }
11
12 if ( ! class_exists( 'CartFlows_Wizard' ) ) :
13
14 /**
15 * CartFlows_Wizard class.
16 */
17 class CartFlows_Wizard {
18
19 /**
20 * Hook in tabs.
21 */
22 public function __construct() {
23 if ( apply_filters( 'cartflows_enable_setup_wizard', true ) && current_user_can( 'manage_options' ) ) {
24 add_action( 'admin_menu', array( $this, 'admin_menus' ) );
25 add_action( 'admin_init', array( $this, 'setup_wizard' ) );
26 add_action( 'admin_notices', array( $this, 'show_setup_wizard' ) );
27 add_action( 'wp_ajax_page_builder_step_save', array( $this, 'page_builder_step_save' ) );
28
29 add_filter( 'cartflows_admin_js_localize', array( $this, 'localize_vars' ) );
30 }
31 }
32
33 /**
34 * Show action links on the plugin screen.
35 *
36 * @since 1.0.0
37 * @return void
38 */
39 function show_setup_wizard() {
40
41 $status = get_option( 'wcf_setup_complete', false );
42
43 if ( false === $status ) { ?>
44 <div class="notice notice-info">
45 <p><b><?php _e( 'Thanks for installing and using CartFlows!', 'cartflows' ); ?></b></p>
46 <p><?php _e( 'It is easy to use the CartFlows. Please use the setup wizard to quick start setup.', 'cartflows' ); ?></p>
47 <p><a href="<?php echo esc_url( admin_url( 'index.php?page=cartflow-setup' ) ); ?>" class="button button-primary">Start Wizard!</a></p>
48 </div>
49 <?php
50 }
51 }
52
53 /**
54 * Add admin menus/screens.
55 */
56 public function admin_menus() {
57 add_dashboard_page( '', '', 'manage_options', 'cartflow-setup', '' );
58 }
59
60 /**
61 * Show the setup wizard.
62 */
63 public function setup_wizard() {
64
65 if ( empty( $_GET['page'] ) || 'cartflow-setup' !== $_GET['page'] ) {
66 return;
67 }
68
69 $this->steps = array(
70 'basic-config' => array(
71 'name' => __( 'Welcome', 'cartflows' ),
72 'view' => array( $this, 'welcome_step' ),
73 'handler' => array( $this, 'welcome_step_save' ),
74 ),
75 'page-builder' => array(
76 'name' => __( 'Page Builder', 'cartflows' ),
77 'view' => array( $this, 'page_builder_step' ),
78 // 'handler' => array( $this, 'page_builder_step_save' ),
79 ),
80 'setup-ready' => array(
81 'name' => __( 'Ready!', 'cartflows' ),
82 'view' => array( $this, 'ready_step' ),
83 'handler' => '',
84 ),
85 );
86
87 $this->step = isset( $_GET['step'] ) ? sanitize_key( $_GET['step'] ) : current( array_keys( $this->steps ) );
88
89 wp_enqueue_style( 'cartflows-setup', CARTFLOWS_URL . 'admin/assets/css/setup-wizard.css', array( 'dashicons' ), CARTFLOWS_VER );
90 wp_style_add_data( 'cartflows-setup', 'rtl', 'replace' );
91 wp_enqueue_script( 'cartflows-setup', CARTFLOWS_URL . 'admin/assets/js/setup-wizard.js', array( 'jquery', 'wp-util', 'updates' ), CARTFLOWS_VER );
92
93 wp_enqueue_media();
94
95 if ( ! empty( $_POST['save_step'] ) && isset( $this->steps[ $this->step ]['handler'] ) ) {
96 call_user_func( $this->steps[ $this->step ]['handler'] );
97 }
98
99 ob_start();
100 $this->setup_wizard_header();
101 $this->setup_wizard_steps();
102 $this->setup_wizard_content();
103 $this->setup_wizard_footer();
104 exit;
105 }
106
107 /**
108 * Get current step slug
109 */
110 public function get_current_step_slug() {
111 $keys = array_keys( $this->steps );
112 return $keys[ array_search( $this->step, array_keys( $this->steps ) ) ];
113 }
114
115 /**
116 * Get previous step link
117 */
118 public function get_prev_step_link() {
119 $keys = array_keys( $this->steps );
120 return add_query_arg( 'step', $keys[ array_search( $this->step, array_keys( $this->steps ) ) - 1 ] );
121 }
122
123 /**
124 * Get next step link
125 */
126 public function get_next_step_link() {
127 $keys = array_keys( $this->steps );
128 return add_query_arg( 'step', $keys[ array_search( $this->step, array_keys( $this->steps ) ) + 1 ] );
129 }
130
131 /**
132 * Get next step link
133 */
134 public function get_next_step_plain_link() {
135 $keys = array_keys( $this->steps );
136 $step = $keys[ array_search( $this->step, array_keys( $this->steps ) ) + 1 ];
137 return admin_url( 'index.php?page=cartflow-setup&step=' . $step );
138 }
139
140 /**
141 * Setup Wizard Header.
142 */
143 public function setup_wizard_header() {
144 ?>
145 <!DOCTYPE html>
146 <html>
147 <head>
148 <meta name="viewport" content="width=device-width" />
149 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
150 <title><?php _e( 'CartFlows Setup', 'cartflows' ); ?></title>
151
152 <script type="text/javascript">
153 addLoadEvent = function(func){if(typeof jQuery!="undefined")jQuery(document).ready(func);else if(typeof wpOnload!='function'){wpOnload=func;}else{var oldonload=wpOnload;wpOnload=function(){oldonload();func();}}};
154 var ajaxurl = '<?php echo admin_url( 'admin-ajax.php', 'relative' ); ?>';
155 var pagenow = '';
156 </script>
157 <?php wp_print_scripts( array( 'cartflows-setup' ) ); ?>
158 <?php do_action( 'admin_print_styles' ); ?>
159 <?php do_action( 'admin_head' ); ?>
160 </head>
161 <body class="cartflows-setup wp-core-ui cartflows-step-<?php echo esc_attr( $this->get_current_step_slug() ); ?>">
162 <div id="cartflows-logo">
163 <h1>CartFlows</h1>
164 </div>
165 <?php
166 }
167
168 /**
169 * Setup Wizard Footer.
170 */
171 public function setup_wizard_footer() {
172
173 $admin_url = admin_url( 'admin.php?page=cartflows_settings' );
174 ?>
175 <div class="close-button-wrapper">
176 <a href="<?php echo esc_url( $admin_url ); ?>" class="wizard-close-link" ><?php _e( 'Exit Setup Wizard', 'cartflows' ); ?></a>
177 </div>
178 </body>
179 </html>
180 <?php
181 }
182
183 /**
184 * Output the steps.
185 */
186 public function setup_wizard_steps() {
187
188 $ouput_steps = $this->steps;
189 ?>
190 <ol class="cartflows-setup-steps">
191 <?php
192 foreach ( $ouput_steps as $step_key => $step ) :
193 $classes = '';
194 $activated = false;
195 if ( $step_key === $this->step ) {
196 $classes = 'active';
197 $activated = true;
198 } elseif ( array_search( $this->step, array_keys( $this->steps ) ) > array_search( $step_key, array_keys( $this->steps ) ) ) {
199 $classes = 'done';
200 $activated = true;
201 }
202 ?>
203 <li class="<?php echo esc_attr( $classes ); ?>">
204 <span><?php echo esc_html( $step['name'] ); ?></span>
205 </li>
206 <?php endforeach; ?>
207 </ol>
208 <?php
209 }
210
211 /**
212 * Output the content for the current step.
213 */
214 public function setup_wizard_content() {
215 echo '<div class="cartflows-setup-content">';
216 call_user_func( $this->steps[ $this->step ]['view'] );
217 echo '</div>';
218 }
219
220 /**
221 * Introduction step.
222 */
223 public function welcome_step() {
224 ?>
225 <h1><?php _e( 'Thank you for choosing CartFlows!', 'cartflows' ); ?></h1>
226 <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
227 <form method="post">
228 <div class="cartflows-setup-actions step">
229 <div class="button-prev-wrap">
230 </div>
231 <div class="button-next-wrap">
232 <input type="submit" class="uct-activate button-primary button button-large button-next" value="<?php _e( 'Lets Go »', 'cartflows' ); ?>" name="save_step" />
233 </div>
234 <?php wp_nonce_field( 'cartflow-setup' ); ?>
235 </div>
236 </form>
237 <?php
238 }
239
240 /**
241 * Save Locale Settings.
242 */
243 public function welcome_step_save() {
244 check_admin_referer( 'cartflow-setup' );
245
246 // Update site title & tagline.
247 $redirect_url = $this->get_next_step_link();
248
249 wp_redirect( esc_url_raw( $redirect_url ) );
250 exit;
251 }
252
253 /**
254 * Locale settings
255 */
256 public function page_builder_step() {
257 ?>
258
259 <h1><?php _e( 'Page Builder', 'cartflows' ); ?></h1>
260 <p class="description"><?php _e( 'Select a page builder which you want to use for creating your new flows.', 'cartflows' ); ?></p>
261 <form method="post">
262 <table class="cartflows-table widefat">
263 <tr class="cartflows-row">
264 <td class="cartflows-row-heading">
265 <label><?php esc_html_e( 'Select Page Builder', 'cartflows' ); ?></label>
266 <i class="cartflows-heading-help dashicons dashicons-editor-help" title="<?php echo esc_attr__( 'Add locations for where this Schema should appear.', 'cartflows' ); ?>"></i>
267 </td>
268 <td class="cartflows-row-content">
269 <?php
270 $installed_plugins = get_plugins();
271 $plugins = array(
272 array(
273 'title' => __( 'Elementor', 'cartflows' ),
274 'value' => 'elementor',
275 'data' => array(
276 'slug' => 'elementor',
277 'init' => 'elementor/elementor.php',
278 'active' => is_plugin_active( 'elementor/elementor.php' ) ? 'yes' : 'no',
279 'install' => isset( $installed_plugins['elementor/elementor.php'] ) ? 'yes' : 'no',
280 ),
281 ),
282 );
283 ?>
284 <select name="page-builder" class="page-builder-list" data-redirect-link="<?php echo esc_url_raw( $this->get_next_step_plain_link() ); ?>">
285 <?php
286 foreach ( $plugins as $key => $plugin ) {
287 echo '<option value="' . esc_attr( $plugin['value'] ) . '" data-install="' . esc_attr( $plugin['data']['install'] ) . '" data-active="' . esc_attr( $plugin['data']['active'] ) . '" data-slug="' . esc_attr( $plugin['data']['slug'] ) . '" data-init="' . esc_attr( $plugin['data']['init'] ) . '">' . esc_html( $plugin['title'] ) . '</option>';
288 }
289 ?>
290 </select>
291 </td>
292 </tr>
293 </table>
294 <p><?php _e( 'The above plugin will be installed and activated for you!', 'cartflows' ); ?></p>
295 <div class="cartflows-setup-actions step">
296 <div class="button-prev-wrap">
297 <a href="<?php echo esc_url( $this->get_prev_step_link() ); ?>" class="button-primary button button-large button-prev" ><?php _e( '« Previous', 'cartflows' ); ?></a>
298 </div>
299 <div class="button-next-wrap">
300 <a href="#" class="button button-primary wcf-install-plugins"><?php _e( 'Next »', 'cartflows' ); ?></a>
301 <!-- <input type="submit" class="button-primary button button-large button-next" value="<?php esc_attr_e( 'Next »', 'cartflows' ); ?>" name="save_step" /> -->
302 </div>
303 <?php wp_nonce_field( 'cartflow-setup' ); ?>
304 </div>
305 </form>
306 <?php
307 }
308
309 /**
310 * Save Locale Settings.
311 */
312 function page_builder_step_save() {
313
314 check_ajax_referer( 'wcf-page-builder-step-save', 'security' );
315
316 $stored = get_option( 'wcf_setup', array() );
317 $page_builder = isset( $_POST['page_builder'] ) ? sanitize_text_field( $_POST['page_builder'] ) : '';
318 $plugin_init = isset( $_POST['plugin_init'] ) ? sanitize_text_field( $_POST['plugin_init'] ) : '';
319
320 if ( $page_builder ) {
321 $stored['page-builder'] = $page_builder;
322 }
323
324 update_option( 'wcf_setup', $stored );
325
326 $activate = activate_plugin( $plugin_init, '', false, true );
327
328 if ( is_wp_error( $activate ) ) {
329 wp_send_json_error(
330 array(
331 'success' => false,
332 'message' => $activate->get_error_message(),
333 )
334 );
335 }
336
337 wp_send_json_success( $stored );
338 }
339
340 /**
341 * Get Location rules of schema for Custom meta box.
342 *
343 * @param array $enabled_on Enabled on rules.
344 * @param array $exclude_from Exlcude on rules.
345 * @return array
346 */
347 public static function get_display_rules_for_meta_box( $enabled_on, $exclude_from ) {
348 $locations = array();
349 $enabled_location = array();
350 $exclude_location = array();
351
352 $args = array(
353 'public' => true,
354 '_builtin' => true,
355 );
356 $post_types = get_post_types( $args );
357 unset( $post_types['attachment'] );
358
359 $args['_builtin'] = false;
360 $custom_post_type = get_post_types( $args );
361 $post_types = array_merge( $post_types, $custom_post_type );
362
363 if ( ! empty( $enabled_on ) && isset( $enabled_on['rule'] ) ) {
364 $enabled_location = $enabled_on['rule'];
365 }
366 if ( ! empty( $exclude_from ) && isset( $exclude_from['rule'] ) ) {
367 $exclude_location = $exclude_from['rule'];
368 }
369
370 if ( in_array( 'specifics', $enabled_location ) || ( in_array( 'basic-singulars', $enabled_location ) && ! in_array( 'basic-singulars', $exclude_location ) ) ) {
371 foreach ( $post_types as $post_type ) {
372 $locations[ $post_type ] = 1;
373 }
374 } else {
375 foreach ( $post_types as $post_type ) {
376 $key = $post_type . '|all';
377 if ( in_array( $key, $enabled_location ) && ! in_array( $key, $exclude_location ) ) {
378 $locations[ $post_type ] = 1;
379 }
380 }
381 }
382 return $locations;
383 }
384
385 /**
386 * Final step.
387 */
388 public function ready_step() {
389
390 // Set setup wizard status to complete.
391 update_option( 'wcf_setup_complete', true );
392 ?>
393 <h1><?php _e( 'Congratulations!', 'cartflows' ); ?></h1>
394
395 <div class="cartflows-setup-next-steps">
396 <div class="cartflows-setup-next-steps-last">
397
398 <p class="success">
399 <?php
400 _e( 'You\'ve successfully completed the setup before you begin setting now you can use it.', 'cartflows' )
401 ?>
402 </p>
403
404
405 <ul class="wcf-wizard-next-steps">
406 <li class="wcf-wizard-next-step-item">
407 <div class="wcf-wizard-next-step-description">
408 <p class="next-step-heading">Next step</p>
409 <h3 class="next-step-description">Create First Flow</h3>
410 <p class="next-step-extra-info">You're ready to add flows to your website.</p>
411 </div>
412 <div class="wcf-wizard-next-step-action">
413 <p class="wc-setup-actions step">
414 <a href="<?php echo esc_url( admin_url( 'edit.php?post_type=cartflows_flow&add-new-flow' ) ); ?>" type="button" class="button button-primary button-hero" ><?php _e( 'Create a flow', 'cartflows' ); ?></a>
415 </p>
416 </div>
417 </li>
418 </ul>
419
420 </div>
421 </div>
422 <?php
423 }
424
425 /**
426 * Localize variables in admin
427 *
428 * @param array $vars variables.
429 */
430 function localize_vars( $vars ) {
431
432 $ajax_actions = array(
433 'wcf_page_builder_step_save',
434 );
435
436 foreach ( $ajax_actions as $action ) {
437
438 $vars[ $action . '_nonce' ] = wp_create_nonce( str_replace( '_', '-', $action ) );
439 }
440
441 return $vars;
442 }
443 }
444
445 new CartFlows_Wizard();
446
447 endif;
448