Skip to content

Commit

Permalink
fix instance url when multisite and automatic. also make sure matomo …
Browse files Browse the repository at this point in the history
…id is saved before sync
  • Loading branch information
annlickander committed Jun 26, 2023
1 parent ce4c201 commit a982fbb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
9 changes: 5 additions & 4 deletions src/Admin/Admin_Analytics_Tab.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ public static function notice(): void

public static function save($site, $request_data): void
{

if (isset($request_data['matomo_ID']) && !isset($request_data['automatic_connection'])) {
update_blog_option($site->id, 'bm_wp_matomo_site_id', $request_data['matomo_ID']);
}

if (isset($request_data['automatic_connection'])) {
update_blog_option($site->id, Matomo_Sync::$automatic_connection_option,
$request_data['automatic_connection'] ?? 0);
Expand All @@ -53,10 +58,6 @@ public static function save($site, $request_data): void
0);
}

if (isset($request_data['matomo_ID']) && !isset($request_data['automatic_connection'])) {
update_blog_option($site->id, 'bm_wp_matomo_site_id', $request_data['matomo_ID']);
}

if (isset($request_data['instance_url'])) {
update_blog_option($site->id, 'bm_wp_matomo_url', $request_data['instance_url']);
}
Expand Down
9 changes: 8 additions & 1 deletion src/Modules/Matomo.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,14 @@ protected static function get_instance_url(): string
{
$value = 'https://analytics.bmedia.io/';
if (is_multisite()) {
$value = get_option('bm_wp_matomo_url', 'https://analytics.bmedia.io/');
$is_connection_enabled_for_site = Matomo_Sync::is_enabled_for_site( get_current_blog_id() );
if( $is_connection_enabled_for_site ){
$value = defined('BM_WP_MATOMO_INSTANCE_URL') ? BM_WP_MATOMO_INSTANCE_URL : 'https://analytics.bmedia.io/';
}
else{
$value = get_option('bm_wp_matomo_url', 'https://analytics.bmedia.io/');
}

}

return trailingslashit(apply_filters('bm_wpexp_matomo_url', $value ));
Expand Down

0 comments on commit a982fbb

Please sign in to comment.