PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 5.3.0
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v5.3.0
5.11.1 5.11.0 5.10.2 5.10.1 trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.3.2 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.1.3 4.10.0 4.11.0 4.12.0 4.13.0 4.13.2 4.13.3 4.13.4 4.13.5 4.14.0 4.14.1 4.14.2 4.15.0 4.15.1 4.15.2 4.15.3 4.2.0 4.3.0 4.3.1 4.4.1 4.4.2 4.5.0 4.6.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.10.0 5.2.0 5.2.1 5.2.2 5.3.0 5.3.1 5.3.2 5.3.3 5.6.0 5.6.1 5.7.0 5.7.1 5.8.0 5.8.1 5.8.2
matomo / app / bootstrap.php
matomo / app Last commit date
config 1 year ago core 1 year ago js 1 year ago lang 1 year ago libs 1 year ago node_modules 2 years ago plugins 1 year ago vendor 1 year ago .htaccess 6 years ago DIObject.php 2 years ago LEGALNOTICE 1 year ago LICENSE 2 years ago LegacyAutoloader.php 2 years ago PRIVACY.md 5 years ago README.md 1 year ago SECURITY.md 2 years ago bootstrap.php 1 year ago console 6 years ago favicon.ico 2 years ago index.php 2 years ago matomo.js 1 year ago matomo.php 2 years ago offline-service-worker.js 5 years ago piwik.js 1 year ago piwik.php 2 years ago robots.txt 5 years ago
bootstrap.php
267 lines
1 <?php
2
3 // if we're loading Matomo directly, rather than bootstrapping from within WordPress,
4 // try to set some INI config values Matomo needs
5 if ( ! defined( 'ABSPATH' ) ) {
6 @ini_set( 'zlib.output_compression', false );
7 }
8
9 // see plugins/WordPress/WordPress.php for more info
10 $GLOBALS['MATOMO_WP_ORIGINAL_ERROR_REPORTING'] = error_reporting();
11
12 $GLOBALS['CONFIG_INI_PATH_RESOLVER'] = function () {
13 if ( defined( 'ABSPATH' )
14 && defined( 'MATOMO_CONFIG_PATH' ) ) {
15 $paths = new \WpMatomo\Paths();
16
17 return $paths->get_config_ini_path();
18 }
19 };
20
21 $matomo_is_archive_request = !empty($_SERVER['argv'])
22 && is_array($_SERVER['argv'])
23 && in_array('climulti:request', $_SERVER['argv'], true);
24
25 if ( ! defined( 'PIWIK_ENABLE_ERROR_HANDLER' ) ) {
26 // we prefer using WP error handler... unless we are archiving where we want to prevent any warnings being printed
27 // as otherwise the archiving would be marked as failed because the cli archive output would contain a warning and
28 // the output would not be possible to do an unserialize anymore
29 if (!$matomo_is_archive_request) {
30 define( 'PIWIK_ENABLE_ERROR_HANDLER', false );
31 }
32 }
33
34 $GLOBALS['MATOMO_LOADED_DIRECTLY'] = ! defined( 'ABSPATH' );
35
36 if (!function_exists('matomo_ch_dir')) {
37 function matomo_ch_dir($file) {
38 if (function_exists('chdir') && is_dir(dirname($file))) {
39 @chdir(dirname($file));
40 }
41 }
42 }
43
44 if (!function_exists('matomo_log_message_no_display')) {
45 function matomo_log_message_no_display($message)
46 {
47 $message = 'Matomo ' . $message;
48
49 if ( defined( 'WP_DEBUG' ) && WP_DEBUG === true ) {
50 if (function_exists('ini_set') && function_exists('ini_get')) {
51 $value_orig = @ini_get('display_errors');
52 $value = @ini_set('display_errors', 'Off');
53 if (false !== $value) {
54 error_log( $message );
55 }
56 @ini_set('display_errors', $value_orig);
57 }
58 }
59
60 if (function_exists('update_option')
61 && class_exists('\WpMatomo\Logger')) {
62 // only if WordPress was bootstrapped by now... otherwise it will fail
63 try {
64 $logger = new \WpMatomo\Logger();
65 $logger->log_exception('archive_boot', new Exception($message));
66 } catch (Exception $e) {
67
68 }
69 }
70 }
71 }
72
73 if ( $GLOBALS['MATOMO_LOADED_DIRECTLY'] ) {
74
75 // prevent from loading twice
76 $matomo_wpload_base = '../../../../wp-load.php';
77 $matomo_wpload_full = dirname( dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) ) . '/wp-load.php';
78
79 if ($matomo_is_archive_request) {
80 ob_start();
81 // the matomo error handler will be only loaded after WordPress has been loaded... here we want to prevent
82 // any warning/notice from being shown while bootstrapping WordPress or otherwise the unserialize of the response
83 // later in climulti will fail
84 set_error_handler(function ($errno, $errstr, $errfile, $errline) {
85 // if the error has been suppressed by the @ we don't handle the error
86 if (error_reporting() == 0) {
87 return;
88 }
89
90 if (in_array($errno, array(E_ERROR, E_PARSE, E_CORE_ERROR, E_CORE_WARNING, E_COMPILE_ERROR, E_COMPILE_WARNING, E_USER_ERROR))) {
91 return false; //force standard behaviour
92 }
93
94 matomo_log_message_no_display( sprintf('error: %s: %s in %s:%s', $errno, $errstr, $errfile, $errline ) );
95 });
96 }
97
98 if (!empty($_SERVER['MATOMO_WP_ROOT_PATH']) && file_exists( rtrim($_SERVER['MATOMO_WP_ROOT_PATH'], '/') . '/wp-load.php')) {
99 $matomo_wp_root_file = rtrim($_SERVER['MATOMO_WP_ROOT_PATH'], '/') . '/wp-load.php';
100 matomo_ch_dir($matomo_wp_root_file);
101 require_once $matomo_wp_root_file;
102 } elseif (file_exists($matomo_wpload_full ) ) {
103 matomo_ch_dir($matomo_wpload_full);
104 require_once $matomo_wpload_full;
105 } elseif (realpath( $matomo_wpload_full ) && file_exists(realpath( $matomo_wpload_full ))) {
106 matomo_ch_dir(realpath( $matomo_wpload_full ));
107
108 require_once realpath( $matomo_wpload_full );
109 } elseif (!empty($_SERVER['SCRIPT_FILENAME']) && file_exists($_SERVER['SCRIPT_FILENAME'])) {
110 // seems symlinked... eg the wp-content dir or wp-content/plugins dir is symlinked from some very much other place...
111 $matomo_wpload_full = dirname($_SERVER['SCRIPT_FILENAME']) . '/' . $matomo_wpload_base;
112 if ( file_exists($matomo_wpload_full ) ) {
113 matomo_ch_dir($matomo_wpload_full);
114
115 require_once $matomo_wpload_full;
116 } elseif (realpath( $matomo_wpload_full ) && file_exists(realpath( $matomo_wpload_full ))) {
117 matomo_ch_dir(realpath( $matomo_wpload_full ));
118 require_once realpath( $matomo_wpload_full );
119 } elseif (file_exists(dirname(dirname(dirname(dirname(dirname( $_SERVER['SCRIPT_FILENAME'] ))))) . '/wp-load.php')) {
120 $matomo_relative_path = dirname(dirname(dirname(dirname(dirname( $_SERVER['SCRIPT_FILENAME'] ))))) . '/wp-load.php';
121
122 matomo_ch_dir($matomo_relative_path);
123 require_once $matomo_relative_path;
124 }
125 }
126
127 if (!defined( 'ABSPATH')) {
128 // still not loaded... look in plugins directory if there is a config file for us.
129 $matomo_wpload_config = dirname(__FILE__) . '/../../matomo.wpload_dir.php';
130 if (file_exists( $matomo_wpload_config) && is_readable($matomo_wpload_config)) {
131 $matomo_wpload_content = @file_get_contents($matomo_wpload_config); // we do not include that file for security reasons
132 if (!empty($matomo_wpload_content)) {
133 $matomo_wpload_content = str_replace(array('<?php', 'exit;', 'wp-load.php'), '', $matomo_wpload_content);
134 $matomo_wpload_content = preg_replace('/\s/', '', $matomo_wpload_content);
135 $matomo_wpload_content = trim(ltrim(trim($matomo_wpload_content), '#')); // the path may be commented out # /abs/path
136 if (strpos($matomo_wpload_content, DIRECTORY_SEPARATOR) === 0) {
137 $matomo_wpload_file = rtrim($matomo_wpload_content, DIRECTORY_SEPARATOR) . '/wp-load.php';
138 if (file_exists($matomo_wpload_file) && is_readable($matomo_wpload_file)) {
139 matomo_ch_dir($matomo_wpload_file);
140 require_once $matomo_wpload_file;
141 }
142 }
143 }
144 }
145 }
146
147 if ($matomo_is_archive_request) {
148 restore_error_handler();
149 if (ob_get_level()) {
150 $matomo_ob_end_clean_msg = @ob_get_clean();
151 if (!empty($matomo_ob_end_clean_msg)) {
152 matomo_log_message_no_display( $matomo_ob_end_clean_msg );
153 }
154 }
155 }
156 }
157
158 if ( ! defined( 'ABSPATH' ) ) {
159 echo 'Could not find wp-load. If your server uses symlinks or a custom content directory, Matomo may not work for you as we cannot detect the paths correctly. For more information see https://matomo.org/faq/wordpress/how-do-i-make-matomo-for-wordpress-work-when-i-have-a-custom-content-directory/';
160 if (!empty($_SERVER['MATOMO_WP_ROOT_PATH'])) {
161 echo ' Note: A custom WP root path was set.';
162 }
163 exit; // if accessed directly
164 }
165
166 if ( !is_plugin_active('matomo/matomo.php')
167 // during tests the plugin may temporarily not be active
168 && (!defined( 'MATOMO_PHPUNIT_TEST' ) || !MATOMO_PHPUNIT_TEST)
169 ) {
170 exit;
171 }
172
173 if ( $GLOBALS['MATOMO_LOADED_DIRECTLY'] ) {
174 // see https://github.com/matomo-org/matomo-for-wordpress/issues/190
175 // wp-external-links plugin would register an ob_start(function () {...}) and manipulate any of our API output
176 // and in some cases the output would get completely lost causing blank pages.
177 add_filter('wpel_apply_settings', '__return_false', 99999);
178
179 // do not strip slashes if we bootstrap matomo within a regular wordpress request
180 if (!empty($_GET)) {
181 $_GET = stripslashes_deep( $_GET );
182 }
183 if (!empty($_POST)) {
184 $_POST = stripslashes_deep( $_POST );
185 }
186 if (!empty($_COOKIE)) {
187 $_COOKIE = stripslashes_deep( $_COOKIE );
188 }
189 if (!empty($_SERVER)) {
190 $_SERVER = stripslashes_deep( $_SERVER );
191 }
192 if (!empty($_REQUEST)) {
193 $_REQUEST = stripslashes_deep( $_REQUEST );
194 }
195 }
196
197
198 if ( matomo_is_app_request() ) {
199 // pretend we are in the admin... potentially avoiding caching etc
200 $GLOBALS['hook_suffix'] = '';
201 include_once ABSPATH . '/wp-admin/includes/class-wp-screen.php';
202 $GLOBALS['current_screen'] = WP_Screen::get();
203
204 // we disable jsonp
205 unset($_GET['jsoncallback']);
206 unset($_GET['callback']);
207 unset($_POST['jsoncallback']);
208 unset($_POST['callback']);
209 }
210
211 if ( ! defined( 'PIWIK_USER_PATH' ) ) {
212 define( 'PIWIK_USER_PATH', dirname( MATOMO_ANALYTICS_FILE ) );
213 }
214
215 if (function_exists('wp_raise_memory_limit') && function_exists('wp_convert_hr_to_bytes')) {
216 $current_limit = ini_get( 'memory_limit' );
217 $current_limit_int = wp_convert_hr_to_bytes( $current_limit );
218 $memory128MbInt = 134217728;
219 if ($current_limit_int && $current_limit_int > 0 && $current_limit_int < $memory128MbInt) {
220 // we try increase memory if memory is less than 128mb
221 wp_raise_memory_limit('admin');
222 }
223 }
224
225 $GLOBALS['MATOMO_MODIFY_CONFIG_SETTINGS'] = function ($settings) {
226 $plugins = $settings['Plugins'];
227 if (is_array($settings['Plugins'])) {
228 $pluginsToRemove = array('Marketplace', 'MultiSites', 'TwoFactorAuth', 'Widgetize', 'Feedback', 'ExamplePlugin', 'ExampleAPI', 'ProfessionalServices', 'MobileAppMeasurable', 'CustomPiwikJs');
229 foreach ($pluginsToRemove as $pluginToRemove) {
230 // Marketplace => this is instead done in wordpress
231 // MultiSites => doesn't really make sense since we have only one website per installation
232 // TwoFactorAuth => not needed as login is being handled by WordPress
233 // widgetize for now we don't want to allow widgetizing as it is based on the token_auth authentication
234 // Monolog => we use our own logger
235 // ProfessionalServices => we advertise in the WP plugin itself instead
236 // feedback => we want to hide things like Need help in the admin etc
237 // MobileAppMeasurable => for WP mobile apps are not a thing
238 // custom variables we don't want to enable as we will deprecate them in Matomo 4 anyway => used to be disabled but we need to make sure the columns get installed otherwise matomo has issues... need to wait to matomo 4 to remove it
239 $pos = array_search($pluginToRemove, $plugins['Plugins']);
240 if ($pos !== false) {
241 array_splice($plugins['Plugins'], $pos, 1);
242 }
243 }
244 if (matomo_has_tag_manager()) {
245 $plugins['Plugins'][] = 'TagManager';
246 }
247 $mustEnable = ['BulkTracking', 'CustomJsTracker'];
248 foreach ($mustEnable as $enable) {
249 if (!in_array($enable, $plugins['Plugins'])) {
250 $plugins['Plugins'][] = $enable;
251 }
252 }
253 }
254 if (!empty($GLOBALS['MATOMO_PLUGINS_ENABLED'])) {
255 foreach ($GLOBALS['MATOMO_PLUGINS_ENABLED'] as $plugin) {
256 if (!in_array($plugin, $plugins['Plugins'])) {
257 $plugins['Plugins'][] = $plugin;
258 }
259 }
260 }
261 if (!empty($GLOBALS['MATOMO_MARKETPLACE_PLUGINS'])) {
262 matomo_filter_incompatible_plugins($plugins['Plugins']);
263 }
264 $settings['Plugins'] = $plugins;
265 return $settings;
266 };
267