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 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助