'sanitize_text_field' ) ); register_setting( 'akia_chat_settings', 'akia_chat_office_name', array( 'sanitize_callback' => 'sanitize_text_field' ) ); register_setting( 'akia_chat_settings', 'akia_chat_powered_by_acknowledged', array( 'sanitize_callback' => 'absint' ) ); } add_action( 'admin_init', 'akia_chat_register_settings' ); // Add settings page to menu function akia_chat_add_settings_page() { add_options_page( 'Akia Web Chat Settings', 'Akia Web Chat', 'manage_options', 'akia-chat-settings', 'akia_chat_settings_page' ); } add_action( 'admin_menu', 'akia_chat_add_settings_page' ); // Enqueue admin scripts for settings page function akia_chat_admin_enqueue_scripts( $hook ) { // Only load on our settings page if ( 'settings_page_akia-chat-settings' !== $hook ) { return; } $akia_domain = 'https://sys.akia.ai/'; $nonce = wp_create_nonce( 'akia_chat_save_settings' ); // Enqueue the admin script $script_url = plugins_url( 'admin.js', __FILE__ ); $script_version = filemtime( plugin_dir_path( __FILE__ ) . 'admin.js' ); // Use file modification time for cache busting wp_enqueue_script( 'akia-chat-admin', $script_url, array(), $script_version, true ); // Localize script with PHP variables wp_localize_script( 'akia-chat-admin', 'akiaChatAdmin', array( 'akiaDomain' => $akia_domain, 'ajaxNonce' => $nonce, ) ); } add_action( 'admin_enqueue_scripts', 'akia_chat_admin_enqueue_scripts' ); // AJAX handler for auto-saving settings function akia_chat_save_settings_ajax() { check_ajax_referer( 'akia_chat_save_settings', '_ajax_nonce' ); if ( ! current_user_can( 'manage_options' ) ) { wp_send_json_error( 'Insufficient permissions' ); return; } $token = isset( $_POST['akia_chat_website_token'] ) ? sanitize_text_field( wp_unslash( $_POST['akia_chat_website_token'] ) ) : ''; $office_name = isset( $_POST['akia_chat_office_name'] ) ? sanitize_text_field( wp_unslash( $_POST['akia_chat_office_name'] ) ) : ''; $powered_by_acknowledged = isset( $_POST['akia_chat_powered_by_acknowledged'] ) ? absint( $_POST['akia_chat_powered_by_acknowledged'] ) : 0; // Get existing token to check if this is a new connection or just updating checkbox $existing_token = get_option( 'akia_chat_website_token', '' ); // Only prevent saving a NEW token if checkbox is not checked // Allow unchecking checkbox even if token exists (user wants to keep account but disable chat) if ( ! empty( $token ) && empty( $existing_token ) && ! $powered_by_acknowledged ) { wp_send_json_error( 'You must acknowledge that a "Powered by Akia" link may appear before connecting.' ); return; } update_option( 'akia_chat_website_token', $token ); update_option( 'akia_chat_office_name', $office_name ); update_option( 'akia_chat_powered_by_acknowledged', $powered_by_acknowledged ); wp_send_json_success( 'Settings saved successfully' ); } add_action( 'wp_ajax_akia_chat_save_settings', 'akia_chat_save_settings_ajax' ); // Add Settings link to plugin action links function akia_chat_add_settings_link( $links ) { $settings_link = '' . __( 'Settings', 'akia-web-chat' ) . ''; array_unshift( $links, $settings_link ); return $links; } add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'akia_chat_add_settings_link' ); // Settings page HTML function akia_chat_settings_page() { if ( ! current_user_can( 'manage_options' ) ) { return; } $token = get_option( 'akia_chat_website_token', '' ); $office_name = get_option( 'akia_chat_office_name', '' ); $powered_by_acknowledged = get_option( 'akia_chat_powered_by_acknowledged', 0 ); $akia_domain = 'https://sys.akia.ai/'; // Change this to your Akia domain (e.g., https://sys.akia.ai for production) ?>
|
|
|
|
This checkbox must be checked to use the plugin. The "Powered by Akia" attribution may appear as part of the chat widget. |
Akia Web Chat is not properly configured. Configure in settings.
Akia Web Chat is not properly configured. Configure in settings.