Writing WordPress Plugin, Options Menu Not Updating All the Way
I am trying to write a plugin for wordpress, I got it to work for the most
part, but after the plugin is updated and I go to the Settings > Hello
World menu, only 1 of the input update when I hit save. I am just trying
to enter some text in each input and when I hit save I want it to save in
the database.
What am I doing wrong here?
<?php
/*
Plugin Name: ABC
Plugin URI: http://example.com/abc
Description: My description will go here
Author: Julie
Author URI: http://example.com/julie/
Version: 1.0
*/
/* Runs when plugin is activated */
register_activation_hook(__FILE__,'hello_world_install');
/* Runs on plugin deactivation*/
register_deactivation_hook( __FILE__, 'hello_world_remove' );
function hello_world_install() {
/* Creates new database field */
add_option("hello_world_data", '', '', 'yes');
add_option("hello_world_data2", '', '', 'yes');
}
function hello_world_remove() {
/* Deletes the database field */
delete_option('hello_world_data');
delete_option('hello_world_data2');
}
if ( is_admin() ){
/* Call the html code */
add_action('admin_menu', 'hello_world_admin_menu');
function hello_world_admin_menu() {
add_options_page('Hello World', 'Hello World', 'administrator',
'hello-world', 'hello_world_html_page');
}
}
function hello_world_html_page() {
?>
<div>
<h2>Hello World Options</h2>
<form method="post" action="options.php">
<?php wp_nonce_field('update-options'); ?>
<table width="510">
<tr valign="top">
<th width="92" scope="row">Enter Text 1</th>
<td width="406">
<input name="hello_world_data" type="text" id="hello_world_data"
value="<?php echo get_option('hello_world_data'); ?>" />
(ex. Hello World 1)</td>
</tr>
<tr valign="top">
<th width="92" scope="row">Enter Text 2</th>
<td width="406">
<input name="hello_world_data2" type="text" id="hello_world_data2"
value="<?php echo get_option('hello_world_data2'); ?>" />
(ex. Hello World 2)</td>
</tr>
</table>
<input type="hidden" name="action" value="update" />
<input type="hidden" name="page_options" value="hello_world_data" />
<input type="hidden" name="page_options" value="hello_world_data2" />
<p>
<input type="submit" value="<?php _e('Save Changes') ?>" />
</p>
</form>
</div>
<?php
}
?>
No comments:
Post a Comment