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

我想在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 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化