Skip to content

Instantly share code, notes, and snippets.

@elebescond
Created November 3, 2011 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save elebescond/1336580 to your computer and use it in GitHub Desktop.
Save elebescond/1336580 to your computer and use it in GitHub Desktop.
Wordpress how to register admin options
<?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