| 1 |
<?php |
| 2 |
/** |
| 3 |
* Step module |
| 4 |
* |
| 5 |
* @package |
| 6 |
*/ |
| 7 |
namespace WPFunnels\Admin\Modules\Steps; |
| 8 |
|
| 9 |
use WPFunnels\Admin\Module\Steps\Wpfnl_Steps_Factory; |
| 10 |
use WPFunnels\Admin\Module\Wpfnl_Admin_Module; |
| 11 |
use WPFunnels\Wpfnl; |
| 12 |
use WPFunnels\Wpfnl_functions; |
| 13 |
use WPFunnelsPro\AbTesting\Wpfnl_Ab_Testing; |
| 14 |
class Module extends Wpfnl_Admin_Module |
| 15 |
{ |
| 16 |
protected $steps = []; |
| 17 |
|
| 18 |
protected $id; |
| 19 |
|
| 20 |
protected $type; |
| 21 |
|
| 22 |
protected $step; |
| 23 |
|
| 24 |
public $step_title; |
| 25 |
|
| 26 |
public function __construct() |
| 27 |
{ |
| 28 |
$this->steps = $this->get_steps(); |
| 29 |
} |
| 30 |
|
| 31 |
/** |
| 32 |
* Get step |
| 33 |
* |
| 34 |
* @return Obj |
| 35 |
*/ |
| 36 |
public function get_step($name) |
| 37 |
{ |
| 38 |
$this->step = Wpfnl_Steps_Factory::build($name); |
| 39 |
return $this->step; |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* Get all steps |
| 44 |
* |
| 45 |
* @return Array |
| 46 |
* @since 2.0.4 |
| 47 |
*/ |
| 48 |
public function get_steps() |
| 49 |
{ |
| 50 |
return [ |
| 51 |
'landing', |
| 52 |
'thankyou', |
| 53 |
'checkout', |
| 54 |
'upsell', |
| 55 |
'downsell', |
| 56 |
]; |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
/** |
| 61 |
* Initialize class |
| 62 |
* |
| 63 |
* @return void |
| 64 |
* @since 2.0.4 |
| 65 |
*/ |
| 66 |
public function init($id) |
| 67 |
{ |
| 68 |
$this->set_id($id); |
| 69 |
$this->step = Wpfnl::get_instance()->step_store; |
| 70 |
$this->step->read($this->get_id()); |
| 71 |
$this->set_type($this->step->get_type()); |
| 72 |
} |
| 73 |
|
| 74 |
/** |
| 75 |
* Set step ID |
| 76 |
* |
| 77 |
* @param Int $id |
| 78 |
* |
| 79 |
* @return void |
| 80 |
* @since 2.0.4 |
| 81 |
*/ |
| 82 |
public function set_id($id) |
| 83 |
{ |
| 84 |
$this->id = $id; |
| 85 |
} |
| 86 |
|
| 87 |
/** |
| 88 |
* Get step ID |
| 89 |
* |
| 90 |
* @return Int |
| 91 |
* @since 2.0.4 |
| 92 |
*/ |
| 93 |
public function get_id() |
| 94 |
{ |
| 95 |
return $this->id; |
| 96 |
} |
| 97 |
|
| 98 |
/** |
| 99 |
* Set step type |
| 100 |
* |
| 101 |
* @param String $type |
| 102 |
* |
| 103 |
* @return void |
| 104 |
* @since 2.0.4 |
| 105 |
*/ |
| 106 |
public function set_type($type) |
| 107 |
{ |
| 108 |
$this->type = $type; |
| 109 |
} |
| 110 |
|
| 111 |
|
| 112 |
/** |
| 113 |
* Get step type |
| 114 |
* |
| 115 |
* @return String |
| 116 |
* @since 2.0.4 |
| 117 |
*/ |
| 118 |
public function get_type() |
| 119 |
{ |
| 120 |
return $this->type; |
| 121 |
} |
| 122 |
|
| 123 |
|
| 124 |
/** |
| 125 |
* Set internal meta fields for this step |
| 126 |
* |
| 127 |
* @since 1.0.0 |
| 128 |
*/ |
| 129 |
public function set_internal_meta_value() |
| 130 |
{ |
| 131 |
$meta_values = []; |
| 132 |
foreach ($this->_internal_keys as $key => $value) { |
| 133 |
$meta_value = $this->step->get_meta($this->get_id(), $key); |
| 134 |
$meta_values[$key] = $meta_value ? $meta_value : $value; |
| 135 |
} |
| 136 |
$this->_internal_keys = $meta_values; |
| 137 |
} |
| 138 |
|
| 139 |
|
| 140 |
/** |
| 141 |
* Get internal meta |
| 142 |
* |
| 143 |
* @return Array |
| 144 |
* @since 2.0.4 |
| 145 |
*/ |
| 146 |
public function get_internal_metas() |
| 147 |
{ |
| 148 |
return $this->_internal_keys; |
| 149 |
} |
| 150 |
|
| 151 |
/** |
| 152 |
* Get meta value by key |
| 153 |
* |
| 154 |
* @param $key |
| 155 |
* |
| 156 |
* @return mixed |
| 157 |
* @since 1.0.0 |
| 158 |
*/ |
| 159 |
public function get_internal_metas_by_key($key) |
| 160 |
{ |
| 161 |
if (isset($this->_internal_keys[$key])) { |
| 162 |
return $this->_internal_keys[$key]; |
| 163 |
} |
| 164 |
|
| 165 |
return ''; |
| 166 |
} |
| 167 |
|
| 168 |
/** |
| 169 |
* Get module name |
| 170 |
* |
| 171 |
* @return String |
| 172 |
* @since 2.0.4 |
| 173 |
*/ |
| 174 |
public function get_name() |
| 175 |
{ |
| 176 |
return __('steps', 'wpfnl'); |
| 177 |
} |
| 178 |
|
| 179 |
|
| 180 |
/** |
| 181 |
* Initialize ajax callback functions |
| 182 |
* |
| 183 |
* @return void |
| 184 |
* @since 2.0.4 |
| 185 |
*/ |
| 186 |
public function init_ajax() |
| 187 |
{ |
| 188 |
wp_ajax_helper()->handle('step-edit') |
| 189 |
->with_callback([ $this, 'step_edit' ]) |
| 190 |
->with_validation($this->get_validation_data()); |
| 191 |
|
| 192 |
} |
| 193 |
|
| 194 |
/** |
| 195 |
* Edit step by ajax request |
| 196 |
* |
| 197 |
* @return array |
| 198 |
* @since 1.0.0 |
| 199 |
*/ |
| 200 |
public function step_edit($payload) |
| 201 |
{ |
| 202 |
$step_id = $payload['step_id']; |
| 203 |
$input = sanitize_text_field($payload['input']); |
| 204 |
|
| 205 |
$step_post = [ |
| 206 |
'ID' => $step_id, |
| 207 |
'post_title' => $input, |
| 208 |
]; |
| 209 |
|
| 210 |
wp_update_post($step_post); |
| 211 |
return [ |
| 212 |
'success' => true, |
| 213 |
'message' => "Step title updated", |
| 214 |
]; |
| 215 |
} |
| 216 |
|
| 217 |
/** |
| 218 |
* Get view |
| 219 |
*/ |
| 220 |
public function get_view() |
| 221 |
{ |
| 222 |
} |
| 223 |
} |
| 224 |
|
| 225 |
|
| 226 |
|