iews/settings.php'; } public function floating_widget_view() { require NTA_WHATSAPP_PLUGIN_DIR . 'views/floating-widget-settings.php'; } public function register_setting() { register_setting($this->option_group, 'nta_whatsapp_setting'); register_setting($this->option_design, 'nta_whatsapp_setting'); register_setting($this->option_woo_button_group, 'nta_wa_woobutton_setting', [$this, 'save_woobutton_setting']); register_setting($this->option_ga_group, 'nta_wa_ga_setting', [$this, 'save_ga_setting']); add_settings_section('page_selected_accounts_section', '', [$this, 'page_selected_accounts_section_callback'], 'floating-widget-whatsapp-1'); add_settings_section('page_design_settings_section', '', [$this, 'page_design_settings_section_callback'], 'floating-widget-whatsapp-2'); add_settings_section('page_display_settings_section', '', [$this, 'page_display_settings_section_callback'], 'floating-widget-whatsapp-3'); add_settings_section('nta_woocommerce_button', '', [$this, 'woocommerce_button_callback'], 'settings-whatsapp-1'); add_settings_section('nta_analytics', '', [$this, 'analytics_callback'], 'settings-whatsapp-2'); add_settings_section('nta_url', '', [$this, 'url_callback'], 'settings-whatsapp-3'); } public function save_woobutton_setting() { $new_input = []; $new_input['nta_woo_button_position'] = sanitize_text_field($_POST['nta_woo_button_position']); $new_input['nta_woo_button_status'] = isset($_POST['nta_woo_button_status']) ? 'ON' : 'OFF'; return $new_input; } public function save_ga_setting() { if (isset($_POST['nta_wa_ga_status'])) { return '1'; } return '0'; } public function save_display_setting() { check_ajax_referer('njt-wa-nonce', 'nonce', true); $new_input = []; $excludePages = Helper::sanitize_array($_POST['excludePages']); $includePages = Helper::sanitize_array($_POST['includePages']); $new_input = Fields::getWidgetDisplay(); $new_input['displayCondition'] = sanitize_text_field($_POST['displayCondition']); $new_input['excludePages'] = empty($excludePages) ? array() : $excludePages; $new_input['includePages'] = empty($includePages) ? array() : $includePages; $new_input['showOnDesktop'] = isset($_POST['showOnDesktop']) ? 'ON' : 'OFF'; $new_input['showOnMobile'] = isset($_POST['showOnMobile']) ? 'ON' : 'OFF'; $time_symbols = Helper::sanitize_array($_POST['time_symbols']); $new_input['time_symbols'] = wp_unslash($time_symbols['hourSymbol']) . ':' . wp_unslash($time_symbols['minSymbol']); update_option('nta_wa_widget_display', $new_input); wp_send_json_success(); } public function save_design_setting() { check_ajax_referer('njt-wa-nonce', 'nonce', true); $new_input = []; $new_input = Fields::getWidgetStyles(); $new_input['title'] = sanitize_text_field(wp_unslash($_POST['title'])); $new_input['textColor'] = sanitize_hex_color($_POST['textColor']); $new_input['backgroundColor'] = sanitize_hex_color($_POST['backgroundColor']); $new_input['description'] = wp_kses_post(wp_unslash($_POST['description'])); $new_input['responseText'] = sanitize_text_field(wp_unslash($_POST['responseText'])); $new_input['scrollHeight'] = sanitize_text_field($_POST['scrollHeight']); $new_input['isShowScroll'] = isset($_POST['isShowScroll']) ? 'ON' : 'OFF'; $new_input['isShowResponseText'] = isset($_POST['isShowResponseText']) ? 'ON' : 'OFF'; $new_input['btnLabel'] = wp_kses_post(wp_unslash($_POST['btnLabel'])); // It can be an html tag $new_input['btnPosition'] = sanitize_text_field($_POST['btnPosition']); $new_input['btnLabelWidth'] = sanitize_text_field($_POST['btnLabelWidth']); $new_input['btnLeftDistance'] = sanitize_text_field($_POST['btnLeftDistance']); $new_input['btnRightDistance'] = sanitize_text_field($_POST['btnRightDistance']); $new_input['btnBottomDistance'] = sanitize_text_field($_POST['btnBottomDistance']); $new_input['isShowBtnLabel'] = isset($_POST['isShowBtnLabel']) ? 'ON' : 'OFF'; $new_input['isShowGDPR'] = isset($_POST['isShowGDPR']) ? 'ON' : 'OFF'; $new_input['gdprContent'] = wp_kses_post(wp_unslash($_POST['gdprContent'])); update_option('nta_wa_widget_styles', $new_input); wp_send_json_success(); } public function save_woocommerce_setting(){ check_ajax_referer('njt-wa-nonce', 'nonce', true); $new_input = []; $new_input = Fields::getWoocommerceSetting(); $new_input['position'] = sanitize_text_field($_POST['position']); $new_input['isShow'] = isset($_POST['isShow']) ? 'ON' : 'OFF'; update_option('nta_wa_woocommerce', $new_input); wp_send_json_success(); } public function save_analytics_setting(){ check_ajax_referer('njt-wa-nonce', 'nonce', true); $new_input = []; $new_input = Fields::getAnalyticsSetting(); $new_input['enabledGoogle'] = isset($_POST['enabledGoogle']) ? 'ON' : 'OFF'; $new_input['enabledFacebook'] = isset($_POST['enabledFacebook']) ? 'ON' : 'OFF'; update_option('nta_wa_analytics', $new_input); wp_send_json_success(); } public function save_url_setting(){ check_ajax_referer('njt-wa-nonce', 'nonce', true); $new_input = []; $new_input = Fields::getURLSettings(); $new_input['openInNewTab'] = isset($_POST['openInNewTab']) ? 'ON' : 'OFF'; $new_input['onDesktop'] = sanitize_text_field($_POST['onDesktop']); $new_input['onMobile'] = sanitize_text_field($_POST['onMobile']); update_option('nta_wa_url', $new_input); wp_send_json_success(); } public function set_account_position() { check_ajax_referer('njt-wa-nonce', 'nonce', true); $positions = Helper::sanitize_array($_POST['positions']); $type = sanitize_text_field($_POST['type']); foreach ($positions as $index => $id) { update_post_meta($id, "nta_wa_{$type}", $index); } wp_send_json_success(); } public function load_accounts_ajax() { check_ajax_referer('njt-wa-nonce', 'nonce', true); $postType = PostType::getInstance(); $accountsList = $postType->get_posts(); $results = array_map(function ($account) { $meta = get_post_meta($account->ID, 'nta_wa_account_info', true); $avatar = get_the_post_thumbnail_url($account->ID); $wg_show = get_post_meta($account->ID, 'nta_wa_widget_show', true); $wg_position = get_post_meta($account->ID, 'nta_wa_widget_position', true); $wc_show = get_post_meta($account->ID, 'nta_wa_wc_show', true); $wc_position = get_post_meta($account->ID, 'nta_wa_wc_position', true); return array_merge(array( 'accountId' => $account->ID, 'accountName' => $account->post_title, 'edit_link' => get_edit_post_link($account->ID), 'avatar' => $avatar !== false ? $avatar : '', 'widget_show' => $wg_show, 'widget_position' => $wg_position, 'wc_show' => $wc_show, 'wc_position' => $wc_position, ),$meta); }, $accountsList); wp_send_json_success($results); } public function set_account_status() { check_ajax_referer('njt-wa-nonce', 'nonce', true); $id = sanitize_text_field($_POST['accountId']); $type = sanitize_text_field($_POST['type']); $status = sanitize_text_field($_POST['status']); update_post_meta($id, "nta_wa_{$type}", $status); wp_send_json_success(); } }