PluginProbe ʕ •ᴥ•ʔ
Microsoft Clarity / 0.8.0
Microsoft Clarity v0.8.0
0.10.26 0.10.25 0.10.24 0.8.0 0.9.0 0.9.1 0.9.2 0.9.3 0.9.4 trunk 0.10.0 0.10.1 0.10.10 0.10.11 0.10.12 0.10.13 0.10.14 0.10.15 0.10.16 0.10.17 0.10.18 0.10.19 0.10.2 0.10.20 0.10.21 0.10.22 0.10.23 0.10.3 0.10.4 0.10.5 0.10.6 0.10.7 0.10.8 0.10.9 0.2 0.4 0.5 0.6 0.6.1 0.7 0.7.1 0.7.2 0.7.3 0.7.4 0.7.5
microsoft-clarity / clarity.php
microsoft-clarity Last commit date
admin 3 years ago LICENSE.txt 5 years ago clarity.php 3 years ago index.php 5 years ago readme.txt 3 years ago
clarity.php
112 lines
1 <?php
2 /**
3 * Plugin Name: Microsoft Clarity
4 * Plugin URI: https://clarity.microsoft.com/
5 * Description: With data and session replay from Clarity, you'll see how people are using your site — where they get stuck and what they love.
6 * Version: 0.8.0
7 * Author: Microsoft
8 * Author URI: https://www.microsoft.com/en-us/
9 * License: MIT
10 * License URI: https://docs.opensource.microsoft.com/content/releasing/license.html
11 */
12
13 /**
14 * Require files only if is admin area
15 * @param void
16 * @return HTML
17 **/
18 if(is_admin()) {
19 require_once plugin_dir_path(__FILE__).'/admin/settings_callbacks.php';
20 require_once plugin_dir_path(__FILE__).'/admin/settings_page.php';
21 }
22
23 // path to Clarity admin page
24 function clarity_plugin_settings_link($links) {
25 $url = get_admin_url() . 'options-general.php?page=clarity_settings';
26 $settings_link = '<a href="' . $url . '">' . __('Settings', 'textdomain') . '</a>';
27 array_unshift($links, $settings_link);
28 return $links;
29 }
30
31 //??????????
32 function clarity_after_setup_theme() {
33 add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'clarity_plugin_settings_link');
34 }
35 add_action ('after_setup_theme', 'clarity_after_setup_theme');
36
37 /**
38 * Add origins for CORS ??????????????
39 * @param void
40 * @return HTML
41 **/
42 add_filter('allowed_http_origins', 'clarity_add_origins');
43 function clarity_add_origins($origins) {
44 $origins[] = 'https://www.clarity.ms';
45 return $origins;
46 }
47
48 /**
49 * Runs when Clarity Plugin is activated
50 * @param void
51 * @return void
52 **/
53 register_activation_hook(__FILE__, 'clarity_on_activation');
54 function clarity_on_activation() {
55 add_option("display_clarity_notice", true);
56 update_option("display_clarity_notice", true);
57 $clarity_wordpress_site_id = get_option('clarity_wordpress_site_id');
58 // Should run once in a Clarity plugin lifetime to identify the wordpress site to Clarity
59 if (empty($clarity_wordpress_site_id)) {
60 update_option('clarity_wordpress_site_id', wp_generate_uuid4());
61 };
62 }
63
64 /**
65 * Runs when Clarity Plugin is deactivated
66 * @param void
67 * @return void
68 **/
69 register_deactivation_hook( __FILE__, 'clarity_on_deactivation');
70 function clarity_on_deactivation() {
71 remove_menu_page('clarity_settings');
72 update_option("display_clarity_notice", false);
73 update_option('clarity_project_id', '');
74 return;
75 }
76
77 /**
78 * Runs when Clarity Plugin is uninstalled
79 * @param void
80 * @return void
81 **/
82 register_uninstall_hook('uninstall.php', 'clarity_on_uninstall');
83 function clarity_on_uninstall() {
84 delete_option("display_clarity_notice");
85 delete_option('clarity_project_id');
86 return;
87 }
88
89 function escape_value_for_script($value) {
90 return htmlspecialchars($value, ENT_QUOTES, 'UTF-8');
91 }
92
93 /**
94 * Adds the script to run clarity
95 * @param void
96 * @return void
97 **/
98 add_action('wp_head', 'clarity_add_script_to_header');
99 function clarity_add_script_to_header(){
100 $p_id_option = get_option('clarity_project_id');
101 if (!empty($p_id_option)) {
102 ?>
103 <script type="text/javascript">
104 (function(c,l,a,r,i,t,y){
105 c[a]=c[a]||function(){(c[a].q=c[a].q||[]).push(arguments)};t=l.createElement(r);t.async=1;
106 t.src="https://www.clarity.ms/tag/"+i+"?ref=wordpress";y=l.getElementsByTagName(r)[0];y.parentNode.insertBefore(t,y);
107 })(window, document, "clarity", "script", "<?php echo escape_value_for_script($p_id_option); ?>");
108 </script>
109 <?php
110 }
111 }
112