Skip to content

Instantly share code, notes, and snippets.

@LinzardMac
Created January 22, 2013 00:13
Show Gist options
  • Select an option

  • Save LinzardMac/4590819 to your computer and use it in GitHub Desktop.

Select an option

Save LinzardMac/4590819 to your computer and use it in GitHub Desktop.
function my_register_settings() {
register_setting( 'my_options', 'my_options' );
add_settings_section( 'my_general', 'General Settings', 'my_section_general', 'my_options' );
add_settings_field( 'myoptions', 'Options', 'my_field_recurrence', 'my_options', 'my_general' );
add_settings_field( 'search', 'Search', 'my_field_search', 'my_options', 'my_general' );
}
add_action( 'admin_init', 'my_register_settings' );
function my_section_general() {
echo 'My PLugin Page';
}
function my_field_recurrence() {
$options = get_option( 'my_options' );
$myoptions = isset( $options['myoptions'] ) ? $options['myoptions'] : 'hourly';
?>
<select name="my_options[myoptions]">
<?php foreach ( $values as $key => $value ): ?>
<option value="<?php echo $key; ?>" <?php selected( $key == $myoptions ); ?>>myoptions</option>
<?php endforeach; ?>
</select>
<?php
}
function my_field_search() {
$options = get_option( 'my_options' );
$search = isset( $options['search'] ) ? $options['search'] : '';
?>
<input type="text" name="my_options[search]" value="<?php echo esc_attr( $search ); ?>" />
<?php
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment