| 1 |
<?php |
| 2 |
/** |
| 3 |
* Create funnel |
| 4 |
* |
| 5 |
* @package |
| 6 |
*/ |
| 7 |
namespace WPFunnels\Modules\Admin\CreateFunnel; |
| 8 |
|
| 9 |
use WPFunnels\Admin\Module\Wpfnl_Admin_Module; |
| 10 |
use WPFunnels\Traits\SingletonTrait; |
| 11 |
use WPFunnels\Wpfnl; |
| 12 |
use WPFunnels\Wpfnl_functions; |
| 13 |
|
| 14 |
class Module extends Wpfnl_Admin_Module |
| 15 |
{ |
| 16 |
use SingletonTrait; |
| 17 |
|
| 18 |
private $builder; |
| 19 |
|
| 20 |
public function get_view() |
| 21 |
{ |
| 22 |
$this->builder = Wpfnl_functions::get_builder_type(); |
| 23 |
if (Wpfnl_functions::is_builder_active($this->builder)) { |
| 24 |
require_once WPFNL_DIR . '/admin/modules/createFunnel/views/view.php'; |
| 25 |
} else { |
| 26 |
require_once WPFNL_DIR . '/admin/modules/createFunnel/views/builder-not-activated.php'; |
| 27 |
} |
| 28 |
} |
| 29 |
|
| 30 |
public function init_ajax() |
| 31 |
{ |
| 32 |
wp_ajax_helper()->handle('create-funnel') |
| 33 |
->with_callback([ $this, 'create_funnel' ]) |
| 34 |
->with_validation($this->get_validation_data()); |
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
/** |
| 39 |
* Create funnel by ajax request |
| 40 |
* |
| 41 |
* @return array |
| 42 |
* @since 1.0.0 |
| 43 |
*/ |
| 44 |
public function create_funnel( $payload ) |
| 45 |
{ |
| 46 |
$funnel = Wpfnl::$instance->funnel_store; |
| 47 |
$funnel_id = $funnel->create($payload['funnelName']); |
| 48 |
if ( $funnel_id ) { |
| 49 |
$general_settings = get_option( '_wpfunnels_general_settings' ); |
| 50 |
if( isset($general_settings['funnel_type']) ){ |
| 51 |
if( 'woocommerce' == $general_settings['funnel_type'] ){ |
| 52 |
$general_settings['funnel_type'] = 'sales'; |
| 53 |
update_option( '_wpfunnels_general_settings', $general_settings ); |
| 54 |
|
| 55 |
} |
| 56 |
|
| 57 |
if( 'sales' == $general_settings['funnel_type'] ){ |
| 58 |
if( Wpfnl_functions::is_lms_addon_active() && isset($payload['type']) && 'lms' === $payload['type'] ){ |
| 59 |
update_post_meta( $funnel_id, '_wpfnl_funnel_type', 'lms' ); |
| 60 |
}elseif( Wpfnl_functions::is_wc_active() && isset($payload['type']) && 'wc' === $payload['type'] ){ |
| 61 |
update_post_meta( $funnel_id, '_wpfnl_funnel_type', 'wc' ); |
| 62 |
}elseif( isset($payload['type']) && 'lead' === $payload['type'] ){ |
| 63 |
update_post_meta( $funnel_id, '_wpfnl_funnel_type', 'lead' ); |
| 64 |
} |
| 65 |
|
| 66 |
}else{ |
| 67 |
|
| 68 |
if( isset($payload['type']) && 'lead' === $payload['type'] ){ |
| 69 |
update_post_meta( $funnel_id, '_wpfnl_funnel_type', 'lead' ); |
| 70 |
} |
| 71 |
} |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
$link = add_query_arg( |
| 76 |
[ |
| 77 |
'page' => 'edit_funnel', |
| 78 |
'id' => $funnel_id, |
| 79 |
], |
| 80 |
admin_url('admin.php') |
| 81 |
); |
| 82 |
|
| 83 |
return [ |
| 84 |
'success' => true, |
| 85 |
'funnelID' => $funnel_id, |
| 86 |
'redirectUrl' => $link, |
| 87 |
]; |
| 88 |
} |
| 89 |
|
| 90 |
public function get_name() |
| 91 |
{ |
| 92 |
return 'create-funnel'; |
| 93 |
} |
| 94 |
} |
| 95 |
|