1

This seems like a very unusual behavior: Usually, when activating a plugin, a path to the plugin's main file (or bootstrap) is stored in the database under options.active_plugins. However, something in the following code is causing Wordpress to store the object itself, rather than a path to it, in the database.

Here is the plugin's bootstrap file (bootstrap.php):

/**
 * Plugin metadata
 */

require_once( plugin_dir_path( __FILE__ ) . 'MyPlugin.php' );

$plugin = new MyPlugin();
$plugin->init();

After activation, the active_plugins option entry will look like this (retrieved using get_option( 'active_plugins' ):

Array {
    [0] => (object) MyPlugin
}

When the expected result would be:

Array {
    [0] => bootstrap.php
}
2

You should just not add code outside of actions (callbacks attached to hooks and filters). Else your variables might conflict with global variables. The default/first action for a plugin bootstrap would be (depending on the type of plugin): plugins_loaded or muplugins_loaded.

Attach hooks from there on to wp_loaded if you want stuff to run on init (but make it multisite save - init has other drawbacks as well).

|improve this answer|||||
-1

It turns out that using a variable named $plugin as a part of the plugin's bootstrap process is causing Wordpress to store that variable's contents, rather than containing the file's path. To fix the issue, simply use a different variable name:

/**
 * Plugin metadata
 */

require_once( plugin_dir_path( __FILE__ ) . 'MyPlugin.php' );

$plugin_starter = new MyPlugin();
$plugin_starter->init();
|improve this answer|||||

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.