Recommended
2 years ago
Support
2 years ago
Cross.php
2 years ago
Fallback.php
2 years ago
Fields.php
2 years ago
Helper.php
2 years ago
I18n.php
2 years ago
Plugin.php
2 years ago
Popup.php
2 years ago
PostType.php
2 years ago
Review.php
2 years ago
Settings.php
2 years ago
Shortcode.php
2 years ago
Upgrade.php
2 years ago
Settings.php
458 lines
| 1 | <?php |
| 2 | namespace NTA_WhatsApp; |
| 3 | use NTA_WhatsApp\Helper; |
| 4 | use NTA_WhatsApp\Fields; |
| 5 | use NTA_WhatsApp\PostType; |
| 6 | |
| 7 | defined('ABSPATH') || exit; |
| 8 | /** |
| 9 | * Settings Page |
| 10 | */ |
| 11 | class Settings |
| 12 | { |
| 13 | protected $option; |
| 14 | protected $option_group = 'nta_whatsapp_group'; |
| 15 | protected $option_design = 'nta_whatsapp_design'; |
| 16 | protected $option_button_group = 'nta_whatsapp_button_group'; |
| 17 | protected $option_woo_button_group = 'nta_wa_woo_button_group'; |
| 18 | protected $option_ga_group = 'nta_wa_ga_group'; |
| 19 | |
| 20 | protected $settings; |
| 21 | |
| 22 | private $floatingWidgetSlug = ''; |
| 23 | private $settingSlug = ''; |
| 24 | |
| 25 | protected static $instance = null; |
| 26 | |
| 27 | public static function getInstance() |
| 28 | { |
| 29 | if (null == self::$instance) { |
| 30 | self::$instance = new self; |
| 31 | self::$instance->doHooks(); |
| 32 | } |
| 33 | return self::$instance; |
| 34 | } |
| 35 | |
| 36 | private function doHooks(){ |
| 37 | add_action('admin_init', [$this, 'register_setting']); |
| 38 | add_action('admin_menu', [$this, 'admin_menu']); |
| 39 | add_action('admin_enqueue_scripts', [$this, 'admin_enqueue_scripts']); |
| 40 | add_action("admin_footer", [$this, 'admin_footer']); |
| 41 | |
| 42 | add_action('wp_ajax_njt_wa_set_account_position', [$this, 'set_account_position']); |
| 43 | add_action('wp_ajax_njt_wa_load_accounts_ajax', [$this, 'load_accounts_ajax']); |
| 44 | add_action('wp_ajax_njt_wa_set_account_status', [$this, 'set_account_status']); |
| 45 | |
| 46 | add_action('wp_ajax_njt_wa_save_display_setting', [$this, 'save_display_setting']); |
| 47 | add_action('wp_ajax_njt_wa_save_design_setting', [$this, 'save_design_setting']); |
| 48 | add_action('wp_ajax_njt_wa_save_woocommerce_setting', [$this, 'save_woocommerce_setting']); |
| 49 | add_action('wp_ajax_njt_wa_save_analytics_setting', [$this, 'save_analytics_setting']); |
| 50 | add_action('wp_ajax_njt_wa_save_url_setting', [$this, 'save_url_setting']); |
| 51 | |
| 52 | add_filter('plugin_action_links_' . NTA_WHATSAPP_BASE_NAME, [$this, 'addActionLinks']); |
| 53 | add_filter('plugin_row_meta', [$this, 'pluginRowMeta'], 10, 2); |
| 54 | } |
| 55 | |
| 56 | public function __construct() |
| 57 | { |
| 58 | } |
| 59 | |
| 60 | public function addActionLinks($links) |
| 61 | { |
| 62 | $links = array_merge(array( |
| 63 | '<a href="' . esc_url(admin_url('/admin.php?page=nta_whatsapp_floating_widget')) . '">' . __('Settings', 'ninjateam-whatsapp') . '</a>', |
| 64 | ), $links); |
| 65 | |
| 66 | $links[] = '<a target="_blank" href="https://1.envato.market/WhatsApp-Plugin" style="color: #43B854; font-weight: bold">' . __('Go Pro', 'ninjateam-whatsapp') . '</a>'; |
| 67 | |
| 68 | return $links; |
| 69 | } |
| 70 | |
| 71 | public function pluginRowMeta($links, $file){ |
| 72 | if ( strpos( $file, 'whatsapp.php' ) !== false ) { |
| 73 | $new_links = array( |
| 74 | 'doc' => '<a href="https://ninjateam.org/wordpress-whatsapp-chat-tutorial/" target="_blank">'. __("Documentation", "filebird") .'</a>' |
| 75 | ); |
| 76 | |
| 77 | $links = array_merge( $links, $new_links ); |
| 78 | } |
| 79 | |
| 80 | return $links; |
| 81 | } |
| 82 | |
| 83 | public function admin_menu() |
| 84 | { |
| 85 | $edit_account_link = 'post-new.php?post_type=whatsapp-accounts'; |
| 86 | |
| 87 | add_menu_page('NTA Whatsapp', 'WhatsApp', 'manage_options', 'nta_whatsapp', [$this, 'create_page_setting_widget'], NTA_WHATSAPP_PLUGIN_URL . 'assets/img/whatsapp-menu.svg', 60); |
| 88 | add_submenu_page('nta_whatsapp', __('Add New account', 'ninjateam-whatsapp'), __('Add New account', 'ninjateam-whatsapp'), 'manage_options', $edit_account_link); |
| 89 | $this->floatingWidgetSlug = add_submenu_page('nta_whatsapp', __('Floating Widget', 'ninjateam-whatsapp'), __('Floating Widget', 'ninjateam-whatsapp'), 'manage_options', 'nta_whatsapp_floating_widget', [$this, 'floating_widget_view']); |
| 90 | $this->settingSlug = add_submenu_page('nta_whatsapp', __('Settings', 'ninjateam-whatsapp'), __('Settings', 'ninjateam-whatsapp'), 'manage_options', 'nta_whatsapp_setting', [$this, 'create_page_setting_widget']); |
| 91 | add_submenu_page( |
| 92 | 'nta_whatsapp', |
| 93 | '', |
| 94 | '<span>' . __('Go Pro', 'ninjateam-whatsapp') . '</span>', |
| 95 | 'manage_options', |
| 96 | 'go_whatsapp_pro', |
| 97 | [ $this, 'go_pro_redirects' ] |
| 98 | ); |
| 99 | } |
| 100 | |
| 101 | public function go_pro_redirects() { |
| 102 | if ( empty( $_GET['page'] ) ) { |
| 103 | return; |
| 104 | } |
| 105 | |
| 106 | if ( 'go_whatsapp_pro' === $_GET['page'] ) { |
| 107 | ?> |
| 108 | <script>window.location.href = 'https://1.envato.market/whatsapp-pro'</script> |
| 109 | <?php |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | function admin_footer() |
| 114 | { |
| 115 | ?> |
| 116 | <style> |
| 117 | body.admin-color-fresh #adminmenu #toplevel_page_nta_whatsapp a[href="admin.php?page=go_whatsapp_pro"] { |
| 118 | color: #00BC28; |
| 119 | font-weight: bold; |
| 120 | position: relative; |
| 121 | } |
| 122 | |
| 123 | body.admin-color-fresh #adminmenu #toplevel_page_nta_whatsapp a[href="admin.php?page=go_whatsapp_pro"]::after { |
| 124 | content: ''; |
| 125 | position: absolute; |
| 126 | width: 4px; |
| 127 | top: 0; |
| 128 | bottom: 0; |
| 129 | left: 0; |
| 130 | background: green; |
| 131 | } |
| 132 | </style> |
| 133 | <script> |
| 134 | jQuery(document).ready(function() { |
| 135 | jQuery('#toplevel_page_nta_whatsapp a[href="admin.php?page=go_whatsapp_pro"]').click(function(event) { |
| 136 | event.preventDefault() |
| 137 | window.open('https://1.envato.market/whatsapp-pro', '_blank') |
| 138 | }) |
| 139 | }) |
| 140 | </script> |
| 141 | <?php |
| 142 | $screen = get_current_screen(); |
| 143 | if ($screen->base !== $this->floatingWidgetSlug) return; |
| 144 | require NTA_WHATSAPP_PLUGIN_DIR . 'views/design-preview.php'; |
| 145 | } |
| 146 | |
| 147 | public function admin_enqueue_scripts($hook_suffix) |
| 148 | { |
| 149 | if ($hook_suffix === 'edit.php' || $hook_suffix === 'post-new.php' || $hook_suffix === 'post.php') { |
| 150 | if (get_post_type() !== 'whatsapp-accounts') return; |
| 151 | } else { |
| 152 | if (!in_array($hook_suffix, [$this->settingSlug, $this->floatingWidgetSlug])) { |
| 153 | return; |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | wp_register_style('nta-css', NTA_WHATSAPP_PLUGIN_URL . 'assets/css/admin.css', ['wp-color-picker']); |
| 158 | wp_enqueue_style('nta-css'); |
| 159 | |
| 160 | wp_register_style('nta-tippy-css', NTA_WHATSAPP_PLUGIN_URL . 'assets/css/tooltip.css'); |
| 161 | wp_enqueue_style('nta-tippy-css'); |
| 162 | |
| 163 | wp_dequeue_style('woosea_jquery_ui-css'); |
| 164 | |
| 165 | wp_register_style('nta-wa-widget', NTA_WHATSAPP_PLUGIN_URL . 'assets/dist/css/style.css'); |
| 166 | wp_enqueue_style('nta-wa-widget'); |
| 167 | wp_enqueue_style('ui-range', NTA_WHATSAPP_PLUGIN_URL . 'assets/libs/ui-range.css'); |
| 168 | |
| 169 | if ( function_exists('wp_timezone_string') ) { |
| 170 | $timezone = wp_timezone_string(); |
| 171 | } else { |
| 172 | $timezone = Helper::wp_timezone_string(); |
| 173 | } |
| 174 | |
| 175 | wp_register_script( |
| 176 | 'nta-wa-js', |
| 177 | NTA_WHATSAPP_PLUGIN_URL . 'assets/dist/js/app.js', |
| 178 | [ |
| 179 | 'jquery', |
| 180 | 'wp-color-picker', |
| 181 | 'backbone', |
| 182 | 'underscore', |
| 183 | 'jquery-ui-tabs', |
| 184 | 'jquery-ui-sortable', |
| 185 | 'jquery-ui-autocomplete', |
| 186 | ], |
| 187 | NTA_WHATSAPP_VERSION, |
| 188 | true |
| 189 | ); |
| 190 | wp_localize_script('nta-wa-js', 'njt_wa', [ |
| 191 | 'url' => admin_url('admin-ajax.php'), |
| 192 | 'nonce' => wp_create_nonce('njt-wa-nonce'), |
| 193 | 'settings' => [ |
| 194 | 'widget' => [ |
| 195 | 'styles' => Fields::getWidgetStyles() |
| 196 | ] |
| 197 | ], |
| 198 | 'timezone' => $timezone, |
| 199 | 'i18n' => array( |
| 200 | 'select_post' => __('Select posts to display the widget', 'ninjateam-whatsapp') |
| 201 | ) |
| 202 | ]); |
| 203 | wp_enqueue_script('nta-wa-js'); |
| 204 | wp_enqueue_script('jquery-validate', NTA_WHATSAPP_PLUGIN_URL . 'assets/libs/jquery.validate.min.js'); |
| 205 | } |
| 206 | |
| 207 | public function page_display_settings_section_callback() |
| 208 | { |
| 209 | global $wpdb; |
| 210 | $option = Fields::getWidgetDisplay(); |
| 211 | $option['time_symbols'] = explode(":", $option['time_symbols']); |
| 212 | $pages = $wpdb->get_results("Select ID, post_title from {$wpdb->posts} where post_type = 'page' and post_status = 'publish'"); |
| 213 | require NTA_WHATSAPP_PLUGIN_DIR . 'views/display-settings.php'; |
| 214 | } |
| 215 | |
| 216 | public function page_design_settings_section_callback() |
| 217 | { |
| 218 | $option = Fields::getWidgetStyles(); |
| 219 | $editor_settings = [ |
| 220 | 'media_buttons' => false, |
| 221 | 'textarea_rows' => get_option('default_post_edit_rows', 5), |
| 222 | 'quicktags' => false, |
| 223 | 'teeny' => true, |
| 224 | ]; |
| 225 | $editor_settings_quicktags = [ |
| 226 | 'media_buttons' => false, |
| 227 | 'textarea_rows' => get_option('default_post_edit_rows', 5), |
| 228 | 'quicktags' => true, |
| 229 | 'teeny' => true, |
| 230 | ]; |
| 231 | require NTA_WHATSAPP_PLUGIN_DIR . 'views/design-settings.php'; |
| 232 | } |
| 233 | |
| 234 | public function page_selected_accounts_section_callback() |
| 235 | { |
| 236 | require NTA_WHATSAPP_PLUGIN_DIR . 'views/selected-accounts.php'; |
| 237 | } |
| 238 | |
| 239 | public function woocommerce_button_callback() |
| 240 | { |
| 241 | $option = Fields::getWoocommerceSetting(); |
| 242 | require NTA_WHATSAPP_PLUGIN_DIR . 'views/woocommerce-button.php'; |
| 243 | } |
| 244 | |
| 245 | public function analytics_callback() |
| 246 | { |
| 247 | $option = Fields::getAnalyticsSetting(); |
| 248 | require NTA_WHATSAPP_PLUGIN_DIR . 'views/analytics.php'; |
| 249 | } |
| 250 | |
| 251 | public function url_callback() |
| 252 | { |
| 253 | $option = Fields::getURLSettings(); |
| 254 | require NTA_WHATSAPP_PLUGIN_DIR . 'views/url-settings.php'; |
| 255 | } |
| 256 | |
| 257 | public function create_page_setting_widget() |
| 258 | { |
| 259 | require NTA_WHATSAPP_PLUGIN_DIR . 'views/settings.php'; |
| 260 | } |
| 261 | |
| 262 | public function floating_widget_view() |
| 263 | { |
| 264 | require NTA_WHATSAPP_PLUGIN_DIR . 'views/floating-widget-settings.php'; |
| 265 | } |
| 266 | |
| 267 | public function register_setting() |
| 268 | { |
| 269 | register_setting($this->option_group, 'nta_whatsapp_setting'); |
| 270 | register_setting($this->option_design, 'nta_whatsapp_setting'); |
| 271 | register_setting($this->option_woo_button_group, 'nta_wa_woobutton_setting', [$this, 'save_woobutton_setting']); |
| 272 | register_setting($this->option_ga_group, 'nta_wa_ga_setting', [$this, 'save_ga_setting']); |
| 273 | |
| 274 | add_settings_section('page_selected_accounts_section', '', [$this, 'page_selected_accounts_section_callback'], 'floating-widget-whatsapp-1'); |
| 275 | add_settings_section('page_design_settings_section', '', [$this, 'page_design_settings_section_callback'], 'floating-widget-whatsapp-2'); |
| 276 | add_settings_section('page_display_settings_section', '', [$this, 'page_display_settings_section_callback'], 'floating-widget-whatsapp-3'); |
| 277 | add_settings_section('nta_woocommerce_button', '', [$this, 'woocommerce_button_callback'], 'settings-whatsapp-1'); |
| 278 | add_settings_section('nta_analytics', '', [$this, 'analytics_callback'], 'settings-whatsapp-2'); |
| 279 | add_settings_section('nta_url', '', [$this, 'url_callback'], 'settings-whatsapp-3'); |
| 280 | } |
| 281 | |
| 282 | public function save_woobutton_setting() |
| 283 | { |
| 284 | $new_input = []; |
| 285 | |
| 286 | $new_input['nta_woo_button_position'] = sanitize_text_field($_POST['nta_woo_button_position']); |
| 287 | $new_input['nta_woo_button_status'] = isset($_POST['nta_woo_button_status']) ? 'ON' : 'OFF'; |
| 288 | return $new_input; |
| 289 | } |
| 290 | |
| 291 | public function save_ga_setting() |
| 292 | { |
| 293 | if (isset($_POST['nta_wa_ga_status'])) { |
| 294 | return '1'; |
| 295 | } |
| 296 | return '0'; |
| 297 | } |
| 298 | |
| 299 | public function save_display_setting() |
| 300 | { |
| 301 | check_ajax_referer('njt-wa-nonce', 'nonce', true); |
| 302 | $new_input = []; |
| 303 | |
| 304 | $excludePages = Helper::sanitize_array($_POST['excludePages']); |
| 305 | $includePages = Helper::sanitize_array($_POST['includePages']); |
| 306 | $includePosts = Helper::sanitize_array($_POST['includePosts']); |
| 307 | |
| 308 | $new_input = Fields::getWidgetDisplay(); |
| 309 | $new_input['displayCondition'] = sanitize_text_field($_POST['displayCondition']); |
| 310 | $new_input['excludePages'] = empty($excludePages) ? array() : $excludePages; |
| 311 | $new_input['includePages'] = empty($includePages) ? array() : $includePages; |
| 312 | $new_input['includePosts'] = empty($includePosts) ? array() : $includePosts; |
| 313 | $new_input['showOnDesktop'] = isset($_POST['showOnDesktop']) ? 'ON' : 'OFF'; |
| 314 | $new_input['showOnMobile'] = isset($_POST['showOnMobile']) ? 'ON' : 'OFF'; |
| 315 | |
| 316 | $time_symbols = Helper::sanitize_array($_POST['time_symbols']); |
| 317 | $new_input['time_symbols'] = wp_unslash($time_symbols['hourSymbol']) . ':' . wp_unslash($time_symbols['minSymbol']); |
| 318 | |
| 319 | update_option('nta_wa_widget_display', $new_input); |
| 320 | wp_send_json_success(); |
| 321 | } |
| 322 | |
| 323 | public function save_design_setting() |
| 324 | { |
| 325 | check_ajax_referer('njt-wa-nonce', 'nonce', true); |
| 326 | |
| 327 | $new_input = []; |
| 328 | |
| 329 | $new_input = Fields::getWidgetStyles(); |
| 330 | $new_input['title'] = sanitize_text_field(wp_unslash($_POST['title'])); |
| 331 | $new_input['textColor'] = sanitize_hex_color($_POST['textColor']); |
| 332 | $new_input['backgroundColor'] = sanitize_hex_color($_POST['backgroundColor']); |
| 333 | $new_input['description'] = wp_kses_post(wp_unslash($_POST['description'])); |
| 334 | $new_input['responseText'] = wp_kses_post(wp_unslash($_POST['responseText'])); |
| 335 | $new_input['scrollHeight'] = sanitize_text_field($_POST['scrollHeight']); |
| 336 | $new_input['isShowScroll'] = isset($_POST['isShowScroll']) ? 'ON' : 'OFF'; |
| 337 | $new_input['isShowResponseText'] = isset($_POST['isShowResponseText']) ? 'ON' : 'OFF'; |
| 338 | $new_input['isShowPoweredBy'] = isset($_POST['isShowPoweredBy']) ? 'ON' : 'OFF'; |
| 339 | |
| 340 | $new_input['btnLabel'] = wp_kses_post(wp_unslash($_POST['btnLabel'])); // It can be an html tag |
| 341 | $new_input['btnPosition'] = sanitize_text_field($_POST['btnPosition']); |
| 342 | $new_input['btnLabelWidth'] = sanitize_text_field($_POST['btnLabelWidth']); |
| 343 | $new_input['btnLeftDistance'] = sanitize_text_field($_POST['btnLeftDistance']); |
| 344 | $new_input['btnRightDistance'] = sanitize_text_field($_POST['btnRightDistance']); |
| 345 | $new_input['btnBottomDistance'] = sanitize_text_field($_POST['btnBottomDistance']); |
| 346 | $new_input['isShowBtnLabel'] = isset($_POST['isShowBtnLabel']) ? 'ON' : 'OFF'; |
| 347 | |
| 348 | $new_input['isShowGDPR'] = isset($_POST['isShowGDPR']) ? 'ON' : 'OFF'; |
| 349 | $new_input['gdprContent'] = wp_kses_post(wp_unslash($_POST['gdprContent'])); |
| 350 | |
| 351 | update_option('nta_wa_widget_styles', $new_input); |
| 352 | wp_send_json_success(); |
| 353 | } |
| 354 | |
| 355 | public function save_woocommerce_setting(){ |
| 356 | check_ajax_referer('njt-wa-nonce', 'nonce', true); |
| 357 | |
| 358 | $new_input = []; |
| 359 | |
| 360 | $new_input = Fields::getWoocommerceSetting(); |
| 361 | $new_input['position'] = sanitize_text_field($_POST['position']); |
| 362 | $new_input['isShow'] = isset($_POST['isShow']) ? 'ON' : 'OFF'; |
| 363 | |
| 364 | update_option('nta_wa_woocommerce', $new_input); |
| 365 | wp_send_json_success(); |
| 366 | } |
| 367 | |
| 368 | public function save_analytics_setting(){ |
| 369 | check_ajax_referer('njt-wa-nonce', 'nonce', true); |
| 370 | |
| 371 | $new_input = []; |
| 372 | |
| 373 | $new_input = Fields::getAnalyticsSetting(); |
| 374 | $new_input['enabledGoogle'] = isset($_POST['enabledGoogle']) ? 'ON' : 'OFF'; |
| 375 | $new_input['enabledFacebook'] = isset($_POST['enabledFacebook']) ? 'ON' : 'OFF'; |
| 376 | $new_input['enabledGoogleGA4'] = isset($_POST['enabledGoogleGA4']) ? 'ON' : 'OFF'; |
| 377 | |
| 378 | update_option('nta_wa_analytics', $new_input); |
| 379 | wp_send_json_success(); |
| 380 | } |
| 381 | |
| 382 | public function save_url_setting(){ |
| 383 | check_ajax_referer('njt-wa-nonce', 'nonce', true); |
| 384 | |
| 385 | $new_input = []; |
| 386 | |
| 387 | $new_input = Fields::getURLSettings(); |
| 388 | $new_input['openInNewTab'] = isset($_POST['openInNewTab']) ? 'ON' : 'OFF'; |
| 389 | $new_input['onDesktop'] = sanitize_text_field($_POST['onDesktop']); |
| 390 | $new_input['onMobile'] = sanitize_text_field($_POST['onMobile']); |
| 391 | |
| 392 | update_option('nta_wa_url', $new_input); |
| 393 | wp_send_json_success(); |
| 394 | } |
| 395 | |
| 396 | public function set_account_position() |
| 397 | { |
| 398 | check_ajax_referer('njt-wa-nonce', 'nonce', true); |
| 399 | |
| 400 | $positions = Helper::sanitize_array($_POST['positions']); |
| 401 | $type = sanitize_text_field($_POST['type']); |
| 402 | |
| 403 | foreach ($positions as $index => $id) { |
| 404 | update_post_meta($id, "nta_wa_{$type}", $index); |
| 405 | } |
| 406 | |
| 407 | wp_send_json_success(); |
| 408 | } |
| 409 | |
| 410 | public function load_accounts_ajax() |
| 411 | { |
| 412 | check_ajax_referer('njt-wa-nonce', 'nonce', true); |
| 413 | $postType = PostType::getInstance(); |
| 414 | $accountsList = $postType->get_posts(); |
| 415 | $results = array_map(function ($account) { |
| 416 | $meta = get_post_meta($account->ID, 'nta_wa_account_info', true); |
| 417 | $avatar = get_the_post_thumbnail_url($account->ID); |
| 418 | $wg_show = get_post_meta($account->ID, 'nta_wa_widget_show', true); |
| 419 | $wg_position = get_post_meta($account->ID, 'nta_wa_widget_position', true); |
| 420 | $wc_show = get_post_meta($account->ID, 'nta_wa_wc_show', true); |
| 421 | $wc_position = get_post_meta($account->ID, 'nta_wa_wc_position', true); |
| 422 | |
| 423 | return array_merge(array( |
| 424 | 'accountId' => $account->ID, |
| 425 | 'accountName' => $account->post_title, |
| 426 | 'edit_link' => get_edit_post_link($account->ID), |
| 427 | 'avatar' => $avatar !== false ? $avatar : '', |
| 428 | 'widget_show' => empty($wg_show) ? 'OFF' : $wg_show, |
| 429 | 'widget_position' => $wg_position, |
| 430 | 'wc_show' => empty($wc_show) ? 'OFF' : $wc_show, |
| 431 | 'wc_position' => $wc_position, |
| 432 | ),$meta); |
| 433 | }, $accountsList); |
| 434 | wp_send_json_success($results); |
| 435 | } |
| 436 | |
| 437 | public function set_account_status() |
| 438 | { |
| 439 | check_ajax_referer('njt-wa-nonce', 'nonce', true); |
| 440 | $id = sanitize_text_field($_POST['accountId']); |
| 441 | $type = sanitize_text_field($_POST['type']); |
| 442 | $status = sanitize_text_field($_POST['status']); |
| 443 | |
| 444 | $wg_position = get_post_meta($id, 'nta_wa_widget_position', true); |
| 445 | $wc_position = get_post_meta($id, 'nta_wa_wc_position', true); |
| 446 | |
| 447 | if ('' === $wg_position) { |
| 448 | update_post_meta($id, "nta_wa_widget_position", 0); |
| 449 | } |
| 450 | |
| 451 | if ('' === $wc_position) { |
| 452 | update_post_meta($id, "nta_wa_wc_position", 0); |
| 453 | } |
| 454 | |
| 455 | update_post_meta($id, "nta_wa_{$type}", $status); |
| 456 | wp_send_json_success(); |
| 457 | } |
| 458 | } |