PluginProbe
Live Chat & AI Chatbot – onWebChat / 1.0.1
Live Chat & AI Chatbot – onWebChat v1.0.1
3.9.2 3.9.3 3.9.1 3.9.0 3.8.4 3.8.2 3.8.1 3.8.0 3.7.2 3.7.1 3.7.0 3.6.0 3.5.5 trunk 1.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 All 48 releases
onwebchat / onwebchat.php

onwebchat.php in Live Chat & AI Chatbot – onWebChat 1.0.1, at onwebchat.php

109 lines 3.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: OnWebChat Live Chat
4 Plugin URI: https://www.onwebchat.com/wp_plugin.php
5 Description: OnWebChat is a live chat system, that helps you communicate with your website's visitors.
6 Author: OnWebChat
7 Version: 1.0
8 Author URI: https://www.onwebchat.com
9 */
10
11 // get logo url
12 define('ONWEBCHAT_SMALL_LOGO', plugins_url( 'images/onwebchat-logo.png' , __FILE__ ));
13
14 // call function on hook admin_menu
15 add_action('admin_menu','onwebchat_setup_menu');
16
17 // define the settings
18 add_action('admin_init','onwebchat_register_setttings');
19
20 // add widget plugin to the footer
21 add_action('wp_footer', 'onwebchat_add_script_at_footer');
22
23 // add menu page on admin menu with function onwebchat_init_menu_page()
24 function onwebchat_setup_menu() {
25 add_menu_page( 'OnWebChat Settings', 'OnWebChat', 'administrator', 'onwebchat_settings', 'onwebchat_init_menu_page', ONWEBCHAT_SMALL_LOGO);
26 }
27
28 // display admin option page
29 function onwebchat_init_menu_page() {
30 ?>
31 <div>
32 <h2>OnWebChat Settings Page</h2>
33 </br>
34 <form action="options.php" method="post">
35 <?php settings_fields('onwebchat_plugin_option'); ?>
36 <!-- prints all settings inputs we need -->
37 <?php do_settings_sections('onwebchat_plugin'); ?>
38 <input name="Submit" type="submit" value="<?php esc_attr_e('Save Changes'); ?>" />
39 </form>
40 </div>
41 <?php
42 }
43
44 // register the settings to store data
45 function onwebchat_register_setttings() {
46 register_setting( 'onwebchat_plugin_option', 'onwebchat_plugin_option', 'plugin_options_validate' );
47 //* plugin
48 add_settings_section('plugin_main', 'Install Chat Widget', 'onwebchat_section_text', 'onwebchat_plugin');
49 //* plugin
50 add_settings_field('plugin_text_string', 'Chat Id:', 'onwebchat_setting_field_text', 'onwebchat_plugin', 'plugin_main');
51 }
52
53 // prints the text of sections
54 function onwebchat_section_text() {
55 echo '<p>To install OnWebChat on your Wordpress site please insert the Chat Id to the following field.</p>'.
56 '<p>You will find Chat Id in settings-page of OnWebChat admin, <a href="https://www.onwebchat.com/login.php" target="_blank">OnWebChat - Admin</a> </p>';
57 }
58
59 // print the text of section field
60 function onwebchat_setting_field_text() {
61 $options = get_option('onwebchat_plugin_option');
62 echo "<input id='plugin_text_string' name='onwebchat_plugin_option[text_string]' size='40' type='text' value='{$options['text_string']}' />";
63 }
64
65 // validate data input
66 function plugin_options_validate($input) {
67 $newinput['text_string'] = trim($input['text_string']);
68
69 if(!preg_match('/^[a-f0-9\\/]{35,50}$/i', $newinput['text_string'])) {
70 $newinput['text_string'] = '';
71 }
72
73 return $newinput;
74 }
75
76 // print chat widget code
77 function onwebchat_add_script_at_footer() {
78
79 $options = get_option('onwebchat_plugin_option');
80 $chatId = $options['text_string'];
81
82 $widgetCode = "<script type='text/javascript'>
83 var onWebChat={ar:[], set: function(a,b){if (typeof onWebChat_==='undefined'){this.ar.
84 push([a,b]);}else{onWebChat_.set(a,b);}},get:function(a){return(onWebChat_.get(a));},w
85 :(function(){ var ga=document.createElement('script'); ga.type = 'text/javascript';ga.
86 async=1;ga.src='//www.onwebchat.com/clientchat/$chatId';
87 var s=document.getElementsByTagName('script')[0];s.parentNode.insertBefore(ga,s);})()}
88 </script>";
89
90
91 //check if user is logged if yes get username, email (all users registered have them)
92 if ( is_user_logged_in() ) {
93
94 global $current_user;
95 get_currentuserinfo();
96
97 // get user name
98 $onwebchat_user = $current_user->user_login;
99
100 // get user email
101 $onwebchat_email = $current_user->user_email;
102
103 //add api info
104 $widgetCode = $widgetCode."<script type='text/javascript'>onWebChat.set('name','$onwebchat_user');onWebChat.set('email','$onwebchat_email'); </script>";
105 }
106
107 echo $widgetCode;
108 }
109 ?>