| 1 |
<?php |
| 2 |
/** |
| 3 |
* Setup wizard |
| 4 |
* |
| 5 |
* @package |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace WPFunnels\Admin; |
| 9 |
|
| 10 |
use WPFunnels\Traits\SingletonTrait; |
| 11 |
|
| 12 |
class SetupWizard |
| 13 |
{ |
| 14 |
use SingletonTrait; |
| 15 |
|
| 16 |
|
| 17 |
public $step_name; |
| 18 |
|
| 19 |
public $steps; |
| 20 |
|
| 21 |
public function __construct() |
| 22 |
{ |
| 23 |
$this->setup_wizard(); |
| 24 |
} |
| 25 |
|
| 26 |
/** |
| 27 |
* Initialize setup wizards |
| 28 |
* |
| 29 |
* @since 1.0.0 |
| 30 |
*/ |
| 31 |
private function setup_wizard() |
| 32 |
{ |
| 33 |
|
| 34 |
$steps = array( |
| 35 |
'type' => array( |
| 36 |
'name' => 'Funnel Type', |
| 37 |
'slug' => 'funnel-type', |
| 38 |
'icon' => WPFNL_URL . 'admin/assets/images/funnel-type.svg', |
| 39 |
'iconActive'=> WPFNL_URL . 'admin/assets/images/funnel-type-active.svg', |
| 40 |
'iconCompleted'=> WPFNL_URL . 'admin/assets/images/funnel-type-completed.svg', |
| 41 |
'completed' => false, |
| 42 |
'isActive' => false, |
| 43 |
), |
| 44 |
'builder' => array( |
| 45 |
'name' => 'Builder Type', |
| 46 |
'slug' => 'builder-type', |
| 47 |
'icon' => WPFNL_URL . 'admin/assets/images/builder.svg', |
| 48 |
'iconActive'=> WPFNL_URL . 'admin/assets/images/builder-active.svg', |
| 49 |
'iconCompleted'=> WPFNL_URL . 'admin/assets/images/builder-completed.svg', |
| 50 |
'completed' => false, |
| 51 |
'isActive' => false, |
| 52 |
), |
| 53 |
'automation' => array( |
| 54 |
'name' => 'Email Automation', |
| 55 |
'slug' => 'email-automation', |
| 56 |
'icon' => WPFNL_URL . 'admin/assets/images/email-automation.svg', |
| 57 |
'iconActive'=> WPFNL_URL . 'admin/assets/images/email-automation-active.svg', |
| 58 |
'iconCompleted'=> WPFNL_URL . 'admin/assets/images/email-automation-completed.svg', |
| 59 |
'completed' => false, |
| 60 |
'isActive' => false, |
| 61 |
), |
| 62 |
'permalink' => array( |
| 63 |
'name' => 'Permalink', |
| 64 |
'slug' => 'permalink', |
| 65 |
'icon' => WPFNL_URL . 'admin/assets/images/permalink.svg', |
| 66 |
'iconActive'=> WPFNL_URL . 'admin/assets/images/permalink-active.svg', |
| 67 |
'iconCompleted'=> WPFNL_URL . 'admin/assets/images/permalink-completed.svg', |
| 68 |
'completed' => false, |
| 69 |
'isActive' => false, |
| 70 |
), |
| 71 |
'thankyou' => array( |
| 72 |
'name' => 'Thank You', |
| 73 |
'slug' => 'thankyou', |
| 74 |
'icon' => WPFNL_URL . 'admin/assets/images/thankyou.svg', |
| 75 |
'iconActive'=> WPFNL_URL . 'admin/assets/images/thankyou-active.svg', |
| 76 |
'iconCompleted'=> WPFNL_URL . 'admin/assets/images/thankyou-completed.svg', |
| 77 |
'completed' => false, |
| 78 |
'isActive' => false, |
| 79 |
), |
| 80 |
); |
| 81 |
$this->step_name = isset( $_GET['step'] ) ? sanitize_text_field( $_GET['step'] ) : current( array_keys( $steps ) ); |
| 82 |
foreach ( $steps as $key => $step ) { |
| 83 |
if( $key === $this->step_name ) { |
| 84 |
$step['isActive'] = true; |
| 85 |
$this->steps[$key] = $step; |
| 86 |
} else { |
| 87 |
$step['completed'] = array_search($this->step_name,array_keys($steps)) > array_search($key,array_keys($steps)) ; |
| 88 |
$this->steps[$key] = $step; |
| 89 |
} |
| 90 |
} |
| 91 |
$installed_plugins = get_plugins(); |
| 92 |
|
| 93 |
wp_enqueue_style('setup-wizard', WPFNL_URL . 'admin/assets/css/wpfnl-admin.css', false, '1.1', 'all'); |
| 94 |
wp_enqueue_script('setup-wizard-runtime', WPFNL_URL . 'admin/assets/dist/runtime/index.min.js', array(), time(), true); |
| 95 |
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); |
| 96 |
wp_localize_script('setup-wizard', 'setup_wizard_obj', |
| 97 |
array( |
| 98 |
'rest_api_url' => esc_url_raw(get_rest_url()), |
| 99 |
'dashboard_url' => esc_url_raw(admin_url('admin.php?page=' . WPFNL_MAIN_PAGE_SLUG)), |
| 100 |
'settings_url' => class_exists( 'WooCommerce' ) ? esc_url_raw(admin_url('admin.php?page=wpfnl_settings')) : esc_url_raw(admin_url()), |
| 101 |
'wizard_url' => esc_url_raw(admin_url('admin.php?page=wpfunnels-setup')), |
| 102 |
'home_url' => esc_url_raw(home_url()), |
| 103 |
'nonce' => wp_create_nonce('wp_rest'), |
| 104 |
'current_step' => $this->step_name, |
| 105 |
'steps' => $this->steps, |
| 106 |
'next_step_link' => $this->get_next_step_link(), |
| 107 |
'prev_step_link' => $this->get_prev_step_link(), |
| 108 |
'is_woo_installed' => isset( $installed_plugins['woocommerce/woocommerce.php'] ) ? 'yes' : 'no', |
| 109 |
'is_mrm_installed' => isset( $installed_plugins['mail-mint/mail-mint.php'] ) ? 'yes' : 'no', |
| 110 |
'is_elementor_installed'=> isset( $installed_plugins['elementor/elementor.php'] ) ? 'yes' : 'no', |
| 111 |
'is_ff_installed' => isset( $installed_plugins['fluentform/fluentform.php'] ) ? 'yes' : 'no', |
| 112 |
'is_cl_installed' => isset( $installed_plugins['cart-lift/cart-lift.php'] ) ? 'yes' : 'no', |
| 113 |
'is_lms_installed' => is_plugin_active( 'wpfunnels-pro-lms/wpfunnels-pro-lms.php' ) ? 'yes' : 'no', |
| 114 |
'is_qb_installed' => isset( $installed_plugins['qubely/qubely.php'] ) ? 'yes' : 'no', |
| 115 |
'is_woo_active' => is_plugin_active( 'woocommerce/woocommerce.php' ) ? 'yes' : 'no', |
| 116 |
'is_elementor_active' => is_plugin_active( 'elementor/elementor.php' ) ? 'yes' : 'no', |
| 117 |
'is_mrm_active' => is_plugin_active( 'mail-mint/mail-mint.php' ) ? 'yes' : 'no', |
| 118 |
'is_ff_active' => is_plugin_active( 'fluentform/fluentform.php' ) ? 'yes' : 'no', |
| 119 |
'is_cl_active' => is_plugin_active( 'cart-lift/cart-lift.php' ) ? 'yes' : 'no', |
| 120 |
'is_qb_active' => is_plugin_active( 'qubely/qubely.php' ) ? 'yes' : 'no', |
| 121 |
'funnel_type' => $this->get_funnel_type() |
| 122 |
) |
| 123 |
); |
| 124 |
|
| 125 |
$this->output_html(); |
| 126 |
} |
| 127 |
|
| 128 |
|
| 129 |
/** |
| 130 |
* Get funnel type |
| 131 |
* |
| 132 |
* @since 2.5.3 |
| 133 |
*/ |
| 134 |
private function get_funnel_type(){ |
| 135 |
$general_settings = get_option( '_wpfunnels_general_settings' ); |
| 136 |
if( isset($general_settings['funnel_type']) ){ |
| 137 |
if( 'woocommerce' == $general_settings['funnel_type'] ){ |
| 138 |
return 'sales'; |
| 139 |
} |
| 140 |
return $general_settings['funnel_type']; |
| 141 |
} |
| 142 |
return 'sales'; |
| 143 |
} |
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
/** |
| 149 |
* Get next step link |
| 150 |
* |
| 151 |
* @return string|void |
| 152 |
* @since 1.0.0 |
| 153 |
*/ |
| 154 |
private function get_next_step_link() { |
| 155 |
$keys = array_keys( $this->steps ); |
| 156 |
$step_index = array_search( $this->step_name, $keys, true ); |
| 157 |
$step_index = ( count( $keys ) == $step_index + 1 ) ? $step_index : $step_index + 1; |
| 158 |
$step = $keys[ $step_index ]; |
| 159 |
return admin_url( 'admin.php?page=wpfunnels-setup&step=' . $step ); |
| 160 |
} |
| 161 |
|
| 162 |
|
| 163 |
/** |
| 164 |
* Get prev step link |
| 165 |
* |
| 166 |
* @return string|void |
| 167 |
* @since 1.0.0 |
| 168 |
*/ |
| 169 |
private function get_prev_step_link() { |
| 170 |
$keys = array_keys( $this->steps ); |
| 171 |
$step = ''; |
| 172 |
$step_index = array_search( $this->step_name, $keys, true ); |
| 173 |
$step_index = ( count( $keys ) == $step_index - 1 ) ? $step_index : $step_index - 1; |
| 174 |
if (isset($keys[ $step_index ])) { |
| 175 |
$step = $keys[ $step_index ]; |
| 176 |
} |
| 177 |
|
| 178 |
return admin_url( 'admin.php?page=wpfunnels-setup&step=' . $step ); |
| 179 |
} |
| 180 |
|
| 181 |
|
| 182 |
/** |
| 183 |
* Output the rendered contents |
| 184 |
* |
| 185 |
* @since 1.0.0 |
| 186 |
*/ |
| 187 |
private function output_html() |
| 188 |
{ |
| 189 |
require_once plugin_dir_path(__FILE__) . 'views/views.php'; |
| 190 |
exit(); |
| 191 |
} |
| 192 |
} |
| 193 |
|