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