Matomo Analytics – Ethical Stats. Powerful Insights. - Version 4.3.1

Version Description

Download this release

Release Info

Developer matomoteam
Plugin Icon 128x128 Matomo Analytics – Ethical Stats. Powerful Insights.
Version 4.3.1
Comparing to
See all releases

Code changes from version 4.3.0 to 4.3.1

classes/WpMatomo.php CHANGED
@@ -33,6 +33,7 @@ use \WpMatomo\Ecommerce\Woocommerce;
33
  use \WpMatomo\Report\Renderer;
34
  use WpMatomo\API;
35
  use \WpMatomo\Admin\Admin;
 
36
 
37
  class WpMatomo {
38
 
@@ -92,9 +93,15 @@ class WpMatomo {
92
  $user_sync->register_hooks();
93
 
94
  $referral = new \WpMatomo\Referral();
95
- if ($referral->should_show()) {
96
  $referral->register_hooks();
97
  }
 
 
 
 
 
 
98
  }
99
 
100
  $tracking_code = new TrackingCode( self::$settings );
@@ -127,7 +134,7 @@ class WpMatomo {
127
  $upload_path = $paths->get_upload_base_dir();
128
 
129
  if ( $upload_path
130
- && ! is_writable( dirname( $upload_path ) ) ) {
131
  add_action(
132
  'init',
133
  function () use ( $upload_path ) {
@@ -135,7 +142,7 @@ class WpMatomo {
135
  add_action(
136
  'admin_notices',
137
  function () use ( $upload_path ) {
138
- echo '<div class="error"><p>' . sprintf(__( 'Matomo Analytics requires the uploads directory %s to be writable. Please make the directory writable for it to work.', 'matomo' ), '(' . esc_html( dirname( $upload_path ) ) . ')') . '</p></div>';
139
  }
140
  );
141
  }
@@ -150,21 +157,20 @@ class WpMatomo {
150
 
151
  public static function is_admin_user() {
152
  if ( ! function_exists( 'is_multisite' )
153
- || ! is_multisite() ) {
154
  return current_user_can( 'administrator' );
155
  }
156
 
157
  return is_super_admin();
158
  }
159
 
160
- private static function get_active_plugins()
161
- {
162
  $plugins = [];
163
- if (function_exists('is_multisite') && is_multisite()) {
164
  $muplugins = get_site_option( 'active_sitewide_plugins' );
165
- $plugins = array_keys($muplugins);
166
  }
167
- $plugins = array_merge((array) get_option( 'active_plugins', array() ), $plugins);
168
 
169
  return $plugins;
170
  }
@@ -177,8 +183,8 @@ class WpMatomo {
177
  // we are not using is_plugin_active() for performance reasons
178
  $active_plugins = self::get_active_plugins();
179
 
180
- if (in_array('wp-rss-aggregator/wp-rss-aggregator.php', $active_plugins)
181
- || in_array('wp-defender/wp-defender.php', $active_plugins)) {
182
  return true;
183
  }
184
 
@@ -199,12 +205,12 @@ class WpMatomo {
199
 
200
  public function init_plugin() {
201
  if ( ( is_admin() || matomo_is_app_request() )
202
- && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) ) {
203
  $installer = new Installer( self::$settings );
204
  $installer->register_hooks();
205
  if ( $installer->looks_like_it_is_installed() ) {
206
  if ( is_admin()
207
- && ( ! defined( 'MATOMO_ENABLE_AUTO_UPGRADE' ) || MATOMO_ENABLE_AUTO_UPGRADE ) ) {
208
  $updater = new Updater( self::$settings );
209
  $updater->update_if_needed();
210
  }
@@ -222,8 +228,8 @@ class WpMatomo {
222
  }
223
  $tracking_code = new TrackingCode( self::$settings );
224
  if ( self::$settings->is_tracking_enabled()
225
- && self::$settings->get_global_option( 'track_ecommerce' )
226
- && ! $tracking_code->is_hidden_user() ) {
227
  $tracker = new AjaxTracker( self::$settings );
228
 
229
  $woocommerce = new Woocommerce( $tracker );
@@ -239,8 +245,7 @@ class WpMatomo {
239
  }
240
  }
241
 
242
- public static function should_disable_addhandler()
243
- {
244
- return defined('MATOMO_DISABLE_ADDHANDLER') && MATOMO_DISABLE_ADDHANDLER;
245
  }
246
  }
33
  use \WpMatomo\Report\Renderer;
34
  use WpMatomo\API;
35
  use \WpMatomo\Admin\Admin;
36
+ use WpMatomo\RedirectOnActivation;
37
 
38
  class WpMatomo {
39
 
93
  $user_sync->register_hooks();
94
 
95
  $referral = new \WpMatomo\Referral();
96
+ if ( $referral->should_show() ) {
97
  $referral->register_hooks();
98
  }
99
+
100
+ /*
101
+ * @see https://github.com/matomo-org/matomo-for-wordpress/issues/434
102
+ */
103
+ $redirect = new RedirectOnActivation($this);
104
+ $redirect->register_hooks();
105
  }
106
 
107
  $tracking_code = new TrackingCode( self::$settings );
134
  $upload_path = $paths->get_upload_base_dir();
135
 
136
  if ( $upload_path
137
+ && ! is_writable( dirname( $upload_path ) ) ) {
138
  add_action(
139
  'init',
140
  function () use ( $upload_path ) {
142
  add_action(
143
  'admin_notices',
144
  function () use ( $upload_path ) {
145
+ echo '<div class="error"><p>' . sprintf( __( 'Matomo Analytics requires the uploads directory %s to be writable. Please make the directory writable for it to work.', 'matomo' ), '(' . esc_html( dirname( $upload_path ) ) . ')' ) . '</p></div>';
146
  }
147
  );
148
  }
157
 
158
  public static function is_admin_user() {
159
  if ( ! function_exists( 'is_multisite' )
160
+ || ! is_multisite() ) {
161
  return current_user_can( 'administrator' );
162
  }
163
 
164
  return is_super_admin();
165
  }
166
 
167
+ private static function get_active_plugins() {
 
168
  $plugins = [];
169
+ if ( function_exists( 'is_multisite' ) && is_multisite() ) {
170
  $muplugins = get_site_option( 'active_sitewide_plugins' );
171
+ $plugins = array_keys( $muplugins );
172
  }
173
+ $plugins = array_merge( (array) get_option( 'active_plugins', array() ), $plugins );
174
 
175
  return $plugins;
176
  }
183
  // we are not using is_plugin_active() for performance reasons
184
  $active_plugins = self::get_active_plugins();
185
 
186
+ if ( in_array( 'wp-rss-aggregator/wp-rss-aggregator.php', $active_plugins )
187
+ || in_array( 'wp-defender/wp-defender.php', $active_plugins ) ) {
188
  return true;
189
  }
190
 
205
 
206
  public function init_plugin() {
207
  if ( ( is_admin() || matomo_is_app_request() )
208
+ && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) ) {
209
  $installer = new Installer( self::$settings );
210
  $installer->register_hooks();
211
  if ( $installer->looks_like_it_is_installed() ) {
212
  if ( is_admin()
213
+ && ( ! defined( 'MATOMO_ENABLE_AUTO_UPGRADE' ) || MATOMO_ENABLE_AUTO_UPGRADE ) ) {
214
  $updater = new Updater( self::$settings );
215
  $updater->update_if_needed();
216
  }
228
  }
229
  $tracking_code = new TrackingCode( self::$settings );
230
  if ( self::$settings->is_tracking_enabled()
231
+ && self::$settings->get_global_option( 'track_ecommerce' )
232
+ && ! $tracking_code->is_hidden_user() ) {
233
  $tracker = new AjaxTracker( self::$settings );
234
 
235
  $woocommerce = new Woocommerce( $tracker );
245
  }
246
  }
247
 
248
+ public static function should_disable_addhandler() {
249
+ return defined( 'MATOMO_DISABLE_ADDHANDLER' ) && MATOMO_DISABLE_ADDHANDLER;
 
250
  }
251
  }
classes/WpMatomo/RedirectOnActivation.php ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Matomo - free/libre analytics platform
4
+ *
5
+ * @link https://matomo.org
6
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
7
+ * @package matomo
8
+ */
9
+
10
+ namespace WpMatomo;
11
+
12
+ use \WpMatomo\Admin\TrackingSettings;
13
+
14
+ class RedirectOnActivation {
15
+ /**
16
+ * @var Settings
17
+ */
18
+ public static $settings;
19
+
20
+ public function __construct() {
21
+ self::$settings = new Settings();
22
+ }
23
+
24
+ public function register_hooks() {
25
+ register_activation_hook(MATOMO_ANALYTICS_FILE, [ $this, 'matomo_activate' ] );
26
+ add_action( 'admin_init', [ $this, 'matomo_plugin_redirect' ] );
27
+ }
28
+
29
+ public function matomo_activate() {
30
+ add_option( 'matomo_plugin_do_activation_redirect', true );
31
+ }
32
+
33
+ public function matomo_plugin_redirect() {
34
+ if ( get_option( 'matomo_plugin_do_activation_redirect', false ) ) {
35
+ delete_option( 'matomo_plugin_do_activation_redirect' );
36
+ $this->redirect_to_getting_started();
37
+ }
38
+ }
39
+ /**
40
+ * We don't test the result of the wp_redirect method and we silent this method
41
+ * as this method will not work during unit tests.
42
+ * We just return if yes or no we should redirect
43
+ *
44
+ * @see https://github.com/matomo-org/matomo-for-wordpress/issues/434
45
+ * @return boolean
46
+ */
47
+ public function redirect_to_getting_started() {
48
+ $redirect = false;
49
+ if(!isset($_GET['activate-multi'])) {
50
+ if
51
+ (
52
+ ( self::$settings->get_global_option( Settings::SHOW_GET_STARTED_PAGE ) === 1 ) &&
53
+ ( self::$settings->get_global_option( 'track_mode' ) === TrackingSettings::TRACK_MODE_DISABLED )
54
+ ) {
55
+ $redirect = true;
56
+ @wp_redirect( admin_url( 'admin.php?page=matomo-get-started' ) );
57
+ }
58
+ }
59
+ return $redirect;
60
+ }
61
+ }
classes/WpMatomo/User/Sync.php CHANGED
@@ -48,11 +48,11 @@ class Sync {
48
  }
49
 
50
  public function register_hooks() {
51
- add_action( 'add_user_role', array( $this, 'sync_current_users' ), $prio = 10, $args = 0 );
52
- add_action( 'remove_user_role', array( $this, 'sync_current_users' ), $prio = 10, $args = 0 );
53
- add_action( 'add_user_to_blog', array( $this, 'sync_current_users' ), $prio = 10, $args = 0 );
54
- add_action( 'remove_user_from_blog', array( $this, 'sync_current_users' ), $prio = 10, $args = 0 );
55
- add_action( 'user_register', array( $this, 'sync_current_users' ), $prio = 10, $args = 0 );
56
  add_action( 'profile_update', array( $this, 'sync_maybe_background' ), $prio = 10, $args = 0 );
57
  }
58
 
@@ -64,7 +64,7 @@ class Sync {
64
  // if they eg alter `get_users` option
65
  wp_schedule_single_event(time() + 5, ScheduledTasks::EVENT_SYNC);
66
  } else {
67
- $this->sync_current_users();
68
  }
69
  }
70
 
@@ -146,6 +146,22 @@ class Sync {
146
  }
147
  }
148
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
149
  /**
150
  * Sync all users. Make sure to always pass all sites that exist within a given site... you cannot just sync an individual
151
  * user... we would delete all other users
48
  }
49
 
50
  public function register_hooks() {
51
+ add_action( 'add_user_role', array( $this, 'sync_current_users_1000' ), $prio = 10, $args = 0 );
52
+ add_action( 'remove_user_role', array( $this, 'sync_current_users_1000' ), $prio = 10, $args = 0 );
53
+ add_action( 'add_user_to_blog', array( $this, 'sync_current_users_1000' ), $prio = 10, $args = 0 );
54
+ add_action( 'remove_user_from_blog', array( $this, 'sync_current_users_1000' ), $prio = 10, $args = 0 );
55
+ add_action( 'user_register', array( $this, 'sync_current_users_1000' ), $prio = 10, $args = 0 );
56
  add_action( 'profile_update', array( $this, 'sync_maybe_background' ), $prio = 10, $args = 0 );
57
  }
58
 
64
  // if they eg alter `get_users` option
65
  wp_schedule_single_event(time() + 5, ScheduledTasks::EVENT_SYNC);
66
  } else {
67
+ $this->sync_current_users_1000();
68
  }
69
  }
70
 
146
  }
147
  }
148
 
149
+ /**
150
+ * similar method to sync_current_users which synchronise on the fly only if we have less than 1000 users.
151
+ * Otherwise it will be done by a background task
152
+ * @see Sync::sync_current_users()
153
+ * @see https://github.com/matomo-org/matomo-for-wordpress/issues/460
154
+ * @return void
155
+ */
156
+ public function sync_current_users_1000() {
157
+ $idsite = Site::get_matomo_site_id( get_current_blog_id() );
158
+ if ( $idsite ) {
159
+ $users = $this->get_users();
160
+ if ( count( $users ) < 1000 ) {
161
+ $this->sync_users( $users, $idsite );
162
+ }
163
+ }
164
+ }
165
  /**
166
  * Sync all users. Make sure to always pass all sites that exist within a given site... you cannot just sync an individual
167
  * user... we would delete all other users
matomo.php CHANGED
@@ -4,10 +4,10 @@
4
  * Description: The #1 Google Analytics alternative that gives you full control over your data and protects the privacy for your users. Free, secure and open.
5
  * Author: Matomo
6
  * Author URI: https://matomo.org
7
- * Version: 4.3.0
8
  * Domain Path: /languages
9
  * WC requires at least: 2.4.0
10
- * WC tested up to: 5.2.0
11
  *
12
  * Matomo - free/libre analytics platform
13
  *
@@ -15,7 +15,6 @@
15
  * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
16
  * @package matomo
17
  */
18
-
19
  if ( ! defined( 'ABSPATH' ) ) {
20
  exit; // if accessed directly
21
  }
4
  * Description: The #1 Google Analytics alternative that gives you full control over your data and protects the privacy for your users. Free, secure and open.
5
  * Author: Matomo
6
  * Author URI: https://matomo.org
7
+ * Version: 4.3.1
8
  * Domain Path: /languages
9
  * WC requires at least: 2.4.0
10
+ * WC tested up to: 5.5.0
11
  *
12
  * Matomo - free/libre analytics platform
13
  *
15
  * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
16
  * @package matomo
17
  */
 
18
  if ( ! defined( 'ABSPATH' ) ) {
19
  exit; // if accessed directly
20
  }
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: matomoteam
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=5EJ2LHATAKCJ4&source=url
4
  Tags: matomo,piwik,analytics,statistics,stats,tracking,ecommerce
5
  Requires at least: 4.8
6
- Tested up to: 5.7
7
- Stable tag: 4.3.0
8
  Requires PHP: 7.2.5
9
  License: GPLv3 or later
10
  License URI: https://www.gnu.org/licenses/gpl-3.0.html
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=5EJ2LHATAKCJ4&source=url
4
  Tags: matomo,piwik,analytics,statistics,stats,tracking,ecommerce
5
  Requires at least: 4.8
6
+ Tested up to: 5.8
7
+ Stable tag: 4.3.1
8
  Requires PHP: 7.2.5
9
  License: GPLv3 or later
10
  License URI: https://www.gnu.org/licenses/gpl-3.0.html