Created
November 3, 2011 14:14
-
-
Save elebescond/1336580 to your computer and use it in GitHub Desktop.
Wordpress how to register admin options
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'admin_init', 'myplugin_admin_init' ); | |
function myplugin_admin_init() { | |
//register settings | |
register_setting( 'myplugin_options_group1', 'myplugin_option_1' ); | |
} | |
// create custom plugin settings menu | |
add_action('admin_menu', 'myplugin_create_menu'); | |
function myplugin_create_menu() { | |
if (function_exists('add_options_page')) { | |
add_options_page(__('Myplugin Plugin Settings','myplugin'), __('My plugin','myplugin'), 'level_10', __FILE__, 'myplugin_settings_page'); | |
} | |
} | |
function myplugin_settings_page() { | |
?> | |
<div class="wrap"> | |
<h2>My Plugins Settings</h2> | |
<form method="post" action="options.php"> | |
<?php settings_fields( 'myplugin_options_group1' ); ?> | |
<table class="form-table"> | |
<tr valign="top"> | |
<th scope="row">Option 1</th> | |
<td><input type="text" name="myplugin_option_1" value="<?php echo get_option('myplugin_option_1'); ?>" /></td> | |
</tr> | |
</table> | |
<p class="submit"> | |
<input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" /> | |
</p> | |
</form> | |
</div> | |
<?php } ?> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment