0

I've been putting together a simple WordPress plugin that employs a sidebar widget and shortcode. One user has reported the following error when trying to activate the plugin on their local WP installation:

Plugin could not be activated because it triggered a fatal error.

Fatal error: Class 'Example_Widget' not found in /Applications/MAMP/htdocs/wordpress/wp-content/plugins/exampleplugin/exampleplugin.php on line 30

Here's the code in exampleplugin.php, beginning with line 29:

$example_plugin = new Example_Plugin;
$example_widget = new Example_Widget;

class Example_Plugin {
    ...
}

I'm fairly new to OOP in PHP, and can't figure out what's causing a fatal error for this user. The plugin works fine for me, making this all the more mysterious.

1 Answer 1

0

You should not need to instantiate the widget class at the top of your code, because of the register_widget function hooked from your main class does that work for you.

EDIT: Wordpress already instantiates your class.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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