0

I'm currently developing a custom plugin. All works well on my local dev environment (Local by Flywheel), but, on production environment, I'm unable to activate the plugin. I get this error message:

Fatal error: Class 'Activate' not found in /datas/vol3/w4a156338/var/www/my-website/htdocs/wp-content/plugins/ads-toolbox/ads-toolbox.php on line 54

The 'ads-toolbox.php' file it the plugin main php file and it contains the following:

function activate_adstoolbox_plugin() {
    Inc\Base\Activate::activate();
}
register_activation_hook( __FILE__, 'activate_adstoolbox_plugin' );

Line 54 is: Inc\Base\Activate::activate();

The class 'Activate' is inside the 'Activate.php' file located in 'inc/Base/' subdirectory and contains:

namespace Inc\Base;

class Activate
{
    public static function activate()
    {
        //Some code
    }

}

I do not understand why it works locally but not on my hosted site!?

Any idea ?

  • Check the difference of your local environment and live...like php version etc – dado Jan 25 at 18:15
  • Can you show where the Activate.php file is being incorporated? – tmdesigned Jan 25 at 21:09
  • sounds like a paths issue on your production server. sometimes you have to tweak where files are being called from. – klewis Jan 26 at 1:54
  • What happens when you add include( __DIR__ . "/inc/Base/activate.php" ); on top of your master file ( ads-toolbox.php) to be sure that the class file is loaded? As mentioned by @klewis, be sure paths are correct. – Charles Jan 27 at 2:29
0

Thanks to @the_hobbes and @Charles, I realized that the file Activate.php was not incorporated. By adding require_once plugin_dir_path( __FILE__ ) . 'inc/Base/Activate.php'; to my code as shown below, it works correctly:

function activate_adstoolbox_plugin() {
    require_once plugin_dir_path( __FILE__ ) . 'inc/Base/Activate.php';
    Inc\Base\Activate::activate();
}
register_activation_hook( __FILE__, 'activate_adstoolbox_plugin' );

Oops! Newbie's error ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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