我想在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>
我为Wordpress编写了一个插件。 我已经激活它,该插件的目的是在Wordpress创建的数据库的site_options表中保存一些选项。 p>
当我点击按钮保存选项时。 它将我重定向到options.php页面。 但是在options.php或数据库中没有添加任何内容。 p>
我在这里做错了什么? p>
我的代码: p>
&lt;?php
//白名单选项
函数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' );
}
?&gt;
&lt; div class =“wrap”&gt;
&lt; h2&gt;分享插件设置&lt; / h2&gt;
&lt;?php
add_action('admin_init ','register_mysettings');
settings_fields('myoption-group');
do_settings_sections('myoption-group');
?&gt;
&lt; form method =“post”action =“options .php“&gt;
&lt; label for =”Facebook“&gt; Facebook&lt; / label&gt;
&lt; input type =”checkbox“name =”Facebook“value =”&lt;?php echo get_option('Facebook' );?&gt;“ checked =“checked”/&gt;&lt; br /&gt;
&lt; label for =“LinkedIn”&gt; LinkedIn&lt; / label&gt;
&lt; input type =“checkbox”name =“LinkedIn”value =“&lt ;?php echo get_option('LinkedIn');?&gt;“ checked =“checked”/&gt;&lt; br /&gt;
&lt; label for =“Twitter”&gt; Twitter&lt; / label&gt;
&lt; input type =“checkbox”name =“Twitter”value =“&lt ;?php echo get_option('Twitter');?&gt;“ checked =“checked”/&gt;&lt; br /&gt;
&lt; label for =“Pinterest”&gt; Pinterest&lt; / label&gt;
&lt; input type =“checkbox”name =“Pinterest”value =“&lt; ;?php echo get_option('Pinterest');?&gt;“ checked =“checked”/&gt;&lt; br /&gt;
&lt; label for =“GooglePlus”&gt; Google Plus&lt; / label&gt;
&lt; input type =“checkbox”name =“GooglePlus”value =“ &lt;?php echo get_option('GooglePlus');?&gt;“ checked =“checked”/&gt;
&lt;?php submit_button(); ?&gt;
&lt; / form&gt;
&lt; / div&gt;
code> pre>
div>
答
You can add setting in your wp_option
table using below code :
add_option('your_option_name','your_option_value');