Hi,
I'm writing my first wordpress plugin and I'm trying to create a function to be called when the plugin is activated.
Currently it looks like this:
class ThumbsUp {
...
}
global $thumbs;
function thumbs_install() {
//global $thumbs;
$thumbs = new ThumbsUp(); /* Line 160 */
$thumbs->installThumbsUp();
} /* Line 162 */
// When plugin is activated -> install.
register_activation_hook(__FILE__,'thumbs_install');
But when I activate the plugin I get the following error:
Plugin could not be activated because it triggered a fatal error.
Fatal error: Cannot redeclare thumbs_install() (previously declared in /dev/site/wp-content/plugins/thumbs-up/thumbs-up.php:160) in /dev/site/wp-content/plugins/thumbs-up/thumbs-up.php on line 162
I've googled and looked and it's talked about as a variable scope issue but I can't find any examples of the answer and my php is not strong enough to translate the discussion into code.
Here's the solution described:
Any global variables that you want to reference inside the function
that is called by register_activation_hook() must be explicitly
declared as global inside the main body of the plugin (ie. _outside_
of this function). The plugin file is include()-ed inside another
function at the point where it is activated unlike at others times
when the plugin file is simply include()-ed. Phew. Bit of an odd one
to get your head around but there we go.
I thought I had done what is described but I still get the error. I've also tried every other combination of where I could possibly put the global $thumbs..
Any ideas?
Thanks