admin管理员组文章数量:1290521
I am learning plugin dev and modified this example snippet. I don't get why $myvar is empty in the my_plugin_action_handler function's scope.
<?php
/**
* Plugin Name: TEST Plugin
*/
global $myvar;
$myvar = false;
function myplugin_activate() {
global $myvar;
$myvar = true;
error_log($myvar); // this will be 'whatever'
}
function my_plugin_action_handler(){
global $myvar;
if($myvar){
error_log("Var true");
}
}
register_activation_hook( __FILE__, 'myplugin_activate' );
add_action('admin_notices', 'my_plugin_action_handler');
本文标签: pluginsSet and access global variable
版权声明:本文标题:plugins - Set and access global variable 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741499933a2382009.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论