| 1 |
<?php |
| 2 |
defined('ABSPATH') || exit; |
| 3 |
|
| 4 |
/** |
| 5 |
* Module Name: Optin Forms |
| 6 |
* Description: Displays Optin form |
| 7 |
*/ |
| 8 |
class TB_Optin_Module extends Themify_Builder_Component_Module { |
| 9 |
|
| 10 |
public static function init():void { |
| 11 |
include_once( THEMIFY_BUILDER_INCLUDES_DIR . '/optin-services/base.php' ); |
| 12 |
add_action('wp_ajax_tb_optin_get_settings', array(__CLASS__, 'ajax_tb_optin_get_settings')); |
| 13 |
} |
| 14 |
|
| 15 |
public static function get_module_name():string { |
| 16 |
return __('Optin Form', 'themify'); |
| 17 |
} |
| 18 |
|
| 19 |
public static function get_module_icon():string { |
| 20 |
return 'email'; |
| 21 |
} |
| 22 |
|
| 23 |
public static function get_js_css():array { |
| 24 |
$_arr = array( |
| 25 |
'css' => 1 |
| 26 |
); |
| 27 |
if (!Themify_Builder_Model::is_front_builder_activate()) { |
| 28 |
$_arr['js'] = 1; |
| 29 |
} |
| 30 |
return $_arr; |
| 31 |
} |
| 32 |
|
| 33 |
|
| 34 |
/** |
| 35 |
* Handles Ajax request to get the options for providers |
| 36 |
* |
| 37 |
* @since 4.2.3 |
| 38 |
*/ |
| 39 |
public static function ajax_tb_optin_get_settings() { |
| 40 |
check_ajax_referer('tf_nonce', 'nonce'); |
| 41 |
$providers = Builder_Optin_Service::get_providers('all',true); |
| 42 |
$providers_settings = $providers_list = $providers_binding = array(); |
| 43 |
foreach ($providers as $id => $instance) { |
| 44 |
$providers_list[$id] = $instance::get_label(); |
| 45 |
|
| 46 |
$providers_settings[] = array( |
| 47 |
'type' => 'group', |
| 48 |
'options' => $instance::get_settings(), |
| 49 |
'wrap_class' => $id |
| 50 |
); |
| 51 |
|
| 52 |
$providers_binding[$id] = array( |
| 53 |
'hide' => array_values(array_diff(array_keys($providers), array($id))), |
| 54 |
'show' => $id, |
| 55 |
); |
| 56 |
} |
| 57 |
|
| 58 |
$options = array( |
| 59 |
array( |
| 60 |
'id' => 'provider', |
| 61 |
'type' => 'select', |
| 62 |
'options' => $providers_list, |
| 63 |
'binding' => $providers_binding |
| 64 |
), |
| 65 |
array( |
| 66 |
'type' => 'group', |
| 67 |
'id' => 'provider_settings', |
| 68 |
'options' => $providers_settings |
| 69 |
) |
| 70 |
); |
| 71 |
die(json_encode($options)); |
| 72 |
} |
| 73 |
|
| 74 |
|
| 75 |
/** |
| 76 |
* Render plain content for static content. |
| 77 |
* |
| 78 |
* @param array $module |
| 79 |
* @return string |
| 80 |
*/ |
| 81 |
public static function get_static_content(array $module):string { |
| 82 |
return ''; |
| 83 |
} |
| 84 |
|
| 85 |
public static function get_styling_image_fields() : array { |
| 86 |
return [ |
| 87 |
'b_i' => '' |
| 88 |
]; |
| 89 |
} |
| 90 |
|
| 91 |
public static function get_translatable_text_fields( $module ) : array { |
| 92 |
return [ 'mod_title', 'label_firstname', 'fn_placeholder', 'label_lastname', 'ln_placeholder', 'label_email', 'email_placeholder', 'label_submit' ]; |
| 93 |
} |
| 94 |
|
| 95 |
public static function get_translatable_textarea_fields( $module ) : array { |
| 96 |
return [ 'gdpr_label', 'errmsg', 'message' ]; |
| 97 |
} |
| 98 |
|
| 99 |
public static function get_translatable_link_fields( $module ) : array { |
| 100 |
return [ 'redirect_to' ]; |
| 101 |
} |
| 102 |
} |
| 103 |
|
| 104 |
TB_Optin_Module::init(); |
| 105 |
|