WordPress 插件开发
<?php
/*
* Plugin Name: test
* Plugin URI: www.test.com
* Version: 1.0
* Author: J Davies
* Author URI: test.com
* Description: Random Test
*/
function say_test(){
$greeting = get_option('test_greeting');
print "Say ".$greeting;
}
function set_test_options(){
add_option('test_greeting','test','test');
}
function unset_test_options(){
delete_option('test_greeting');
}
register_activation_hook(__FILE__,'set_test_options');
register_deactivation_hook(__FILE__,'unset_test_options');
?>
I am using this website http://wpbits.wordpress.com/2007/08/15/adding-options-to-wordpress-plugins/,to help me workout how to make a plugin that saves options.
Here is my code, but it wont seem to work. Can anyone point me in right direction please:
<?php
/*
* Plugin Name: test
* Plugin URI: www.test.com
* Version: 1.0
* Author: J Davies
* Author URI: test.com
* Description: Random Test
*/
function say_test(){
$greeting = get_option('test_greeting');
print "Say ".$greeting;
}
function set_test_options(){
add_option('test_greeting','test','test');
}
function unset_test_options(){
delete_option('test_greeting');
}
register_activation_hook(__FILE__,'set_test_options');
register_deactivation_hook(__FILE__,'unset_test_options');
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我发现了问题,我需要将每个函数包装在 if(function_exists()) 中。
谢谢
I have found the problem, I needed to wrap each function in if(function_exists()).
Thanks
我在这里看到的唯一奇怪的事情是
add_option()
应该只接受两个或四个参数(第三个参数为空)。设置第三个会导致 Wordpress 运行其_deprecated_argument()
函数,如果处于调试模式,该函数将触发错误。Only strange thing I can see here is that
add_option()
should only take two or four arguments (with an empty third). Setting the third causes Wordpress to run its_deprecated_argument()
function which will trigger an error if in debug mode.