saving plugin options - settings_fields()

Here we will discuss about the wordpress general help and support.
  • Ads

saving plugin options - settings_fields()

Postby prasad » Thu Aug 05, 2010 12:02 am

I'm trying to save some plug-in options with no luck. First, the option is not even being added with the default and when I click save it just takes me to options.php. Any idea what I'm missing?

add_action("admin_init","tvc_globals_init");
function tvc_globals_init(){
register_setting("tvc_globals", "tvc_global_main");
}
register_activation_hook( __FILE__, 'tvc_globals_activate' );
function tvc_globals_activate(){
add_option("tvc_global_main", "my_default");
}
add_action('admin_menu', 'tvcweb_admin_actions');
function tvcweb_admin_actions(){
add_options_page("TVC Globals", "TVC Globals", 10 , __FILE__ , "tvc_global_admin");
}
function tvc_global_admin(){
register_setting("tvc_globals", "tvc_global_main");
$tvc_main = get_option("tvc_global_main");
print "<div class=\"wrap\">
<h2>TVCWeb Global Settings</h2>
<form method=\"post\" action=\"options.php\">". settings_fields("tvc_globals") ."
<div class=\"form-table\">
<p>site root<br />
<input name=\"tvc_global_main\" type=\"text\" value=\"$tvc_main\" />
</p>
</div>
<p class=\"submit\"><input type=\"submit\" class=\"button-primary\" value=\"".__("Save Changes")."\" /></p>
</form>
</div>";
}
prasad
Newbie
Newbie
 
Posts: 86
Joined: Fri Jul 23, 2010 2:34 am

Re: saving plugin options - settings_fields()

Postby prasad » Thu Aug 05, 2010 12:02 am

I believe I've figured out my problem. It's the way I was calling settings_fields().

Many thanks to the sample provided at planetozh

Sticking to his code formatting this is now working for me. Once I try to build and print one long string again, I'm back to the broken behavior.
prasad
Newbie
Newbie
 
Posts: 86
Joined: Fri Jul 23, 2010 2:34 am

  • Ads

Return to Wordpress General Help

Who is online

Users browsing this forum: No registered users and 1 guest

cron