| 1 |
<?php |
| 2 |
|
| 3 |
defined( 'ABSPATH' ) || die(); |
| 4 |
|
| 5 |
use Sellkit_Elementor_Optin_Module as Module; |
| 6 |
use \Elementor\Repeater as Repeater; |
| 7 |
|
| 8 |
/** |
| 9 |
* Holds methods for adding Optin widget's content tab controls. |
| 10 |
*/ |
| 11 |
class Sellkit_Elementor_Optin_Tab_Content { |
| 12 |
|
| 13 |
public function __construct( $widget ) { |
| 14 |
$this->add_section_form_fields( $widget ); |
| 15 |
$this->add_section_submit_button( $widget ); |
| 16 |
$this->add_section_settings( $widget ); |
| 17 |
$this->add_section_after_submit_actions( $widget ); |
| 18 |
$this->add_section_messages( $widget ); |
| 19 |
} |
| 20 |
|
| 21 |
private function add_section_form_fields( $widget ) { |
| 22 |
$widget->start_controls_section( |
| 23 |
'section_form_fields', |
| 24 |
[ |
| 25 |
'label' => esc_html__( 'Form Fields', 'sellkit' ), |
| 26 |
] |
| 27 |
); |
| 28 |
|
| 29 |
$repeater = new Repeater(); |
| 30 |
|
| 31 |
$repeater->add_control( |
| 32 |
'type', |
| 33 |
[ |
| 34 |
'label' => esc_html__( 'Type', 'sellkit' ), |
| 35 |
'type' => 'select', |
| 36 |
'options' => Module::get_field_types(), |
| 37 |
'default' => 'text', |
| 38 |
] |
| 39 |
); |
| 40 |
|
| 41 |
foreach ( Sellkit_Elementor_Optin_Field_Base::get_fields_controls() as $key => $props ) { |
| 42 |
if ( strpos( $key, 'responsive' ) ) { |
| 43 |
$repeater->add_responsive_control( str_replace( '_responsive', '', $key ), $props ); |
| 44 |
continue; |
| 45 |
} |
| 46 |
$repeater->add_control( $key, $props ); |
| 47 |
} |
| 48 |
|
| 49 |
$widget->add_control( |
| 50 |
'fields', |
| 51 |
[ |
| 52 |
'type' => 'repeater', |
| 53 |
'fields' => $repeater->get_controls(), |
| 54 |
'default' => [ |
| 55 |
[ |
| 56 |
'label' => esc_html__( 'Name', 'sellkit' ), |
| 57 |
'type' => 'text', |
| 58 |
'placeholder' => 'Name', |
| 59 |
], |
| 60 |
[ |
| 61 |
'label' => esc_html__( 'Email', 'sellkit' ), |
| 62 |
'type' => 'email', |
| 63 |
'placeholder' => 'Email', |
| 64 |
'required' => 'true', |
| 65 |
], |
| 66 |
], |
| 67 |
'title_field' => '{{{ label }}}', |
| 68 |
] |
| 69 |
); |
| 70 |
|
| 71 |
$widget->end_controls_section(); |
| 72 |
} |
| 73 |
|
| 74 |
private function add_section_submit_button( $widget ) { |
| 75 |
$widget->start_controls_section( |
| 76 |
'section_submit_button', |
| 77 |
[ |
| 78 |
'label' => esc_html__( 'Submit Button', 'sellkit' ), |
| 79 |
] |
| 80 |
); |
| 81 |
|
| 82 |
$widget->add_control( |
| 83 |
'submit_button_text', |
| 84 |
[ |
| 85 |
'label' => esc_html__( 'Text', 'sellkit' ), |
| 86 |
'type' => 'text', |
| 87 |
'default' => esc_html__( 'Subscribe', 'sellkit' ), |
| 88 |
] |
| 89 |
); |
| 90 |
|
| 91 |
$widget->add_control( |
| 92 |
'submit_button_subtext', |
| 93 |
[ |
| 94 |
'label' => esc_html__( 'Sub Text', 'sellkit' ), |
| 95 |
'type' => 'text', |
| 96 |
] |
| 97 |
); |
| 98 |
|
| 99 |
$widget->add_control( |
| 100 |
'submit_button_icon', |
| 101 |
[ |
| 102 |
'label' => esc_html__( 'Icon', 'sellkit' ), |
| 103 |
'type' => 'icons', |
| 104 |
'skin' => 'inline', |
| 105 |
'label_block' => false, |
| 106 |
] |
| 107 |
); |
| 108 |
|
| 109 |
$widget->add_responsive_control( |
| 110 |
'submit_button_width', |
| 111 |
[ |
| 112 |
'label' => esc_html__( 'Column Width', 'sellkit' ), |
| 113 |
'type' => 'select', |
| 114 |
'default' => '100', |
| 115 |
'options' => [ |
| 116 |
'100' => '100%', |
| 117 |
'80' => '80%', |
| 118 |
'75' => '75%', |
| 119 |
'66' => '66%', |
| 120 |
'60' => '60%', |
| 121 |
'50' => '50%', |
| 122 |
'40' => '40%', |
| 123 |
'33' => '33%', |
| 124 |
'25' => '25%', |
| 125 |
'20' => '20%', |
| 126 |
], |
| 127 |
] |
| 128 |
); |
| 129 |
|
| 130 |
$widget->end_controls_section(); |
| 131 |
} |
| 132 |
|
| 133 |
private function add_section_settings( $widget ) { |
| 134 |
$widget->start_controls_section( |
| 135 |
'section_settings', |
| 136 |
[ |
| 137 |
'label' => esc_html__( 'Settings', 'sellkit' ), |
| 138 |
] |
| 139 |
); |
| 140 |
|
| 141 |
$widget->add_control( |
| 142 |
'label', |
| 143 |
[ |
| 144 |
'label' => esc_html__( 'Label', 'sellkit' ), |
| 145 |
'type' => 'switcher', |
| 146 |
'label_on' => esc_html__( 'Show', 'sellkit' ), |
| 147 |
'label_off' => esc_html__( 'Hide', 'sellkit' ), |
| 148 |
'default' => 'yes', |
| 149 |
] |
| 150 |
); |
| 151 |
|
| 152 |
$widget->add_control( |
| 153 |
'required_mark', |
| 154 |
[ |
| 155 |
'label' => esc_html__( 'Required Mark', 'sellkit' ), |
| 156 |
'type' => 'switcher', |
| 157 |
'label_on' => esc_html__( 'Show', 'sellkit' ), |
| 158 |
'label_off' => esc_html__( 'Hide', 'sellkit' ), |
| 159 |
'return_value' => 'show', |
| 160 |
'prefix_class' => 'label-required-mark-', |
| 161 |
] |
| 162 |
); |
| 163 |
|
| 164 |
$widget->add_control( |
| 165 |
'crm_actions', |
| 166 |
[ |
| 167 |
'label' => esc_html__( 'CRM Integrations', 'sellkit' ), |
| 168 |
'type' => 'select2', |
| 169 |
'multiple' => true, |
| 170 |
'options' => Module::get_action_types(), |
| 171 |
'label_block' => true, |
| 172 |
'render_type' => 'ui', |
| 173 |
] |
| 174 |
); |
| 175 |
|
| 176 |
$widget->end_controls_section(); |
| 177 |
} |
| 178 |
|
| 179 |
private function add_section_after_submit_actions( $widget ) { |
| 180 |
$widget->start_controls_section( |
| 181 |
'section_after_submit_actions', |
| 182 |
[ |
| 183 |
'label' => esc_html__( 'After Submit Actions', 'sellkit' ), |
| 184 |
] |
| 185 |
); |
| 186 |
|
| 187 |
$widget->add_control( |
| 188 |
'download_source', |
| 189 |
[ |
| 190 |
'label' => esc_html__( 'Download a File', 'sellkit' ), |
| 191 |
'type' => 'select', |
| 192 |
'default' => '', |
| 193 |
'options' => [ |
| 194 |
'' => esc_html__( 'None', 'sellkit' ), |
| 195 |
'file' => esc_html__( 'File', 'sellkit' ), |
| 196 |
'url' => esc_html__( 'URL', 'sellkit' ), |
| 197 |
], |
| 198 |
] |
| 199 |
); |
| 200 |
|
| 201 |
$widget->add_control( |
| 202 |
'download_url', |
| 203 |
[ |
| 204 |
'label' => esc_html__( 'Download URL', 'sellkit' ), |
| 205 |
'type' => 'url', |
| 206 |
'placeholder' => esc_html__( 'https: //your-link.com', 'sellkit' ), |
| 207 |
'options' => false, |
| 208 |
'default' => [ 'url' => '' ], |
| 209 |
'condition' => [ 'download_source' => 'url' ], |
| 210 |
] |
| 211 |
); |
| 212 |
|
| 213 |
$widget->add_control( |
| 214 |
'download_file', |
| 215 |
[ |
| 216 |
'label' => esc_html__( 'File', 'sellkit' ), |
| 217 |
'type' => 'sellkit_file_uploader', |
| 218 |
'condition' => [ 'download_source' => 'file' ], |
| 219 |
] |
| 220 |
); |
| 221 |
|
| 222 |
$widget->add_control( |
| 223 |
'redirect_to', |
| 224 |
[ |
| 225 |
'label' => esc_html__( 'Redirect to', 'sellkit' ), |
| 226 |
'type' => 'select', |
| 227 |
'default' => 'funnel', |
| 228 |
'options' => [ |
| 229 |
'funnel' => esc_html__( 'Next Funnel Step', 'sellkit' ), |
| 230 |
'custom' => esc_html__( 'Custom URL', 'sellkit' ), |
| 231 |
], |
| 232 |
] |
| 233 |
); |
| 234 |
|
| 235 |
$widget->add_control( |
| 236 |
'redirect_url', |
| 237 |
[ |
| 238 |
'label' => esc_html__( 'Redirect URL', 'sellkit' ), |
| 239 |
'type' => 'url', |
| 240 |
'placeholder' => esc_html__( 'https: //your-link.com', 'sellkit' ), |
| 241 |
'options' => false, |
| 242 |
'default' => [ 'url' => '' ], |
| 243 |
'condition' => [ |
| 244 |
'redirect_to' => 'custom', |
| 245 |
] |
| 246 |
] |
| 247 |
); |
| 248 |
|
| 249 |
$widget->end_controls_section(); |
| 250 |
} |
| 251 |
|
| 252 |
private function add_section_messages( $widget ) { |
| 253 |
$widget->start_controls_section( |
| 254 |
'section_messages', |
| 255 |
[ |
| 256 |
'label' => esc_html__( 'Feedback Messages', 'sellkit' ), |
| 257 |
] |
| 258 |
); |
| 259 |
|
| 260 |
$widget->add_control( |
| 261 |
'messages_custom', |
| 262 |
[ |
| 263 |
'label' => esc_html__( 'Custom Messages', 'sellkit' ), |
| 264 |
'type' => 'switcher', |
| 265 |
'render_type' => 'template', |
| 266 |
] |
| 267 |
); |
| 268 |
|
| 269 |
$widget->add_control( |
| 270 |
'messages_success', |
| 271 |
[ |
| 272 |
'label' => esc_html__( 'Success Message', 'sellkit' ), |
| 273 |
'type' => 'text', |
| 274 |
'default' => Module::$messages['success'], |
| 275 |
'label_block' => true, |
| 276 |
'render_type' => 'ui', |
| 277 |
'condition' => [ |
| 278 |
'messages_custom' => 'yes', |
| 279 |
], |
| 280 |
] |
| 281 |
); |
| 282 |
|
| 283 |
$widget->add_control( |
| 284 |
'messages_error', |
| 285 |
[ |
| 286 |
'label' => esc_html__( 'Error Message', 'sellkit' ), |
| 287 |
'type' => 'text', |
| 288 |
'default' => Module::$messages['error'], |
| 289 |
'label_block' => true, |
| 290 |
'render_type' => 'template', |
| 291 |
'condition' => [ |
| 292 |
'messages_custom' => 'yes', |
| 293 |
], |
| 294 |
] |
| 295 |
); |
| 296 |
|
| 297 |
$widget->add_control( |
| 298 |
'messages_required', |
| 299 |
[ |
| 300 |
'label' => esc_html__( 'Required Message', 'sellkit' ), |
| 301 |
'type' => 'text', |
| 302 |
'default' => Module::$messages['required'], |
| 303 |
'label_block' => true, |
| 304 |
'render_type' => 'template', |
| 305 |
'condition' => [ |
| 306 |
'messages_custom' => 'yes', |
| 307 |
], |
| 308 |
] |
| 309 |
); |
| 310 |
|
| 311 |
$widget->end_controls_section(); |
| 312 |
} |
| 313 |
} |
| 314 |
|