forked from chatwoot/wp-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchatwoot-plugin.php
More file actions
205 lines (196 loc) · 9.92 KB
/
Copy pathchatwoot-plugin.php
File metadata and controls
205 lines (196 loc) · 9.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
<?php
/**
* Plugin Name: Chatwoot Plugin
* Plugin URI: https://www.chatwoot.com/
* Description: Chatwoot Plugin for WordPress. This plugin helps you to quickly integrate Chatwoot live-chat widget on Wordpress websites.
* Author: antpb
* Author URI: chatwoot.com
* Text Domain: chatwoot-plugin
* Version: 0.2.0
*
* @package chatwoot-plugin
*/
add_action('admin_enqueue_scripts', 'chatwoot_admin_styles');
/**
* Load Chatwoot Admin CSS.
*
* @since 0.1.0
*
* @return {void}.
*/
function chatwoot_admin_styles() {
wp_enqueue_style('admin-styles', plugin_dir_url(__FILE__) . '/admin.css');
}
add_action( 'wp_enqueue_scripts', 'chatwoot_assets' );
/**
* Load Chatwoot Assets.
*
* @since 0.1.0
*
* @return {void}.
*/
function chatwoot_assets() {
wp_enqueue_script( 'chatwoot-client', plugins_url( '/js/chatwoot.js' , __FILE__ ) );
}
add_action( 'wp_enqueue_scripts', 'chatwoot_load' );
/**
* Initialize embed code options.
*
* @since 0.1.0
*
* @return {void}.
*/
function chatwoot_load() {
// Get our site options for site url and token.
$chatwoot_url = 'chatwoot_url = ' . json_encode(get_option('chatwootSiteURL')) . ';';
$chatwoot_token = 'chatwoot_token = ' . json_encode(get_option('chatwootSiteToken')) . ';';
$chatwoot_hide_message_bubble = 'chatwoot_hide_message_bubble = ' . json_encode(get_option('chatwootHideMessageBubble')) . ';';
$chatwoot_widget_locale = 'chatwoot_widget_locale = ' . json_encode(get_option('chatwootWidgetLocale')) . ';';
$chatwoot_widget_type = 'chatwoot_widget_type = ' . json_encode(get_option('chatwootWidgetType')) . ';';
$chatwoot_widget_position = 'chatwoot_widget_position = ' . json_encode(get_option('chatwootWidgetPosition')) . ';';
$chatwoot_launcher_text = 'chatwoot_launcher_text = ' . json_encode(get_option('chatwootLauncherText')) . ';';
// Localize our variables for the Javascript embed code.
wp_add_inline_script('chatwoot-client', $chatwoot_token, 'before');
wp_add_inline_script('chatwoot-client', $chatwoot_url, 'before');
wp_add_inline_script('chatwoot-client', $chatwoot_hide_message_bubble, 'before');
wp_add_inline_script('chatwoot-client', $chatwoot_widget_locale, 'before');
wp_add_inline_script('chatwoot-client', $chatwoot_widget_type, 'before');
wp_add_inline_script('chatwoot-client', $chatwoot_launcher_text, 'before');
wp_add_inline_script('chatwoot-client', $chatwoot_widget_position, 'before');
}
add_action('admin_menu', 'chatwoot_setup_menu');
/**
* Set up Settings options page.
*
* @since 0.1.0
*
* @return {void}.
*/
function chatwoot_setup_menu(){
add_options_page('Option', 'Chatwoot Settings', 'manage_options', 'chatwoot-plugin-options', 'chatwoot_options_page');
}
add_action( 'admin_init', 'chatwoot_register_settings' );
/**
* Register Settings.
*
* @since 0.1.0
*
* @return {void}.
*/
function chatwoot_register_settings() {
add_option('chatwootSiteToken', '');
add_option('chatwootSiteURL', '');
add_option('chatwootHideMessageBubble', false);
add_option('chatwootWidgetLocale', 'en');
add_option('chatwootWidgetType', 'standard');
add_option('chatwootWidgetPosition', 'right');
add_option('chatwootLauncherText', '');
register_setting('chatwoot-plugin-options', 'chatwootSiteToken');
register_setting('chatwoot-plugin-options', 'chatwootSiteURL');
register_setting('chatwoot-plugin-options', 'chatwootHideMessageBubble');
register_setting('chatwoot-plugin-options', 'chatwootWidgetLocale');
register_setting('chatwoot-plugin-options', 'chatwootWidgetType');
register_setting('chatwoot-plugin-options', 'chatwootWidgetPosition');
register_setting('chatwoot-plugin-options', 'chatwootLauncherText');
}
/**
* Render page.
*
* @since 0.1.0
*
* @return {void}.
*/
function chatwoot_options_page() {
?>
<div>
<h2>Chatwoot Settings</h2>
<form method="post" action="options.php" class="chatwoot--form">
<?php settings_fields('chatwoot-plugin-options'); ?>
<div class="form--input">
<label for="chatwootSiteToken">Chatwoot Website Token</label>
<input
type="text"
name="chatwootSiteToken"
value="<?php echo get_option('chatwootSiteToken'); ?>"
/>
</div>
<div class="form--input">
<label for="chatwootSiteURL">Chatwoot Installation URL</label>
<input
type="text"
name="chatwootSiteURL"
value="<?php echo get_option('chatwootSiteURL'); ?>"
/>
</div>
<hr />
<div style="margin-bottom: 15px;">
<label for="chatwootHideMessageBubble" style="font-weight: 600;">Hide Message Bubble</label>
<br>
<input type="checkbox" name="chatwootHideMessageBubble" value="1" <?php checked(1, get_option('chatwootHideMessageBubble'), true); ?>/>
</div>
<div class="form--input">
<label for="chatwootWidgetType">Widget Design</label>
<select name="chatwootWidgetType">
<option value="standard" <?php selected(get_option('chatwootWidgetType'), 'standard'); ?>>Standard</option>
<option value="expanded_bubble" <?php selected(get_option('chatwootWidgetType'), 'expanded_bubble'); ?>>Expanded Bubble</option>
</select>
</div>
<div class="form--input">
<label for="chatwootWidgetPosition">Widget Position</label>
<select name="chatwootWidgetPosition">
<option value="left" <?php selected(get_option('chatwootWidgetPosition'), 'left'); ?>>Left</option>
<option value="right" <?php selected(get_option('chatwootWidgetPosition'), 'right'); ?>>Right</option>
</select>
</div>
<div class="form--input">
<label for="chatwootWidgetLocale">Language</label>
<select name="chatwootWidgetLocale">
<option <?php selected(get_option('chatwootWidgetLocale'), 'ar'); ?> value="ar">العربية (ar)</option>
<option <?php selected(get_option('chatwootWidgetLocale'), 'ca'); ?> value="ca">Català (ca)</option>
<option <?php selected(get_option('chatwootWidgetLocale'), 'cs'); ?> value="cs">čeština (cs)</option>
<option <?php selected(get_option('chatwootWidgetLocale'), 'da'); ?> value="da">dansk (da)</option>
<option <?php selected(get_option('chatwootWidgetLocale'), 'de'); ?> value="de">Deutsch (de)</option>
<option <?php selected(get_option('chatwootWidgetLocale'), 'el'); ?> value="el">ελληνικά (el)</option>
<option <?php selected(get_option('chatwootWidgetLocale'), 'en'); ?> value="en">English (en)</option>
<option <?php selected(get_option('chatwootWidgetLocale'), 'es'); ?> value="es">Español (es)</option>
<option <?php selected(get_option('chatwootWidgetLocale'), 'fa'); ?> value="fa">فارسی (fa)</option>
<option <?php selected(get_option('chatwootWidgetLocale'), 'fi'); ?> value="fi">suomi, suomen kieli (fi)</option>
<option <?php selected(get_option('chatwootWidgetLocale'), 'fr'); ?> value="fr">Français (fr)</option>
<option <?php selected(get_option('chatwootWidgetLocale'), 'hi'); ?> value="hi'">हिन्दी (hi)</option>
<option <?php selected(get_option('chatwootWidgetLocale'), 'hu'); ?> value="hu">magyar nyelv (hu)</option>
<option <?php selected(get_option('chatwootWidgetLocale'), 'id'); ?> value="id">Bahasa Indonesia (id)</option>
<option <?php selected(get_option('chatwootWidgetLocale'), 'it'); ?> value="it">Italiano (it)</option>
<option <?php selected(get_option('chatwootWidgetLocale'), 'ja'); ?> value="ja">日本語 (ja)</option>
<option <?php selected(get_option('chatwootWidgetLocale'), 'ko'); ?> value="ko">한국어 (ko)</option>
<option <?php selected(get_option('chatwootWidgetLocale'), 'ml'); ?> value="ml">മലയാളം (ml)</option>
<option <?php selected(get_option('chatwootWidgetLocale'), 'nl'); ?> value="nl">Nederlands (nl) </option>
<option <?php selected(get_option('chatwootWidgetLocale'), 'no'); ?> value="no">norsk (no)</option>
<option <?php selected(get_option('chatwootWidgetLocale'), 'pl'); ?> value="pl">język polski (pl)</option>
<option <?php selected(get_option('chatwootWidgetLocale'), 'pt_BR'); ?> value="pt_BR">Português Brasileiro (pt-BR)
<option <?php selected(get_option('chatwootWidgetLocale'), 'pt'); ?> value="pt">Português (pt)</option>
<option <?php selected(get_option('chatwootWidgetLocale'), 'ro'); ?> value="ro">Română (ro)</option>
<option <?php selected(get_option('chatwootWidgetLocale'), 'ru'); ?> value="ru">русский (ru)</option>
<option <?php selected(get_option('chatwootWidgetLocale'), 'sv'); ?> value="sv">Svenska (sv)</option>
<option <?php selected(get_option('chatwootWidgetLocale'), 'ta'); ?> value="ta">தமிழ் (ta)</option>
<option <?php selected(get_option('chatwootWidgetLocale'), 'tr'); ?> value="tr">Türkçe (tr)</option>
<option <?php selected(get_option('chatwootWidgetLocale'), 'vi'); ?> value="vi">Tiếng Việt (vi)</option>
<option <?php selected(get_option('chatwootWidgetLocale'), 'zh_CN'); ?> value="zh_CN">中文 (zh-CN)</option>
<option <?php selected(get_option('chatwootWidgetLocale'), 'zh_TW'); ?> value="zh_TW">中文 (台湾) (zh-TW)</option>
<option <?php selected(get_option('chatwootWidgetLocale'), 'zh'); ?> value="zh'">中文 (zh)</option>
</select>
</div>
<?php if (get_option('chatwootWidgetType') == 'expanded_bubble') : ?>
<div class="form--input">
<label for="chatwootLauncherText">Launcher Text (Optional)</label>
<input
type="text"
name="chatwootLauncherText"
value="<?php echo get_option('chatwootLauncherText'); ?>"
/>
</div>
<?php endif; ?>
<?php submit_button(); ?>
</form>
</div>
<?php
}