【问题标题】:Wordpress Plugin DevelopmentWordPress 插件开发
【发布时间】:2011-05-06 20:54:00
【问题描述】:

我正在使用这个网站http://wpbits.wordpress.com/2007/08/15/adding-options-to-wordpress-plugins/,to 帮助我锻炼如何制作一个保存选项的插件。 这是我的代码,但它似乎不起作用。谁能指出我正确的方向:

<?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');
?>

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    我发现了问题,我需要将每个函数包装在 if(function_exists()) 中。 谢谢

    【讨论】:

      【解决方案2】:

      我在这里看到的唯一奇怪的事情是add_option() 应该只接受两个或四个参数(第三个是空的)。设置第三个会导致 Wordpress 运行其 _deprecated_argument() 函数,如果处于调试模式,则会触发错误。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-05-02
        • 1970-01-01
        • 1970-01-01
        • 2015-03-10
        • 1970-01-01
        • 2014-11-05
        相关资源
        最近更新 更多