PluginProbe
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell / 3.10.6
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell v3.10.6
3.13.3 3.13.2 3.13.1 3.13.0 3.12.13 3.12.12 3.12.11 3.12.10 3.12.9 3.12.8 3.12.7 3.12.6 3.12.5 3.12.4 3.12.3 3.12.1 3.12.2 3.12.0 3.11.1 3.11.0 3.10.9 3.10.8 3.10.7 3.10.6 2.8.16 All 261 releases
wpfunnels / admin / modules / setup-wizard / setup-wizard.php

setup-wizard.php in WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell 3.10.6, at admin/modules/setup-wizard/setup-wizard.php

448 lines 18.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Setup wizard
4 *
5 * @package
6 */
7
8 namespace WPFunnels\Admin;
9
10 use WPFunnels\Traits\SingletonTrait;
11 use WPFunnels\Wpfnl_functions;
12
13 class SetupWizard
14 {
15 use SingletonTrait;
16
17
18 public $step_name;
19
20 public $steps;
21
22 public function __construct()
23 {
24 $this->setup_wizard();
25 }
26
27 /**
28 * Register AJAX handlers
29 * This should be called early, not just when rendering the wizard
30 *
31 * @since 3.3.1
32 */
33 public static function register_ajax_handlers() {
34 add_action('wp_ajax_wpfnl_activate_plugin', array(__CLASS__, 'ajax_activate_plugin_static'));
35 add_action('wp_ajax_wpfnl_update_step_meta', array(__CLASS__, 'ajax_update_step_meta'));
36 add_action('wp_ajax_wpfnl_activate_mail_mint', array(__CLASS__, 'ajax_activate_mail_mint'));
37 }
38
39 /**
40 * AJAX handler for updating step meta
41 *
42 * @since 3.3.1
43 */
44 public static function ajax_update_step_meta() {
45 // Check user capabilities
46 if (!current_user_can('wpf_manage_funnels')) {
47 wp_send_json_error(array('message' => 'Insufficient permissions'));
48 wp_die();
49 }
50
51 $step_id = isset($_POST['step_id']) ? absint($_POST['step_id']) : 0;
52 $meta_key = isset($_POST['meta_key']) ? sanitize_text_field($_POST['meta_key']) : '';
53 $meta_value = isset($_POST['meta_value']) ? $_POST['meta_value'] : '';
54
55 if (!$step_id || !$meta_key) {
56 wp_send_json_error(array('message' => 'Invalid parameters'));
57 wp_die();
58 }
59
60 // Decode JSON if it's a JSON string
61 if (is_string($meta_value) && (substr($meta_value, 0, 1) === '{' || substr($meta_value, 0, 1) === '[')) {
62 $decoded = json_decode(stripslashes($meta_value), true);
63 if (json_last_error() === JSON_ERROR_NONE) {
64 $meta_value = $decoded;
65 }
66 }
67
68 update_post_meta($step_id, $meta_key, $meta_value);
69
70 wp_send_json_success(array(
71 'message' => 'Meta updated successfully',
72 'step_id' => $step_id,
73 'meta_key' => $meta_key
74 ));
75 wp_die();
76 }
77
78 /**
79 * Static AJAX handler for plugin activation
80 *
81 * @since 3.3.1
82 */
83 public static function ajax_activate_plugin_static() {
84 // Check user capabilities first
85 if (!current_user_can('activate_plugins')) {
86 wp_send_json_error(array('message' => 'Insufficient permissions'));
87 wp_die();
88 }
89
90 // Get the plugin parameter
91 $plugin = isset($_POST['plugin']) ? sanitize_text_field($_POST['plugin']) : '';
92
93 if (empty($plugin)) {
94 wp_send_json_error(array('message' => 'Plugin parameter is required'));
95 wp_die();
96 }
97
98 // Check if plugin file exists
99 $plugin_file = WP_PLUGIN_DIR . '/' . $plugin;
100 if (!file_exists($plugin_file)) {
101 wp_send_json_error(array('message' => 'Plugin file not found: ' . $plugin));
102 wp_die();
103 }
104
105 // Check if already active
106 if (is_plugin_active($plugin)) {
107 wp_send_json_success(array('message' => 'Plugin is already active'));
108 wp_die();
109 }
110
111 // Activate the plugin
112 $result = activate_plugin($plugin, '', false, true);
113
114 if (is_wp_error($result)) {
115 wp_send_json_error(array('message' => $result->get_error_message()));
116 wp_die();
117 }
118
119 // Special handling for WooCommerce
120 if (strpos($plugin, 'woocommerce') !== false) {
121 delete_transient('_wc_activation_redirect');
122 }
123
124 // Special handling for Elementor
125 if (strpos($plugin, 'elementor') !== false) {
126 update_option('elementor_onboarded', true);
127 }
128
129 wp_send_json_success(array('message' => 'Plugin activated successfully', 'plugin' => $plugin));
130 wp_die();
131 }
132
133 /**
134 * AJAX handler for Mail Mint activation with explicit database initialization
135 * This ensures Mail Mint databases are created even on PHP 7.4
136 *
137 * @since 3.3.1
138 */
139 public static function ajax_activate_mail_mint() {
140 // Check user capabilities first
141 if (!current_user_can('activate_plugins')) {
142 wp_send_json_error(array('message' => 'Insufficient permissions'));
143 wp_die();
144 }
145
146 // Activate the Mail Mint plugin
147 $mail_mint_plugin = 'mail-mint/mail-mint.php';
148
149 if (!is_plugin_active($mail_mint_plugin)) {
150 $result = activate_plugin($mail_mint_plugin, '', false, true);
151
152 if (is_wp_error($result)) {
153 wp_send_json_error(array('message' => $result->get_error_message()));
154 wp_die();
155 }
156 }
157
158 // Explicitly trigger Mail Mint activation logic to ensure database creation
159 $mail_mint_file = WP_PLUGIN_DIR . '/' . $mail_mint_plugin;
160 if (file_exists($mail_mint_file)) {
161 require_once WP_PLUGIN_DIR . '/mail-mint/includes/MrmActivator.php';
162
163 // Call the activation method directly to ensure databases are created
164 \MrmActivator::activate();
165
166 // Remove the Mail Mint setup wizard transient to prevent it from showing
167 delete_transient('mailmint_show_setup_wizard');
168 }
169
170 wp_send_json_success(array('message' => 'Mail Mint activated and initialized successfully'));
171 wp_die();
172 }
173
174 /**
175 * Initialize setup wizards
176 *
177 * @since 1.0.0
178 */
179 private function setup_wizard()
180 {
181
182 $steps = array(
183 'type' => array(
184 'name' => 'Funnel Type',
185 'slug' => 'funnel-type',
186 'icon' => WPFNL_URL . 'admin/assets/images/funnel-type.svg',
187 'iconActive'=> WPFNL_URL . 'admin/assets/images/funnel-type-active.svg',
188 'iconCompleted'=> WPFNL_URL . 'admin/assets/images/funnel-type-completed.svg',
189 'completed' => false,
190 'isActive' => false,
191 ),
192 'builder' => array(
193 'name' => 'Builder Type',
194 'slug' => 'builder-type',
195 'icon' => WPFNL_URL . 'admin/assets/images/builder.svg',
196 'iconActive'=> WPFNL_URL . 'admin/assets/images/builder-active.svg',
197 'iconCompleted'=> WPFNL_URL . 'admin/assets/images/builder-completed.svg',
198 'completed' => false,
199 'isActive' => false,
200 ),
201 'automation' => array(
202 'name' => 'Email Automation',
203 'slug' => 'email-automation',
204 'icon' => WPFNL_URL . 'admin/assets/images/email-automation.svg',
205 'iconActive'=> WPFNL_URL . 'admin/assets/images/email-automation-active.svg',
206 'iconCompleted'=> WPFNL_URL . 'admin/assets/images/email-automation-completed.svg',
207 'completed' => false,
208 'isActive' => false,
209 ),
210 'permalink' => array(
211 'name' => 'Permalink',
212 'slug' => 'permalink',
213 'icon' => WPFNL_URL . 'admin/assets/images/permalink.svg',
214 'iconActive'=> WPFNL_URL . 'admin/assets/images/permalink-active.svg',
215 'iconCompleted'=> WPFNL_URL . 'admin/assets/images/permalink-completed.svg',
216 'completed' => false,
217 'isActive' => false,
218 ),
219 'thankyou' => array(
220 'name' => 'Thank You',
221 'slug' => 'thankyou',
222 'icon' => WPFNL_URL . 'admin/assets/images/thankyou.svg',
223 'iconActive'=> WPFNL_URL . 'admin/assets/images/thankyou-active.svg',
224 'iconCompleted'=> WPFNL_URL . 'admin/assets/images/thankyou-completed.svg',
225 'completed' => false,
226 'isActive' => false,
227 ),
228 );
229 $this->step_name = isset( $_GET['step'] ) ? sanitize_text_field( $_GET['step'] ) : current( array_keys( $steps ) );
230 foreach ( $steps as $key => $step ) {
231 if( $key === $this->step_name ) {
232 $step['isActive'] = true;
233 $this->steps[$key] = $step;
234 } else {
235 $step['completed'] = array_search($this->step_name,array_keys($steps)) > array_search($key,array_keys($steps)) ;
236 $this->steps[$key] = $step;
237 }
238 }
239 $installed_plugins = get_plugins();
240
241 $product_url = esc_url_raw(
242 add_query_arg(
243 array(
244 'post_type' => 'product',
245 'wpfunnels' => 'yes',
246 ),
247 admin_url('post-new.php')
248 )
249 );
250
251 // Admin Name & Email Finding Starts
252 $admin_email = get_option('admin_email');
253 $admin_user = get_user_by('email', $admin_email);
254 $admin_name = $admin_user ? $admin_user->display_name : '';
255 // Admin Name & Email Finding Ends
256
257 wp_enqueue_style('setup-wizard', WPFNL_URL . 'admin/assets/css/wpfnl-admin.css', false, '1.1', 'all');
258 wp_enqueue_script('setup-wizard-runtime', WPFNL_URL . 'admin/assets/dist/runtime/index.min.js', array(), time(), true);
259 wp_enqueue_script('setup-wizard', WPFNL_URL . 'admin/assets/dist/js/setup-wizard.min.js', array('jquery', 'wp-util', 'updates', 'setup-wizard-runtime'), time(), true);
260 wp_localize_script('setup-wizard', 'setup_wizard_obj',
261 array(
262 'rest_api_url' => esc_url_raw(get_rest_url()),
263 'ajax_url' => esc_url_raw(admin_url('admin-ajax.php')),
264 'admin_url' => esc_url_raw(admin_url()),
265 'dashboard_url' => esc_url_raw(admin_url('admin.php?page=' . WPFNL_MAIN_PAGE_SLUG)),
266 'settings_url' => class_exists( 'WooCommerce' ) ? esc_url_raw(admin_url('admin.php?page=wpfnl_settings')) : esc_url_raw(admin_url()),
267 'wizard_url' => esc_url_raw(admin_url('admin.php?page=wpfunnels-setup')),
268 'home_url' => esc_url_raw(home_url()),
269 'nonce' => wp_create_nonce('wp_rest'),
270 'product_url' => $product_url,
271 'admin_nonce' => wp_create_nonce('wpfnl-admin'),
272 'currency_symbol' => class_exists( 'WooCommerce' ) ? get_woocommerce_currency_symbol() : '$',
273 'currency_position' => class_exists( 'WooCommerce' ) ? get_option('woocommerce_currency_pos', 'left') : 'left',
274 'current_step' => $this->step_name,
275 'steps' => $this->steps,
276 'next_step_link' => $this->get_next_step_link(),
277 'prev_step_link' => $this->get_prev_step_link(),
278 'is_woo_installed' => isset( $installed_plugins['woocommerce/woocommerce.php'] ) ? 'yes' : 'no',
279 'is_mrm_installed' => isset( $installed_plugins['mail-mint/mail-mint.php'] ) ? 'yes' : 'no',
280 'is_elementor_installed'=> isset( $installed_plugins['elementor/elementor.php'] ) ? 'yes' : 'no',
281 'is_ff_installed' => isset( $installed_plugins['fluentform/fluentform.php'] ) ? 'yes' : 'no',
282 'is_cl_installed' => isset( $installed_plugins['cart-lift/cart-lift.php'] ) ? 'yes' : 'no',
283 'is_lms_installed' => is_plugin_active( 'wpfunnels-pro-lms/wpfunnels-pro-lms.php' ) ? 'yes' : 'no',
284 'is_qb_installed' => isset( $installed_plugins['qubely/qubely.php'] ) ? 'yes' : 'no',
285 'is_woo_active' => is_plugin_active( 'woocommerce/woocommerce.php' ) ? 'yes' : 'no',
286 'is_elementor_active' => is_plugin_active( 'elementor/elementor.php' ) ? 'yes' : 'no',
287 'is_mrm_active' => is_plugin_active( 'mail-mint/mail-mint.php' ) ? 'yes' : 'no',
288 'is_ff_active' => is_plugin_active( 'fluentform/fluentform.php' ) ? 'yes' : 'no',
289 'is_cl_active' => is_plugin_active( 'cart-lift/cart-lift.php' ) ? 'yes' : 'no',
290 'is_qb_active' => is_plugin_active( 'qubely/qubely.php' ) ? 'yes' : 'no',
291 'is_pro_active' => Wpfnl_functions::is_wpfnl_pro_activated() ? 'yes' : 'no',
292 'funnel_type' => $this->get_funnel_type(),
293 'getPlugins' => $this->get_essential_plugins(),
294 'defaultSettings' => Wpfnl_functions::get_general_settings(),
295 'logo_url' => WPFNL_URL .'admin/assets/images/setup-funnel-logo.png',
296 'welcome_image' => WPFNL_URL .'admin/assets/images/welcome-image.png',
297 'gb_builder_img' => WPFNL_URL .'admin/assets/images/gutenberg.png',
298 'elementor_img' => WPFNL_URL .'admin/assets/images/elementor.png',
299 'oxygen_img' => WPFNL_URL .'admin/assets/images/oxygen.png',
300 'divi_img' => WPFNL_URL .'admin/assets/images/divi.png',
301 'bricks_img' => WPFNL_URL .'admin/assets/images/bricks.png',
302 'others_builder_img' => WPFNL_URL .'admin/assets/images/others.png',
303 'wc_logo' => WPFNL_URL .'admin/assets/images/wc-logo.png',
304 'mail_mint_logo' => WPFNL_URL .'admin/assets/images/mail-mint.png',
305 'wizard_video_poster' => WPFNL_URL .'admin/assets/images/setup-wizard-done-video-poster.png',
306 'no_plugin_image' => WPFNL_URL .'admin/assets/images/no-plugin-install.png',
307 'qubely_img' => WPFNL_URL .'admin/assets/images/qubely.svg',
308 'quote_img' => WPFNL_URL .'admin/assets/images/quote-icon.svg',
309 'done_icon' => WPFNL_URL .'admin/assets/images/done-icon.svg',
310 'generate_funnel_image' => WPFNL_URL .'admin/assets/images/generate-funnel-image.webp',
311 'generate_store_image' => WPFNL_URL .'admin/assets/images/generate-store-checkout.webp',
312 'admin_email' => $admin_email,
313 'admin_name' => $admin_name,
314 )
315 );
316 $this->output_html();
317 }
318
319
320 /**
321 * Get essential plugins for WPFunnels
322 *
323 * @return array
324 * @since 3.3.1
325 */
326 public function get_essential_plugins(){
327 $plugins = [
328 ['name' => 'wc', 'slug' => 'woocommerce', 'type' => 'plugin', 'constant' => 'WC_PLUGIN_FILE', 'path' => 'woocommerce/woocommerce.php'],
329 ['name' => 'mailmint', 'slug' => 'mail-mint', 'type' => 'plugin', 'constant' => 'MRM_VERSION', 'path' => 'mail-mint/mail-mint.php'],
330 ['name' => 'elementor', 'slug' => 'elementor', 'type' => 'plugin', 'constant' => 'ELEMENTOR_VERSION', 'path' => 'elementor/elementor.php'],
331 ['name' => 'qubely', 'slug' => 'qubely', 'type' => 'plugin', 'constant' => 'QUBELY_VERSION', 'path' => 'qubely/qubely.php'],
332 ['name' => 'divi', 'slug' => 'divi-builder', 'type' => 'plugin', 'constant' => 'ET_BUILDER_PLUGIN_VERSION', 'path' => 'divi-builder/divi-builder.php']
333 ];
334
335 foreach($plugins as &$plugin) {
336 $plugin['status'] = $this->get_plugin_status($plugin['constant'], $plugin['path']);
337 }
338
339 $oxygen_status = 'uninstalled';
340 if (Wpfnl_functions::is_plugin_activated('oxygen/functions.php')) {
341 $oxygen_status = 'activated';
342 } else if (Wpfnl_functions::is_plugin_installed('oxygen/functions.php')) {
343 $oxygen_status = 'installed';
344 }
345 $plugins[] = ['name' => 'oxygen', 'slug' => 'oxygen', 'type' => 'plugin', 'path' => 'oxygen/functions.php', 'status' => $oxygen_status];
346
347 $maybe_bricks = Wpfnl_functions::maybe_bricks_theme();
348 $bricks_status = $maybe_bricks ? 'activated' : 'uninstalled';
349 if (Wpfnl_functions::maybe_theme_installed('bricks') && !$maybe_bricks ) {
350 $bricks_status = 'installed';
351 }
352 $plugins[] = ['name' => 'bricks', 'slug' => 'bricks', 'type' => 'theme', 'path' => 'bricks', 'status' => $bricks_status];
353
354 $is_divi_theme_active = Wpfnl_functions::wpfnl_is_theme_active('Divi');
355 $divi_status = $is_divi_theme_active ? 'activated' : 'uninstalled';
356 if (Wpfnl_functions::maybe_theme_installed('Divi') && !$is_divi_theme_active ) {
357 $divi_status = 'installed';
358 }
359 $plugins[] = ['name' => 'divi', 'slug' => 'divi', 'type' => 'theme', 'path' => 'Divi', 'status' => $divi_status];
360
361 return $plugins;
362 }
363
364 /**
365 * Get plugin status
366 *
367 * @param string $constant
368 * @param string $path
369 * @return string
370 * @since 3.3.1
371 */
372 public function get_plugin_status($constant, $path) {
373 $installed_plugins = get_plugins();
374 if(defined($constant)){
375 return 'activated';
376 } else if(isset($installed_plugins[$path])) {
377 return 'installed';
378 } else {
379 return 'uninstalled';
380 }
381 }
382
383
384 /**
385 * Get funnel type
386 *
387 * @since 2.5.3
388 */
389 private function get_funnel_type(){
390 $general_settings = get_option( '_wpfunnels_general_settings' );
391 if( isset($general_settings['funnel_type']) ){
392 if( 'woocommerce' == $general_settings['funnel_type'] ){
393 return 'sales';
394 }
395 return $general_settings['funnel_type'];
396 }
397 return 'sales';
398 }
399
400
401
402
403 /**
404 * Get next step link
405 *
406 * @return string|void
407 * @since 1.0.0
408 */
409 private function get_next_step_link() {
410 $keys = array_keys( $this->steps );
411 $step_index = array_search( $this->step_name, $keys, true );
412 $step_index = ( count( $keys ) == $step_index + 1 ) ? $step_index : $step_index + 1;
413 $step = $keys[ $step_index ];
414 return admin_url( 'admin.php?page=wpfunnels-setup&step=' . $step );
415 }
416
417
418 /**
419 * Get prev step link
420 *
421 * @return string|void
422 * @since 1.0.0
423 */
424 private function get_prev_step_link() {
425 $keys = array_keys( $this->steps );
426 $step = '';
427 $step_index = array_search( $this->step_name, $keys, true );
428 $step_index = ( count( $keys ) == $step_index - 1 ) ? $step_index : $step_index - 1;
429 if (isset($keys[ $step_index ])) {
430 $step = $keys[ $step_index ];
431 }
432
433 return admin_url( 'admin.php?page=wpfunnels-setup&step=' . $step );
434 }
435
436
437 /**
438 * Output the rendered contents
439 *
440 * @since 1.0.0
441 */
442 private function output_html()
443 {
444 require_once plugin_dir_path(__FILE__) . 'views/views.php';
445 exit();
446 }
447 }
448