[wp-trac] [WordPress Trac] #6971: plugin variables not available as
global in register_activation_hook function
WordPress Trac
wp-trac at lists.automattic.com
Wed May 14 23:32:02 GMT 2008
#6971: plugin variables not available as global in register_activation_hook
function
---------------------+------------------------------------------------------
Reporter: spikyjt | Owner: anonymous
Type: defect | Status: new
Priority: normal | Milestone: 2.5.2
Component: General | Version: 2.5.1
Severity: normal | Keywords: register_activation_hook plugin global
---------------------+------------------------------------------------------
When the function called by register_activation_hook is requires variables
that are declared in the main code of a plugin, they are not available as
globals, however wordpress vars such as $wpdb are. For example:
{{{
$my_plugin_some_var = "foo";
register_activation_hook(__FILE__, 'my_install_func');
function my_install_func() {
global $wpdb; // wordpress var, this will be fine
global $my_plugin_some_var; // this will not work, the var will have to be
re-declared here
....
}
}}}
This is particularly frustrating for plugins that create tables in the
database and wish to store the table name in a variable for access in
other functions that access data in those tables.
--
Ticket URL: <http://trac.wordpress.org/ticket/6971>
WordPress Trac <http://trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list