onWebChat, for AI training). require_once __DIR__ . '/includes/woocommerce-sync.php'; // Live order-status lookup (onWebChat -> plugin, during a chat). require_once __DIR__ . '/includes/woocommerce-orders.php'; } }); // add styles add_action( 'admin_enqueue_scripts', 'register_plugin_styles' ); // call function on hook admin_menu add_action('admin_menu','onwebchat_setup_menu'); // create login error notice add_action( 'admin_notices', 'onwebchat_login_error' ); // define the settings add_action('admin_init','onwebchat_register_setttings'); // handle form submissions early (before any output) add_action('admin_init', 'onwebchat_handle_all_form_submissions'); /* ---------------------------------------------------- * * Display onWebChat on footer * ---------------------------------------------------- */ // add widget plugin to the footer add_action('wp_footer', 'onwebchat_add_script_at_footer'); /* ----------------------------------------------------- * * Admin Page registration * ----------------------------------------------------- */ function onwebchat_setup_menu() { add_menu_page( 'onWebChat Settings', 'onWebChat', 'administrator', 'onwebchat_settings', 'onwebchat_init_menu_page', ONWEBCHAT_SMALL_LOGO); } /* ------------------------------------------------------ * * Admin Page Display Function * ------------------------------------------------------ */ function onwebchat_init_menu_page() { // Load the new tabbed settings page require_once __DIR__ . '/admin/settings-page.php'; onwebchat_settings_page(); } /* ----------------------------------------------------- * * Admin Page Styles Registration * ----------------------------------------------------- */ function register_plugin_styles() { wp_register_style( 'onwebchat', plugins_url( 'onwebchat/css/onwebchat.css' ) ); wp_enqueue_style( 'onwebchat' ); } /* ----------------------------------------------------- * * Tabs Settings Registration * ----------------------------------------------------- */ function onwebchat_register_setttings() { /******************** Account Tab ************************/ //* register the Chat Id register_setting( 'onwebchat_plugin_option', 'onwebchat_plugin_option'); //* register the username register_setting( 'onwebchat_plugin_option', 'onwebchat_plugin_option_user'); //* register the hide (checkbox) register_setting( 'onwebchat_plugin_option_checkbox', 'onwebchat_plugin_option_hide'); //TODO api code //* register the api code register_setting( 'onwebchat_plugin_option', 'onwebchat_plugin_option_api_code'); /******************** WooCommerce Sync Settings ************************/ register_setting( 'onwebchat_wc_sync', 'onwebchat_wc_sync_enabled'); register_setting( 'onwebchat_wc_sync', 'onwebchat_wc_sync_mode'); register_setting( 'onwebchat_wc_sync', 'onwebchat_wc_sync_include_price'); register_setting( 'onwebchat_wc_sync', 'onwebchat_wc_sync_secret'); register_setting( 'onwebchat_wc_sync', 'onwebchat_wc_last_bulk_sync'); register_setting( 'onwebchat_wc_sync', 'onwebchat_wc_excluded_categories'); register_setting( 'onwebchat_wc_sync', 'onwebchat_wc_sync_categories'); } /* ----------------------------------------------------- * * onWebChat Display Function * ----------------------------------------------------- */ // print chat widget code function onwebchat_add_script_at_footer() { $options = get_option('onwebchat_plugin_option'); $chatId = (is_array($options) && isset($options['text_string'])) ? $options['text_string'] : ''; //$hideWidget = get_option('onwebchat_plugin_option_hide'); $hideWidget = false; // If no chat ID is configured, don't output widget code if (empty($chatId)) { return; } // Merchant option: show the chat widget only to signed-in users (default: off). if (get_option('onwebchat_plugin_option_logged_only', 0) && !is_user_logged_in()) { return; } $widgetCode = ""; $apiCode = get_option('onwebchat_plugin_option_api_code'); $apiCode = str_replace('\\','',$apiCode); $apiCode = ""; $widgetCode .= $apiCode; // Identity PROOF for the logged-in email: HMAC_SHA256(shared sync secret, lowercase(email)). // The onWebChat server recomputes it with the same secret; only when it matches does the AI treat // the email as verified and allow the email-only "my recent orders" lookup. A visitor faking // onWebChat.set('email') from the console cannot produce this hash, so they can never list another // customer's orders. The '0' sentinel means "not signed in": it tells onWebChat to DROP any stored // proof, so on a shared computer nobody inherits the previous customer's identity after a logout. $onwebchat_email_hash = '0'; $onwebchat_wc_secret = get_option('onwebchat_wc_sync_secret'); //check if user is logged if yes get username, email if ( is_user_logged_in() ) { $current_user = wp_get_current_user(); // get user name (escaped for safe use inside the inline script) $onwebchat_user = esc_js( $current_user->user_login ); // get user email (escaped for safe use inside the inline script) $onwebchat_email = esc_js( $current_user->user_email ); //add api info if ($onwebchat_user != null && $onwebchat_user != "" && $onwebchat_user != "guest" && $onwebchat_user != "Guest") { if ($onwebchat_email != null && $onwebchat_email != ""){ // Hash the raw (unescaped) email so both sides hash identical bytes. if (!empty($onwebchat_wc_secret)) { $onwebchat_email_hash = hash_hmac('sha256', strtolower(trim($current_user->user_email)), $onwebchat_wc_secret); } $widgetCode = $widgetCode.""; } else { $widgetCode = $widgetCode.""; } } } if (!empty($onwebchat_wc_secret)) { $widgetCode .= ""; } $currentPage = substr( strtolower($_SERVER['SERVER_PROTOCOL']), 0, strpos( strtolower($_SERVER['SERVER_PROTOCOL']), "/") ); $currentPage .= ( empty($_SERVER['HTTPS']) ? NULL : ( ($_SERVER['HTTPS'] == "on") ? "s" : NULL) ); $currentPage .= "://" . $_SERVER['SERVER_NAME']; $currentPage .= ( $_SERVER['SERVER_PORT'] == 80 ? "" : ":".$_SERVER['SERVER_PORT'] ); $currentPage .= $_SERVER['REQUEST_URI']; $pagesSelect = get_option('onwebchat_plugin_option_pages_select'); $showPages = get_option('onwebchat_plugin_option_show_pages'); $showPages = explode(' ', $showPages); $hidePages = get_option('onwebchat_plugin_option_hide_pages'); $hidePages = explode(' ', $hidePages); $showSelect=true; if ($pagesSelect==1){ } else if ($pagesSelect==2){ $showSelect=false; foreach ($showPages as $page){ if ($page !== "") { if (strpos($currentPage, $page) !== false) { $showSelect = true; } } } } else if ($pagesSelect==3){ $showSelect=true; foreach ($hidePages as $page){ if ($page !== "") { if (strpos($currentPage, $page) !== false) { $showSelect = false; } } } } else if($pagesSelect == 4) { //hide chat widget from all pages $hideWidget = true; } if(!$hideWidget && $showSelect) { echo $widgetCode; } } /************************************************************************ * display error function ***********************************************************************/ function onwebchat_login_error($contition = false) { if($contition) { ?>
Invalid credentials! Please make sure you have entered the correct email and password, OR provide a valid Chat ID