microsoft / ApplicationInsights-WordPress

Main development repository for Application Insights WordPress plugin.
MIT License
45 stars 42 forks source link

500 error: Class 'ApplicationInsights\WordPress\Settings' not found #21

Open maxleistner opened 6 years ago

maxleistner commented 6 years ago

I get the following error after activating the plugin:

Class 'ApplicationInsights\WordPress\Settings' not found on Line 13

 3:    Plugin Name: Application Insights
 4:    Description: Integrates a WordPress site with Microsoft Application Insights.
 5:    Version: 2.3
 6:    Author: ApplicationInsights
 7:    License:  MIT
 8:     */
 9:    
10:    require_once 'vendor/autoload.php';
11:    
12:    // Enables Admin configuration experience
13:    $mySettingsPage = new ApplicationInsights\WordPress\Settings();
14:    
15:    // Enables client-side instrumentation
16:    $clientInstrumentation = new ApplicationInsights\WordPress\Client_Instrumentation();
17:    add_action('wp_head', array($clientInstrumentation, 'addPrefix'));

WordPress 4.9.1 PHP 7.2.10-0ubuntu0.18.04.1 Apache/2.4.29 (Ubuntu)

maxleistner commented 6 years ago

I found the problem :) We have a vendor folder in our system, because we do as well have several dependencies. As require_once 'vendor/autoload.php'; loads the autoloader file relative to the file which calls the require, it searches in our vendor folder. Therefore you should change the call to a more save function, which looks for the file in the right folder ;)

atjensw commented 6 years ago

I have the same issue.

dulfe commented 6 years ago

I had the same problem... in my case only appeared when using OpCache... this fixed the issue.

Change

require_once 'vendor/autoload.php';

to

require_once __DIR__ . '/vendor/autoload.php';

in ApplicationInsightsPlugin.php

I have sent a PR request with that fix (and some other code) yesterday.... you are welcome to test it :)

Hope it helps.