forked from crisp-im/crisp-plugin-wordpress
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcrisp.php
More file actions
81 lines (66 loc) · 2.04 KB
/
crisp.php
File metadata and controls
81 lines (66 loc) · 2.04 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
<?php
/**
* @package Crisp
* @version 0.1
*/
/*
Plugin Name: Crisp
Plugin URI: http://wordpress.org/plugins/crisp/
Description: Crisp is a Livechat plugin
Author: Crisp Communications
Version: 0.1
Author URI: https://crisp.im
*/
add_action('admin_menu', 'crisp_create_menu');
function crisp_create_menu() {
add_menu_page('Crisp Settings', 'Crisp Settings', 'administrator', __FILE__, 'crisp_plugin_settings_page' , 'https://crisp.im/favicon.png');
add_action( 'admin_init', 'register_crisp_plugin_settings' );
}
function register_crisp_plugin_settings() {
register_setting( 'crisp-plugin-settings-group', 'website_id' );
}
function crisp_plugin_settings_page() {
?>
<div class="wrap">
<h2>Crisp</h2>
<form method="post" action="options.php">
<?php settings_fields( 'crisp-plugin-settings-group' ); ?>
<?php do_settings_sections( 'crisp-plugin-settings-group' ); ?>
<table class="form-table">
<td><a target="_blank" href="https://app.crisp.im/#/settings/websites">Get your Website Id here</a></td>
<tr valign="top">
<th scope="row">Website Id</th>
<td><input type="text" name="website_id" value="<?php echo esc_attr( get_option('website_id') ); ?>" /></td>
</tr>
</table>
<?php submit_button(); ?>
</form>
</div>
<?php }
add_action('wp_head', 'crisp_hook_head');
function crisp_hook_head() {
$website_id = get_option('website_id');
$output="<script type='text/javascript'>
CRISP_WEBSITE_ID = '$website_id';
(function(){
d=document;s=d.createElement('script');
s.src='https://client.crisp.im/l.js';
s.async=1;d.getElementsByTagName('head')[0].appendChild(s);
})();
</script>";
echo $output;
if ( is_user_logged_in() ) {
$current_user = wp_get_current_user();
$email = $current_user->user_email;
$output='<script type="text/javascript">
jQuery(function($){
window.CRISP_READY_TRIGGER = function() {
// Feed this call with your own internal email data.
$crisp.user.email.set("' . $email . '");
};
});
</script>';
echo $output;
}
}
?>