WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 0 down vote accepted

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.

share|improve this answer
Worked perfectly. Good to know. Thanks! – cms09 Feb 23 '13 at 10:56

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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