0

In the WordPress dashboard, it said there was an update for the Google Analytics plugin. I clicked to have it update, which seemed to succeed. After doing this, I tried updating another plugin and got an error (see below). I then tried viewing the site (dashboard or otherwise), and everything gets the same error with no page displayed:

Invalid plugin installation directory. Please verify if the plugin's dir name is equal to "googleanalytics".

In other words, the site is now down because of updating Google Analytics in the WordPress dashboard. How is the above error to be resolved?

Update 1: Upon searching the server for changed files, I found that the code generating this error is in /wp-content/plugins/googleanalytics/googleanalytics.php. I modified the code to display (for my IP) the path being compared against. Curiously, it would appear the code is searching the string [omitted]\wp-content\plugins\googleanalytics\googleanalytics.php for the pattern /\/googleanalytics\// using the preg_match() function. The function is returning false.

Update 2: The source code (of the latest version) can be found here. It seems that the previous version did not have this path check.

1

If you rename the plugins folder googleanalytics into something else, e.g. OLDgoogleanalytics then refresh your website, the error is gone. Now you can access your backend plugins page (optional: rename the folder OLDgoogleanalytics back to googleanalytics) and you can see that trying to enable the Google Analytics plugin gives the error you mentioned.

I temporarily fixed the error by commenting this piece of code.

if ( ! preg_match( '/\/' . GA_NAME . '\//', realpath( __FILE__ ), $test ) ) {

echo _( 'Invalid plugin installation directory. Please verify if the plugin\'s dir name is equal to "' . GA_NAME . '".' );

// To make able the message above to be displayed in the activation error notice.
die();
}
  • While I agree that commenting out the whole check statement could resolve this particular issue in this case, I feel it is probably safer instead to modify the string search to use the correct type of slashes for the path. This way, technically the check is still being performed. I have posted an answer showing how to do this. I would be curious if my solution works in your case. – Michael Feb 7 '17 at 9:18
  • For completeness, do you know if your server is running IIS (on Windows)? – Michael Feb 7 '17 at 9:29
  • Yes your proposed solution works in my case. I am using Apache on Windows. – MDT Feb 7 '17 at 10:53
1

It would appear the issue is a bug created by the plugin developers. They apparently did not test version 2.1 of the plugin on a server running IIS. The string search they perform assumes the directory path of the plugin uses forward slashes /, but on IIS the path uses backslashes \. To resolve this issue, you may replace realpath( __FILE__ ) with str_replace('\\', '/', realpath( __FILE__ )) on line 42 of googleanalytics.php. The resulting line is thus:

if ( ! preg_match( '/\/' . GA_NAME . '\//', str_replace('\\', '/', realpath( __FILE__ )), $test ) ) {

Not the answer you're looking for? Browse other questions tagged or ask your own question.