How do I update an option?
-
Hi
I am a total newbie and have started on a simple plugin which changes the Howdy message – which seems to work.
Then I added in an additional input box on the form where the user can add in a custom message for September.
Was able to successfully create an options array, save initial string (Happy September), retrieve this string and display it in an input box, but for the life of me I can’t figure out how to update it.
Below is my code….
Sorry if it’s all messed up!
if (is_admin()) { function wp_customize_howdy() { add_options_page ("Customize Howdy", "Customize Howdy", "manage_options", basename(__FILE__), "wp_customize_the_howdy_page"); } add_action("admin_menu", "wp_customize_howdy"); } function wp_customize_the_howdy_page() { $today = date("m.d.y"); $the_month = date ("m"); if (isset($_POST["howdynewtext"])) { $nonce = $_REQUEST["_wpnonce"]; if (! wp_verify_nonce($nonce, "php-the-howdy-text") ) { die("Error!"); } $howdynewtext = $_POST["howdynewtext"]; update_option ("wp_howdynewtext", $howdynewtext); } $wp_howdynewtext = get_option("wp_howdynewtext"); $myOptions = get_option("MyOptions"); $wp_howdyseptext = $myOptions['firstOption']; ?> <div class="bootstrap-wrapper"> <form action="" method="post" onsubmit="submit_me('howdyseptext')"> <?php wp_nonce_field("php-the-howdy-text"); ?> <div style="margin:0px;margin-top:20px;"> <h2>Customize the Howdy Message!</h2> <p>Banish Howdy forever!</p> <p>Below you can enter a different word for Howdy and a different message (up to 25 characters) for special dates!</p> <p>Change Howdy to.... <input type="text" name = "howdynewtext" value= "<?php echo $wp_howdynewtext; ?>" /></p> <p>Sep. Message.... <input type="text" name = "howdyseptext" value= "<?php echo $wp_howdyseptext; ?>" /></p> <p><input type="submit" value="Update" class="button-primary control-label col-xs-2" id="submit" name="submit" /></p> </div> </form> </div> <?php } function submit_me('howdyseptext') { // update_option('myOptions', $myOptions); // update_option('myOptions', $_POST); } function customize_the_howdy_msg ($wp_admin_bar) { $the_month = date ("m"); $the_day = date ("d"); $my_account = $wp_admin_bar->get_node ("my-account"); $howdynewtext = get_option ("wp_howdynewtext"); $newtitle = str_replace ("Howdy", $howdynewtext, $my_account->title ); $wp_admin_bar->add_node (array( "id" => "my-account", "title" => $newtitle, ) ); } if (get_option ("wp_howdynewtext")) { add_filter ("admin_bar_menu", "customize_the_howdy_msg", 25); }
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘How do I update an option?’ is closed to new replies.