[wp-hackers] Hook being called twice on activate, once on deactivate

Otto otto at ottodestruct.com
Thu Oct 29 19:42:39 UTC 2009


I can't explain why you're having it run twice or whatever, but the
reason you lose the prefix is simple. Your $wpdb is not in scope at
the initial activation point.

When you first get activated, your plugin is included from inside the
activate_plugin function, meaning that you're not in global scope for
that one run, you're in the function scope.

When you get included from then on, in the normal load-everything
sequence, your plugin gets included from the main path, inside
wp-settings.php.

$wpdb won't be defined in the function scope, unless you global it first.

Which just goes to show: If you want a global variable, then *always*
say so. Never assume scope.


-Otto


More information about the wp-hackers mailing list