Skip to content

Instantly share code, notes, and snippets.

@middlesister
Last active December 17, 2015 05:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save middlesister/5560820 to your computer and use it in GitHub Desktop.
Save middlesister/5560820 to your computer and use it in GitHub Desktop.
Add child theme settings to Thematic theme options page
<?php
add_action ('admin_init', 'childtheme_opt_init');
/**
* Add childtheme settings to the thematic theme
*
* This will create a separate setting in the database, but
* add the settings to the existing theme options page in Thematic
**/
function childtheme_opt_init() {
/* Register childtheme setting separate from thematic */
register_setting(
'thematic_opt_group', // Add to thematic settings page group
'childtheme_options', // Name of the database option
'childtheme_options_validate' // The sanitization callback for the options
);
/* Add a settings section for our childtheme */
add_settings_section(
'childtheme_section', // Slug of this section
__( 'Childtheme title', 'child-textdomain' ), // Title of this section (optional, can be empty string)
'childtheme_section_html', // Callback function for this section description
'thematic_theme_opt' // Add to the thematic setting sections
);
/* Add settings fields to the settings section */
add_settings_field(
'childtheme_textarea', // Slug of the option
__( 'Write some text', 'child-textdomain' ), // Title of the option
'childtheme_textarea_html', // Callback for rendering the option
'thematic_theme_opt', // Add to the thematic setting sections
'childtheme_section' // Add to the section defined above
);
}
/**
* Return default childtheme options.
*
* @return array $childtheme_default_opt The default options
*/
function childtheme_default_opt() {
$childtheme_default_opt = array(
'childtheme_textarea' => 'Bacon!'
);
return $childtheme_default_opt;
}
/**
* Validate our child theme options
*
* Thematic takes care of the thematic form data, we only need
* to worry about the childtheme settings we have created
*
* @param array $input Raw input from the form
* @return array $output Sanitized and cleaned data ready for database
**/
function childtheme_options_validate( $input ) {
/* Pull existing settings from database */
$output = get_option( 'childtheme_options', childtheme_default_opt() );
/* Allow basic HTML and WP shortcodes */
if ( isset( $input['childtheme_textarea'] ) ) {
$output['childtheme_textarea'] = wp_kses_post( $input['childtheme_textarea'] ) ;
}
return $output;
}
/**
* Render the description of settings section: childtheme_section
**/
function childtheme_section_html() {
// sound of one hand clapping
}
/**
* Render the textarea for childtheme setting: childtheme_textarea
*/
function childtheme_textarea_html() {
$options = thematic_get_wp_opt( 'childtheme_options', childtheme_default_opt() );
?>
<textarea rows="5" cols="94" id="childtheme_textarea" name="childtheme_options[childtheme_textarea]"><?php echo $options['childtheme_textarea']; ?></textarea>
<?php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment