PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 1.0.2
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v1.0.2
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 6 years ago core 6 years ago js 6 years ago lang 6 years ago libs 6 years ago plugins 6 years ago vendor 6 years ago .htaccess 6 years ago LEGALNOTICE 6 years ago LICENSE 6 years ago PRIVACY.md 6 years ago README.md 6 years ago SECURITY.md 6 years ago bootstrap.php 6 years ago console 6 years ago favicon.ico 6 years ago index.php 6 years ago matomo.js 6 years ago matomo.php 6 years ago piwik.js 6 years ago piwik.php 6 years ago robots.txt 6 years ago
bootstrap.php
203 lines
1 <?php
2
3 $GLOBALS['CONFIG_INI_PATH_RESOLVER'] = function () {
4 if ( defined( 'ABSPATH' )
5 && defined( 'MATOMO_CONFIG_PATH' ) ) {
6 $paths = new \WpMatomo\Paths();
7
8 return $paths->get_config_ini_path();
9 }
10 };
11
12 $matomo_is_archive_request = !empty($_SERVER['argv'])
13 && is_array($_SERVER['argv'])
14 && in_array('climulti:request', $_SERVER['argv'], true);
15
16 if ( ! defined( 'PIWIK_ENABLE_ERROR_HANDLER' ) ) {
17 // we prefer using WP error handler... unless we are archiving where we want to prevent any warnings being printed
18 // as otherwise the archiving would be marked as failed because the cli archive output would contain a warning and
19 // the output would not be possible to do an unserialize anymore
20 if (!$matomo_is_archive_request) {
21 define( 'PIWIK_ENABLE_ERROR_HANDLER', false );
22 }
23 }
24
25 $matomo_was_wp_loaded_directly = ! defined( 'ABSPATH' );
26
27
28 function matomo_log_message_no_display($message)
29 {
30 $message = 'Matomo ' . $message;
31
32 if ( defined( 'WP_DEBUG' ) && WP_DEBUG === true ) {
33 if (function_exists('ini_set') && function_exists('ini_get')) {
34 $value_orig = @ini_get('display_errors');
35 $value = @ini_set('display_errors', 'Off');
36 if (false !== $value) {
37 error_log( $message );
38 }
39 @ini_set('display_errors', $value_orig);
40 }
41 }
42
43 if (function_exists('update_option')
44 && class_exists('\WpMatomo\Logger')) {
45 // only if WordPress was bootstrapped by now... otherwise it will fail
46 try {
47 $logger = new \WpMatomo\Logger();
48 $logger->log_exception('archive_boot', new Exception($message));
49 } catch (Exception $e) {
50
51 }
52 }
53 }
54
55 if ( $matomo_was_wp_loaded_directly ) {
56 // prevent from loading twice
57 $matomo_wpload_base = '../../../../wp-load.php';
58 $matomo_wpload_full = dirname( __FILE__ ) . '/' . $matomo_wpload_base;
59
60 if ($matomo_is_archive_request) {
61 ob_start();
62 // the matomo error handler will be only loaded after WordPress has been loaded... here we want to prevent
63 // any warning/notice from being shown while bootstrapping WordPress or otherwise the unserialize of the response
64 // later in climulti will fail
65 set_error_handler(function ($errno, $errstr, $errfile, $errline) {
66 // if the error has been suppressed by the @ we don't handle the error
67 if (error_reporting() == 0) {
68 return;
69 }
70
71 if (in_array($errno, array(E_ERROR, E_PARSE, E_CORE_ERROR, E_CORE_WARNING, E_COMPILE_ERROR, E_COMPILE_WARNING, E_USER_ERROR))) {
72 return false; //force standard behaviour
73 }
74
75 matomo_log_message_no_display( sprintf('error: %s: %s in %s:%s', $errno, $errstr, $errfile, $errline ) );
76 });
77 }
78
79 if (!empty($_ENV['MATOMO_WP_ROOT_PATH']) && file_exists( rtrim($_ENV['MATOMO_WP_ROOT_PATH'], '/') . '/wp-load.php')) {
80 require_once rtrim($_ENV['MATOMO_WP_ROOT_PATH'], '/') . '/wp-load.php';
81 } elseif ( file_exists($matomo_wpload_full ) ) {
82 require_once $matomo_wpload_full;
83 } elseif (realpath( $matomo_wpload_full ) && file_exists(realpath( $matomo_wpload_full ))) {
84 require_once realpath( $matomo_wpload_full );
85 } elseif (!empty($_SERVER['SCRIPT_FILENAME']) && file_exists($_SERVER['SCRIPT_FILENAME'])) {
86 // seems symlinked... eg the wp-content dir or wp-content/plugins dir is symlinked from some very much other place...
87 $matomo_wpload_full = dirname($_SERVER['SCRIPT_FILENAME']) . '/' . $matomo_wpload_base;
88 if ( file_exists($matomo_wpload_full ) ) {
89 require_once $matomo_wpload_full;
90 } elseif (realpath( $matomo_wpload_full ) && file_exists(realpath( $matomo_wpload_full ))) {
91 require_once realpath( $matomo_wpload_full );
92 } elseif (file_exists(dirname(dirname(dirname(dirname(dirname( $_SERVER['SCRIPT_FILENAME'] ))))) . '/wp-load.php')) {
93 require_once dirname(dirname(dirname(dirname(dirname( $_SERVER['SCRIPT_FILENAME'] ))))) . '/wp-load.php';
94 }
95 }
96
97 if ($matomo_is_archive_request) {
98 restore_error_handler();
99 if (ob_get_level()) {
100 $matomo_ob_end_clean_msg = @ob_get_clean();
101 if (!empty($matomo_ob_end_clean_msg)) {
102 matomo_log_message_no_display( $matomo_ob_end_clean_msg );
103 }
104 }
105 }
106 }
107
108 if ( ! defined( 'ABSPATH' ) ) {
109 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/what-are-the-requirements-for-matomo-for-wordpress/';
110 exit; // if accessed directly
111 }
112
113 if ( !is_plugin_active('matomo/matomo.php')
114 && (!defined( 'MATOMO_PHPUNIT_TEST' ) || !MATOMO_PHPUNIT_TEST) ) { // during tests the plugin may temporarily not be active
115 exit;
116 }
117
118 if ($matomo_was_wp_loaded_directly) {
119 // see https://github.com/matomo-org/wp-matomo/issues/190
120 // wp-external-links plugin would register an ob_start(function () {...}) and manipulate any of our API output
121 // and in some cases the output would get completely lost causing blank pages.
122 add_filter('wpel_apply_settings', '__return_false', 99999);
123
124 // do not strip slashes if we bootstrap matomo within a regular wordpress request
125 if (!empty($_GET)) {
126 $_GET = stripslashes_deep( $_GET );
127 }
128 if (!empty($_POST)) {
129 $_POST = stripslashes_deep( $_POST );
130 }
131 if (!empty($_COOKIE)) {
132 $_COOKIE = stripslashes_deep( $_COOKIE );
133 }
134 if (!empty($_SERVER)) {
135 $_SERVER = stripslashes_deep( $_SERVER );
136 }
137 if (!empty($_REQUEST)) {
138 $_REQUEST = stripslashes_deep( $_REQUEST );
139 }
140 }
141
142
143 if ( matomo_is_app_request() ) {
144 // pretend we are in the admin... potentially avoiding caching etc
145 $GLOBALS['hook_suffix'] = '';
146 include_once ABSPATH . '/wp-admin/includes/class-wp-screen.php';
147 $GLOBALS['current_screen'] = WP_Screen::get();
148
149 // we disable jsonp
150 unset($_GET['jsoncallback']);
151 unset($_GET['callback']);
152 unset($_POST['jsoncallback']);
153 unset($_POST['callback']);
154 }
155
156 if ( ! defined( 'PIWIK_USER_PATH' ) ) {
157 define( 'PIWIK_USER_PATH', dirname( MATOMO_ANALYTICS_FILE ) );
158 }
159
160 if (function_exists('wp_raise_memory_limit') && function_exists('wp_convert_hr_to_bytes')) {
161 $current_limit = ini_get( 'memory_limit' );
162 $current_limit_int = wp_convert_hr_to_bytes( $current_limit );
163 $memory128MbInt = 134217728;
164 if ($current_limit_int && $current_limit_int > 0 && $current_limit_int < $memory128MbInt) {
165 // we try increase memory if memory is less than 128mb
166 wp_raise_memory_limit('admin');
167 }
168 }
169
170 $GLOBALS['MATOMO_MODIFY_CONFIG_SETTINGS'] = function ($settings) {
171 $plugins = $settings['Plugins'];
172 if (is_array($settings['Plugins'])) {
173 $pluginsToRemove = array('Marketplace', 'MultiSites', 'TwoFactorAuth', 'Widgetize', 'Monolog', 'Feedback', 'ExamplePlugin', 'ExampleAPI', 'ProfessionalServices', 'MobileAppMeasurable');
174 foreach ($pluginsToRemove as $pluginToRemove) {
175 // Marketplace => this is instead done in wordpress
176 // MultiSites => doesn't really make sense since we have only one website per installation
177 // TwoFactorAuth => not needed as login is being handled by WordPress
178 // widgetize for now we don't want to allow widgetizing as it is based on the token_auth authentication
179 // Monolog => we use our own logger
180 // ProfessionalServices => we advertise in the WP plugin itself instead
181 // feedback => we want to hide things like Need help in the admin etc
182 // MobileAppMeasurable => for WP mobile apps are not a thing
183 // 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
184 $pos = array_search($pluginToRemove, $plugins['Plugins']);
185 if ($pos !== false) {
186 array_splice($plugins['Plugins'], $pos, 1);
187 }
188 }
189 if (matomo_has_tag_manager()) {
190 $plugins['Plugins'][] = 'TagManager';
191 }
192 }
193 if (!empty($GLOBALS['MATOMO_PLUGINS_ENABLED'])) {
194 foreach ($GLOBALS['MATOMO_PLUGINS_ENABLED'] as $plugin) {
195 if (!in_array($plugin, $plugins['Plugins'])) {
196 $plugins['Plugins'][] = $plugin;
197 }
198 }
199 }
200 $settings['Plugins'] = $plugins;
201 return $settings;
202 };
203