braekling / WP-Matomo

Official WP-Matomo (former WP-Piwik) repository
GNU General Public License v3.0
31 stars 29 forks source link

Enter manually save code in wrong place #46

Closed hrhthegreat closed 7 years ago

hrhthegreat commented 7 years ago

Hello,

As far as I understood, When you enter the code manually the data should be saved on sitemeta table on row with meta_key wp-piwik-manually. But with wp-piwik 1.0.13 the data is saved in first site options table on tracking code. Can anyone else confirm this behavior? I tested on fresh setup also and the result is the same.

I investigated the problem and it's here : private function prepareTrackingCode($value, $in) { if ($in ['track_mode'] == 'manually' || $in ['track_mode'] == 'disabled') { $value = stripslashes ( $value ); if ($this->checkNetworkActivation ()) add_site_option ( 'wp-piwik-manually', $value ); return $value; } /*$result = self::$wpPiwik->updateTrackingCode (); echo '<pre>'; print_r($result); echo '</pre>'; $this->setOption ( 'noscript_code', $result ['noscript'] );*/ return; // $result ['script']; }

add_site_option would not update the option is it's already exist. So, First it should check and the update or add.

braekling commented 7 years ago

I replaced add_site_option by update_site_option. This should make sure the tracking code is updated even if the option already exists.