That was officially my first pull request and merge! I’m pretty new to Github and a very casual WordPress theme developer (and not at all a programming expert). I merged your pull request. It works perfectly. The only thing I might add now is a delete_option
so that during development when I’m adding all sorts of different settings and then discarding them, the RESET will fully clear/clean the options table.
For anyone else who wants to do this, here’s the main code snippets. Note: “Respite” is my theme name and so I prefix everything with “respite_”. I still need to style/layout a few things better. The full and up-to-date code is still on Github.
https://github.com/lukejanicke/respite/blob/master/options.php
function respite_settings_defaults() {
$copyright = sprintf( '© %s %s. All rights reserved.', date( 'Y'), get_option( 'blogname' ) );
$meta = array (
'date' => 1,
'category' => 1,
'author' => 1,
'comments' => 1
);
$social = array (
'twitter' => '',
'facebook' => '',
'google' => ''
);
$options = array (
'copyright' => $copyright,
'quip' => $quip,
'meta' => $meta,
'social' => $social
);
return $options;
}
function respite_add_default_settings() {
$options = respite_settings_defaults();
add_option( 'respite', $options );
}
add_action( 'after_theme_setup', 'respite_add_default_settings' );
function respite_sanitize_settings( $settings ) {
if( isset( $settings['reset'] ) ) {
$settings = respite_settings_defaults();
}
return $settings;
}
function respite_register_settings() {
register_setting( 'respite_settings', 'respite', 'respite_sanitize_settings' );
}
add_action( 'admin_init', 'respite_register_settings' );
function respite_options_menu() {
add_theme_page('Respite Options', 'Respite Options', 'edit_theme_options', 'respite-settings', 'respite_settings_page');
}
add_action( 'admin_menu', 'respite_options_menu' );
function respite_settings_page() {
?>
<div class="wrap">
<h2>Respite Options</h2>
<form method="post" action="options.php"><?php
settings_fields( 'respite_settings' );
do_settings_sections( 'respite_settings' );
$options = get_option('respite'); ?>
<table class="form-table">
<tr valign="top">
<th scope="row"><label for"copyright">Copyright Notice</label></th>
<td><p><input type="text" id="copyright" name="respite[copyright]" value='<?php echo $options['copyright']; ?>' /></p><p><em>Optional.</em> Use this field to enter a copyright notice, or any other notice you would like to appear at the bottom of every page. You can include HTML.</p></td>
</tr>
<tr valign="top">
<th scope="row">Post Meta Fields</th>
<td><p><input type="checkbox" id="date" name="respite[meta][date]" value="1" <?php echo checked( 1, $options['meta']['date'], false ); ?> /> <label for"date">Date</label></p>
<p><input type="checkbox" id="category" name="respite[meta][category]" value="1" <?php checked( $options['meta']['category'] ); ?> /> <label for"category">Category</label></p>
<p><input type="checkbox" id="author" name="respite[meta][author]" value="1" <?php checked( $options['meta']['author'] ); ?> /> <label for"author">Author</label></p>
<p><input type="checkbox" id="comments" name="respite[meta][comments]" value="1" <?php checked( $options['meta']['comments'] ); ?> /> <label for"comments">Comments</label></p>
<p>Select the post meta components you would like displayed.</p></td>
</tr>
<tr valign="top">
<th scope="row">Social Network Presences</th>
<td>
<label for"twitter">Twitter</label>
<p><input type="text" id="twitter" name="respite[social][twitter]" value='<?php echo $options['social']['twitter']; ?>' /></p>
<label for"facebook">Facebook</label>
<p><input type="text" id="facebook" name="respite[social][facebook]" value='<?php echo $options['social']['facebook']; ?>' /></p>
<label for"google">Google Plus</label>
<p><input type="text" id="google" name="respite[social][google]" value='<?php echo $options['social']['google']; ?>' /></p>
</td>
</tr>
</table>
<?php submit_button(); ?>
<p class="submit">
<input type="submit" class="button button-secondary" name="respite[reset]" value="<?php _e('Reset Settings'); ?>" />
</p>
</form>
</div>
<?php }