Wordpress插件选项页面

时间:2014-05-07 14:29:15

标签: php wordpress wordpress-plugin

我正在尝试创建一个wordpress twitter插件,对于我的选项页面,我需要将表单保存到我设法创建的表格中。我已经创建了表单,现在我需要知道如何确保它发布到我的表中?我有以下代码,我的表名是wp_twitter_carla。

function register_mysettings() {
    //register our settings
    register_setting( 'twitter-settings-group', 'twitteruser' );
    register_setting( 'twitter-settings-group', 'notweets' );
    register_setting( 'twitter-settings-group', 'replies' );
    register_setting( 'twitter-settings-group', 'retweets' );
}

function twitter_settings_page() {
?>
<div class="wrap">
<h2>Twitter Feed by Carla</h2>

<form method="post" action="options.php">
    <?php settings_fields( 'twitter-settings-group' ); ?>
    <?php do_settings_sections( 'twitter-settings-group' ); ?>
    <table class="form-table">
        <tr valign="top">
        <th scope="row">Twitter Username</th>
        <td><input type="text" name="twitteruser" value="<?php echo get_option('twitteruser'); ?>" /></td>
        </tr>

        <tr valign="top">
        <th scope="row">Number of tweets to show</th>
        <td><input type="text" name="notweets" value="<?php echo get_option('notweets'); ?>" /></td>
        </tr>

        <tr valign="top">
        <th scope="row">Show replies?</th>
        <td><input type="text" name="replies" value="<?php echo get_option('replies'); ?>" /></td>
        </tr>

        <tr valign="top">
        <th scope="row">Show retweets?</th>
        <td><input type="text" name="retweets" value="<?php echo get_option('retweets'); ?>" /></td>
        </tr>
    </table>

    <?php submit_button(); ?>

</form>
</div>

2 个答案:

答案 0 :(得分:1)

Wordpress应将您的设置保存在wp_options表中。打开phpmyadmin,选择你的数据库并单击 sql写了这个sql代码

SELECT * FROM `wp_options` WHERE `option_name` LIKE '%twitter-settings-group%' OR `option_value` LIKE '%twitter-settings-group%

应该有一个结果是wp序列化你的表单并在数据库中保持一行。

最诚挚的问候, 吊架。

答案 1 :(得分:0)

虽然这不能直接回答您的具体问题,但我建议您使用Redux Framework。它是一个基于WordPress设置API的选项框架,它非常易于使用。它将为您处理所有数据库发布,检索等。绝对值得花一些时间来学习他们的API,我想你会对它感到高兴。