更新时间:2022-10-26 19:10:40
When activation occurs, your plugin is included from another function and then your myplugin_activate() is called from within that function (specifically, within the activate_plugin() function) at the point where your plugin is activated. The main body variables are therefore in the scope of the activate_plugin() function and are not global, unless you explicitly declare their global scope
See the rest of this note on variable scope: http://codex.wordpress.org/Function_Reference/register_activation_hook#A_Note_on_Variable_Scope