put['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(); } }