[wp-hackers] register_activation_hook is acting funny

Scott Kingsley Clark scott at skcdev.com
Sat Aug 7 03:11:04 UTC 2010


Maybe it's my code, or maybe something else is going on. I'm thinking 
something else is going on. Let me explain how my activation function 
works (code located in the plugin):

register_activation_hook(__FILE__,'my_activate');
function my_activate()
{
     $myfile_contents = file_get_contents(dirname(__FILE__).'/myfile.txt');
     update_option('my_option',$myfile_contents);
}

Now, first of all, if I remove that file_get_contents() and put the 
string directly into the $myfile_contents variable, all is well.

However, the second that file_get_contents() is added, I get a massive 
dump on my face:

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

Fatal error: Cannot redeclare my_menu() (previously declared in 
/home/path/to/my/site/wp-content/plugins/my-plugin/my-plugin.php:16) in 
/home/path/to/my/site/wp-content/plugins/my-plugin/my-plugin.php on line 26

This is weird, as the activation is happening, it seems to some how be 
tripping the activation when it gets another file (whether using include 
or file_get_contents) and includes my plugin TWICE (or it seems to 
apparently from the error), so pretty stumped on this one.

Has anyone experienced an issue like this before?


Best Regards,

Scott Kingsley Clark
Developer / Consultant
SKC Development, LLC

------------------------------------
E-mail: scott at skcdev.com
Website: http://skcdev.com/
Phone: 214.233.4048
Fax: 214.260.1426

AIM / Yahoo / Skype: sc0ttkclark
Google Talk: sc0ttkclark at gmail.com
------------------------------------




More information about the wp-hackers mailing list