Wordpress版本3.4.2
这是最简单的插件形式,只有两个钩子:
register_activation_hook(__FILE__, sbv_activate());
register_deactivation_hook(__FILE__, sbv_deactivate());
function sbv_activate() {
add_option('sbv_opt1', 'test');
}
function sbv_deactivate() {
delete_option('sbv_opt1');
}
我在激活此插件后去检查选项表,似乎该选项不存在,如果我从去激活功能中删除delete_option()行,它将起作用。纠正我,如果我错了,似乎wordpress正在调用sbv_activate()然后调用sbv_deactivate(),从而撤消我在激活中所做的事情,我不认为它应该像这样。我对此感到很疯狂。
答案 0 :(得分:3)
您应该只使用函数的名称而不是函数本身:
register_activation_hook(__FILE__, 'sbv_activate');
register_deactivation_hook(__FILE__, 'sbv_deactivate');
WP Codex参考:http://codex.wordpress.org/Function_Reference/register_activation_hook