duangu9997 2015-12-03 10:36
浏览 35
已采纳

我想在wordpress的选项表中保存自定义设置

I have written a plug-in for Wordpress. I have activated it and the purpose of that plug-in is to save some options in the site_options table of the database Wordpress created.

When I hit the button to save the options. it redirects me to the options.php page. But nothing is added on the options.php or in the database.

What am I doing wrong here?

My code:

<?php
    // whitelist options
    function register_mysettings() {
        register_setting( 'myoption-group', 'Facebook' );
        register_setting( 'myoption-group', 'LinkedIn' );
        register_setting( 'myoption-group', 'Twitter' );
        register_setting( 'myoption-group', 'Pinterest' );
        register_setting( 'myoption-group', 'GooglePlus' );
    }
?>

<div class="wrap">
    <h2>Sharing plugin settings</h2>

    <?php
        add_action( 'admin_init', 'register_mysettings' );
        settings_fields( 'myoption-group' );
        do_settings_sections( 'myoption-group' );
    ?>

    <form method="post" action="options.php">
        <label for="Facebook">Facebook</label>
        <input type="checkbox" name="Facebook" value="<?php echo get_option('Facebook'); ?>" checked="checked" /><br/>
        <label for="LinkedIn">LinkedIn</label>
        <input type="checkbox" name="LinkedIn" value="<?php echo get_option('LinkedIn'); ?>" checked="checked" /><br/>
        <label for="Twitter">Twitter</label>
        <input type="checkbox" name="Twitter" value="<?php echo get_option('Twitter'); ?>" checked="checked" /><br/>
        <label for="Pinterest">Pinterest</label>
        <input type="checkbox" name="Pinterest" value="<?php echo get_option('Pinterest'); ?>" checked="checked" /><br/>
        <label for="GooglePlus">Google Plus</label>
        <input type="checkbox" name="GooglePlus" value="<?php echo get_option('GooglePlus'); ?>" checked="checked" />
        <?php submit_button(); ?>
    </form>
</div>
  • 写回答

1条回答 默认 最新

  • doukou4066 2015-12-03 10:54
    关注

    You can add setting in your wp_option table using below code :

    add_option('your_option_name','your_option_value');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?