PluginProbe
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell / trunk
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell vtrunk
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 2.8.17 2.8.18 2.8.19 All 258 releases
wpfunnels / admin / modules / setup-wizard / setup-wizard.php

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

432 lines 18.2 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 $steps = array(
182 'type' => array(
183 'name' => 'Funnel Type',
184 'slug' => 'funnel-type',
185 'icon' => WPFNL_URL . 'admin/assets/images/funnel-type.svg',
186 'iconActive'=> WPFNL_URL . 'admin/assets/images/funnel-type-active.svg',
187 'iconCompleted'=> WPFNL_URL . 'admin/assets/images/funnel-type-completed.svg',
188 'completed' => false,
189 'isActive' => false,
190 ),
191 'builder' => array(
192 'name' => 'Builder Type',
193 'slug' => 'builder-type',
194 'icon' => WPFNL_URL . 'admin/assets/images/builder.svg',
195 'iconActive'=> WPFNL_URL . 'admin/assets/images/builder-active.svg',
196 'iconCompleted'=> WPFNL_URL . 'admin/assets/images/builder-completed.svg',
197 'completed' => false,
198 'isActive' => false,
199 ),
200 'automation' => array(
201 'name' => 'Email Automation',
202 'slug' => 'email-automation',
203 'icon' => WPFNL_URL . 'admin/assets/images/email-automation.svg',
204 'iconActive'=> WPFNL_URL . 'admin/assets/images/email-automation-active.svg',
205 'iconCompleted'=> WPFNL_URL . 'admin/assets/images/email-automation-completed.svg',
206 'completed' => false,
207 'isActive' => false,
208 ),
209 'permalink' => array(
210 'name' => 'Permalink',
211 'slug' => 'permalink',
212 'icon' => WPFNL_URL . 'admin/assets/images/permalink.svg',
213 'iconActive'=> WPFNL_URL . 'admin/assets/images/permalink-active.svg',
214 'iconCompleted'=> WPFNL_URL . 'admin/assets/images/permalink-completed.svg',
215 'completed' => false,
216 'isActive' => false,
217 ),
218 'thankyou' => array(
219 'name' => 'Thank You',
220 'slug' => 'thankyou',
221 'icon' => WPFNL_URL . 'admin/assets/images/thankyou.svg',
222 'iconActive'=> WPFNL_URL . 'admin/assets/images/thankyou-active.svg',
223 'iconCompleted'=> WPFNL_URL . 'admin/assets/images/thankyou-completed.svg',
224 'completed' => false,
225 'isActive' => false,
226 ),
227 );
228 $this->step_name = isset( $_GET['step'] ) ? sanitize_text_field( $_GET['step'] ) : current( array_keys( $steps ) );
229 foreach ( $steps as $key => $step ) {
230 if( $key === $this->step_name ) {
231 $step['isActive'] = true;
232 $this->steps[$key] = $step;
233 } else {
234 $step['completed'] = array_search($this->step_name,array_keys($steps)) > array_search($key,array_keys($steps)) ;
235 $this->steps[$key] = $step;
236 }
237 }
238 $installed_plugins = get_plugins();
239
240 $product_url = esc_url_raw(
241 add_query_arg(
242 array(
243 'post_type' => 'product',
244 'wpfunnels' => 'yes',
245 ),
246 admin_url('post-new.php')
247 )
248 );
249
250 // Admin Name & Email Finding Starts
251 $admin_email = get_option('admin_email');
252 $admin_user = get_user_by('email', $admin_email);
253 $admin_name = $admin_user ? $admin_user->display_name : '';
254 // Admin Name & Email Finding Ends
255
256 wp_enqueue_style('setup-wizard', WPFNL_URL . 'admin/assets/css/wpfnl-admin.css', false, '1.1', 'all');
257 wp_enqueue_script('setup-wizard-runtime', WPFNL_URL . 'admin/assets/dist/runtime/index.min.js', array(), time(), true);
258 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);
259 Wpfnl_functions::enqueue_bundle_style( 'setup-wizard', 'setup-wizard-bundle' );
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 'getPlugins' => $this->get_essential_plugins(),
293 'defaultSettings' => Wpfnl_functions::get_general_settings(),
294 'logo_url' => WPFNL_URL .'admin/assets/images/setup-funnel-logo.png',
295 'welcome_image' => WPFNL_URL .'admin/assets/images/welcome-image.png',
296 'gb_builder_img' => WPFNL_URL .'admin/assets/images/gutenberg.png',
297 'elementor_img' => WPFNL_URL .'admin/assets/images/elementor.png',
298 'oxygen_img' => WPFNL_URL .'admin/assets/images/oxygen.png',
299 'divi_img' => WPFNL_URL .'admin/assets/images/divi.png',
300 'bricks_img' => WPFNL_URL .'admin/assets/images/bricks.png',
301 'others_builder_img' => WPFNL_URL .'admin/assets/images/others.png',
302 'wc_logo' => WPFNL_URL .'admin/assets/images/wc-logo.png',
303 'mail_mint_logo' => WPFNL_URL .'admin/assets/images/mail-mint.png',
304 'wizard_video_poster' => WPFNL_URL .'admin/assets/images/setup-wizard-done-video-poster.png',
305 'no_plugin_image' => WPFNL_URL .'admin/assets/images/no-plugin-install.png',
306 'qubely_img' => WPFNL_URL .'admin/assets/images/qubely.svg',
307 'quote_img' => WPFNL_URL .'admin/assets/images/quote-icon.svg',
308 'done_icon' => WPFNL_URL .'admin/assets/images/done-icon.svg',
309 'generate_funnel_image' => WPFNL_URL .'admin/assets/images/generate-funnel-image.webp',
310 'generate_store_image' => WPFNL_URL .'admin/assets/images/generate-store-checkout.webp',
311 'admin_email' => $admin_email,
312 'admin_name' => $admin_name,
313 )
314 );
315 $this->output_html();
316 }
317
318
319 /**
320 * Get essential plugins for WPFunnels
321 *
322 * @return array
323 * @since 3.3.1
324 */
325 public function get_essential_plugins(){
326 $plugins = [
327 ['name' => 'wc', 'slug' => 'woocommerce', 'type' => 'plugin', 'constant' => 'WC_PLUGIN_FILE', 'path' => 'woocommerce/woocommerce.php'],
328 ['name' => 'mailmint', 'slug' => 'mail-mint', 'type' => 'plugin', 'constant' => 'MRM_VERSION', 'path' => 'mail-mint/mail-mint.php'],
329 ['name' => 'elementor', 'slug' => 'elementor', 'type' => 'plugin', 'constant' => 'ELEMENTOR_VERSION', 'path' => 'elementor/elementor.php'],
330 ['name' => 'qubely', 'slug' => 'qubely', 'type' => 'plugin', 'constant' => 'QUBELY_VERSION', 'path' => 'qubely/qubely.php'],
331 ['name' => 'divi', 'slug' => 'divi-builder', 'type' => 'plugin', 'constant' => 'ET_BUILDER_PLUGIN_VERSION', 'path' => 'divi-builder/divi-builder.php']
332 ];
333
334 foreach($plugins as &$plugin) {
335 $plugin['status'] = $this->get_plugin_status($plugin['constant'], $plugin['path']);
336 }
337
338 $oxygen_status = 'uninstalled';
339 if (Wpfnl_functions::is_plugin_activated('oxygen/functions.php')) {
340 $oxygen_status = 'activated';
341 } else if (Wpfnl_functions::is_plugin_installed('oxygen/functions.php')) {
342 $oxygen_status = 'installed';
343 }
344 $plugins[] = ['name' => 'oxygen', 'slug' => 'oxygen', 'type' => 'plugin', 'path' => 'oxygen/functions.php', 'status' => $oxygen_status];
345
346 $maybe_bricks = Wpfnl_functions::maybe_bricks_theme();
347 $bricks_status = $maybe_bricks ? 'activated' : 'uninstalled';
348 if (Wpfnl_functions::maybe_theme_installed('bricks') && !$maybe_bricks ) {
349 $bricks_status = 'installed';
350 }
351 $plugins[] = ['name' => 'bricks', 'slug' => 'bricks', 'type' => 'theme', 'path' => 'bricks', 'status' => $bricks_status];
352
353 $is_divi_theme_active = Wpfnl_functions::wpfnl_is_theme_active('Divi');
354 $divi_status = $is_divi_theme_active ? 'activated' : 'uninstalled';
355 if (Wpfnl_functions::maybe_theme_installed('Divi') && !$is_divi_theme_active ) {
356 $divi_status = 'installed';
357 }
358 $plugins[] = ['name' => 'divi', 'slug' => 'divi', 'type' => 'theme', 'path' => 'Divi', 'status' => $divi_status];
359
360 return $plugins;
361 }
362
363 /**
364 * Get plugin status
365 *
366 * @param string $constant
367 * @param string $path
368 * @return string
369 * @since 3.3.1
370 */
371 public function get_plugin_status($constant, $path) {
372 $installed_plugins = get_plugins();
373 if(defined($constant)){
374 return 'activated';
375 } else if(isset($installed_plugins[$path])) {
376 return 'installed';
377 } else {
378 return 'uninstalled';
379 }
380 }
381
382
383
384
385
386
387 /**
388 * Get next step link
389 *
390 * @return string|void
391 * @since 1.0.0
392 */
393 private function get_next_step_link() {
394 $keys = array_keys( $this->steps );
395 $step_index = array_search( $this->step_name, $keys, true );
396 $step_index = ( count( $keys ) == $step_index + 1 ) ? $step_index : $step_index + 1;
397 $step = $keys[ $step_index ];
398 return admin_url( 'admin.php?page=wpfunnels-setup&step=' . $step );
399 }
400
401
402 /**
403 * Get prev step link
404 *
405 * @return string|void
406 * @since 1.0.0
407 */
408 private function get_prev_step_link() {
409 $keys = array_keys( $this->steps );
410 $step = '';
411 $step_index = array_search( $this->step_name, $keys, true );
412 $step_index = ( count( $keys ) == $step_index - 1 ) ? $step_index : $step_index - 1;
413 if (isset($keys[ $step_index ])) {
414 $step = $keys[ $step_index ];
415 }
416
417 return admin_url( 'admin.php?page=wpfunnels-setup&step=' . $step );
418 }
419
420
421 /**
422 * Output the rendered contents
423 *
424 * @since 1.0.0
425 */
426 private function output_html()
427 {
428 require_once plugin_dir_path(__FILE__) . 'views/views.php';
429 exit();
430 }
431 }
432