diff --git a/CHANGELOG.md b/CHANGELOG.md
index 321404034..82fbe1715 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,6 @@
+0.2.11
+- Better support when a WordPress directory is symlinked
+
0.2.10
- Improvements for the system report
- Apache htaccess change fixing HTML were not loaded on some installs
diff --git a/app/bootstrap.php b/app/bootstrap.php
index 62720c324..b8c7b4437 100644
--- a/app/bootstrap.php
+++ b/app/bootstrap.php
@@ -12,14 +12,34 @@
define( 'PIWIK_ENABLE_ERROR_HANDLER', false );
}
-$was_loaded_directly = ! defined( 'ABSPATH' );
+$matomo_was_wp_loaded_directly = ! defined( 'ABSPATH' );
-if ( $was_loaded_directly ) {
+if ( $matomo_was_wp_loaded_directly ) {
// prevent from loading twice
- require_once( dirname( __FILE__ ) . '/../../../../wp-load.php' );
+ $matomo_wpload_base = '../../../../wp-load.php';
+ $matomo_wpload_full = dirname( __FILE__ ) . '/' . $matomo_wpload_base;
+
+ if (!empty($_ENV['MATOMO_WP_ROOT_PATH']) && file_exists( rtrim($_ENV['MATOMO_WP_ROOT_PATH'], '/') . '/wp-load.php')) {
+ require_once rtrim($_ENV['MATOMO_WP_ROOT_PATH'], '/') . '/wp-load.php';
+ } elseif ( file_exists($matomo_wpload_full ) ) {
+ require_once $matomo_wpload_full;
+ } elseif (realpath( $matomo_wpload_full ) && file_exists(realpath( $matomo_wpload_full ))) {
+ require_once realpath( $matomo_wpload_full );
+ } elseif (!empty($_SERVER['SCRIPT_FILENAME']) && file_exists($_SERVER['SCRIPT_FILENAME'])) {
+ // seems symlinked... eg the wp-content dir or wp-content/plugins dir is symlinked from some very much other place...
+ $matomo_wpload_full = dirname($_SERVER['SCRIPT_FILENAME']) . '/' . $matomo_wpload_base;
+ if ( file_exists($matomo_wpload_full ) ) {
+ require_once $matomo_wpload_full;
+ } elseif (realpath( $matomo_wpload_full ) && file_exists(realpath( $matomo_wpload_full ))) {
+ require_once realpath( $matomo_wpload_full );
+ } elseif (file_exists(dirname(dirname(dirname(dirname(dirname( $_SERVER['SCRIPT_FILENAME'] ))))) . '/wp-load.php')) {
+ require_once dirname(dirname(dirname(dirname(dirname( $_SERVER['SCRIPT_FILENAME'] ))))) . '/wp-load.php';
+ }
+ }
}
if ( ! defined( 'ABSPATH' ) ) {
+ 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/';
exit; // if accessed directly
}
@@ -29,7 +49,7 @@
exit;
}
-if ($was_loaded_directly) {
+if ($matomo_was_wp_loaded_directly) {
// do not strip slashes if we bootstrap matomo within a regular wordpress request
if (!empty($_GET)) {
$_GET = stripslashes_deep( $_GET );
diff --git a/classes/WpMatomo.php b/classes/WpMatomo.php
index be5800bc1..ec7708604 100644
--- a/classes/WpMatomo.php
+++ b/classes/WpMatomo.php
@@ -144,7 +144,7 @@ function () {
add_action(
'admin_notices',
function () {
- echo '
' . __( 'It looks like you are maybe using a custom WordPress content directory. The Matomo Analytics plugin likely won\'t fully work.', 'matomo' ) . '
';
+ echo '' . __( 'It looks like you are maybe using a custom WordPress content directory. The Matomo reporting/admin pages might not work. You may be able to workaround this.', 'matomo' ) . ' '. esc_html__('Learn more', 'matomo').'.
';
}
);
}
diff --git a/classes/WpMatomo/Admin/SystemReport.php b/classes/WpMatomo/Admin/SystemReport.php
index 8724f4d69..fc26a3e49 100644
--- a/classes/WpMatomo/Admin/SystemReport.php
+++ b/classes/WpMatomo/Admin/SystemReport.php
@@ -240,6 +240,22 @@ private function get_matomo_info() {
'comment' => $tmp_dir,
);
+ if ( ! empty( $_ENV['MATOMO_WP_ROOT_PATH'] ) ) {
+ $custom_path = rtrim($_ENV['MATOMO_WP_ROOT_PATH'], '/') . '/wp-load.php';
+ $path_exists = file_exists($custom_path );
+ $comment = '';
+ if (!$path_exists) {
+ $comment = 'It seems the path does not point to the WP root directory.';
+ }
+
+ $rows[] = array(
+ 'name' => 'Custom MATOMO_WP_ROOT_PATH',
+ 'value' => $path_exists,
+ 'is_error' => ! $path_exists,
+ 'comment' => $comment,
+ );
+ }
+
if ( ! \WpMatomo::is_safe_mode() ) {
try {
Bootstrap::do_bootstrap();
diff --git a/matomo.php b/matomo.php
index 716fd8522..6c48ff50a 100644
--- a/matomo.php
+++ b/matomo.php
@@ -4,7 +4,7 @@
* Description: Most powerful web analytics for WordPress giving you 100% data ownership and privacy protection
* Author: Matomo
* Author URI: https://matomo.org
- * Version: 0.2.10
+ * Version: 0.2.11
* Domain Path: /languages
* WC requires at least: 2.4.0
* WC tested up to: 3.2.6
@@ -36,7 +36,9 @@
$GLOBALS['MATOMO_PLUGIN_FILES'] = array( MATOMO_ANALYTICS_FILE );
function matomo_has_compatible_content_dir() {
- return defined( 'WP_CONTENT_DIR' ) && ABSPATH . 'wp-content' === rtrim( WP_CONTENT_DIR, '/' );
+ return (defined( 'WP_CONTENT_DIR' )
+ && ABSPATH . 'wp-content' === rtrim( WP_CONTENT_DIR, '/' ))
+ || ( !empty( $_ENV['MATOMO_WP_ROOT_PATH'] ) && is_dir( $_ENV['MATOMO_WP_ROOT_PATH'] ) );
}
function matomo_is_app_request() {
diff --git a/plugins/WordPress/Commands/GenerateCoreAssets.php b/plugins/WordPress/Commands/GenerateCoreAssets.php
index 54b668ca1..45dc08ec9 100644
--- a/plugins/WordPress/Commands/GenerateCoreAssets.php
+++ b/plugins/WordPress/Commands/GenerateCoreAssets.php
@@ -19,6 +19,10 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
+if (!defined( 'ABSPATH')) {
+ exit; // if accessed directly
+}
+
class GenerateCoreAssets extends ConsoleCommand
{
protected function configure()
diff --git a/plugins/WordPress/Controller.php b/plugins/WordPress/Controller.php
index 47b503e08..3d0e3d1a8 100644
--- a/plugins/WordPress/Controller.php
+++ b/plugins/WordPress/Controller.php
@@ -9,8 +9,9 @@
namespace Piwik\Plugins\WordPress;
-use Piwik\Common;
-use Piwik\Piwik;
+if (!defined( 'ABSPATH')) {
+ exit; // if accessed directly
+}
class Controller extends \Piwik\Plugin\Controller
{
diff --git a/plugins/WordPress/WordPress.php b/plugins/WordPress/WordPress.php
index 75861f9bb..51c46f498 100644
--- a/plugins/WordPress/WordPress.php
+++ b/plugins/WordPress/WordPress.php
@@ -11,24 +11,14 @@
use Exception;
use Piwik\API\Request;
-use Piwik\AuthResult;
use Piwik\Common;
-use Piwik\Container\StaticContainer;
use Piwik\FrontController;
-use Piwik\Piwik;
use Piwik\Plugin;
use Piwik\Plugins\CoreHome\SystemSummary\Item;
use Piwik\Scheduler\Task;
use Piwik\Url;
-use Piwik\View;
use Piwik\Widget\WidgetsList;
-use WpMatomo\Access;
-use WpMatomo\Admin\TrackingSettings;
-use WpMatomo\API;
use WpMatomo\Bootstrap;
-use WpMatomo\Settings;
-use WpMatomo\Site;
-use WpMatomo\User;
if (!defined( 'ABSPATH')) {
exit; // if accessed directly