@@ -17,6 +17,7 @@ public function get_file_name(): string
1717
1818 public function get_file_contents (): string
1919 {
20+ $ settings = get_settings ();
2021 $ upload_dir = get_upload_dir ();
2122
2223 // make path relative to ABSPATH again
@@ -25,6 +26,7 @@ public function get_file_contents(): string
2526 }
2627 $ wp_timezone_string = wp_timezone_string ();
2728 $ functions_filename = KOKO_ANALYTICS_PLUGIN_DIR . '/src/collect-functions.php ' ;
29+ $ excluded_ip_addresses_string = var_export ($ settings ['exclude_ip_addresses ' ], true );
2830
2931 // make path relative to ABSPATH again
3032 if (str_starts_with ($ functions_filename , ABSPATH )) {
@@ -48,6 +50,11 @@ public function get_file_contents(): string
4850// path to functions.php file in Koko Analytics plugin directory
4951require ' $ functions_filename';
5052
53+ // check if IP address is on list of addresses to ignore
54+ if (!isset( \$_GET['test']) && in_array(KokoAnalytics\get_client_ip(), $ excluded_ip_addresses_string)) {
55+ exit;
56+ }
57+
5158// function call to collect the request data
5259KokoAnalytics\collect_request();
5360
@@ -61,16 +68,16 @@ public function install()
6168 {
6269 $ file_name = $ this ->get_file_name ();
6370
64- /* Attempt to put the file into place if it does not exist already */
65- if (! is_file ($ file_name )) {
66- $ created = file_put_contents ($ file_name , $ this ->get_file_contents ());
67- if (! $ created ) {
68- return __ ('Error creating file ' , 'koko-analytics ' );
69- }
71+ // attempt to overwrite file with latest contents to ensure it's up-to-date
72+ file_put_contents ($ file_name , $ this ->get_file_contents ());
73+
74+ $ exists = is_file ($ file_name );
75+ update_option ('koko_analytics_use_custom_endpoint ' , $ exists , true );
76+
77+ if (! $ exists ) {
78+ return __ ('Error creating file ' , 'koko-analytics ' );
7079 }
7180
72- // File was successfully created, so let's start using it from now on
73- update_option ('koko_analytics_use_custom_endpoint ' , true , true );
7481 return true ;
7582 }
7683
0 commit comments