Skip to content

Instantly share code, notes, and snippets.

@middlesister
Created May 12, 2013 18:53
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/5564519 to your computer and use it in GitHub Desktop.
Save middlesister/5564519 to your computer and use it in GitHub Desktop.
<?php
add_action ('admin_init', 'childtheme_opt_init');
/**
* Add childtheme settings to the thematic theme
*
* This will add childtheme options to the thematic theme settings
* in the database, and add to the existing theme options page in Thematic
**/
function childtheme_opt_init() {
/* Add default values for the childtheme options to thematic default options array */
add_filter( 'thematic_theme_default_opt','childtheme_add_default_ops', 10, 1 );
/* Add childtheme field validation to thematic validation */
add_filter( 'thematic_theme_opt_validation','childtheme_add_validation', 20, 2 );
/* 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_pagetitle_top_html', // Callback for rendering the option
'thematic_theme_opt', // Add to the thematic setting sections
'childtheme_section' // Add to the section defined above
);
}
/**
* Add default values for the child theme options
* to the thematic options array
*
* @param array $defaults The thematic default options
* @return array $defaults The new defaults
**/
function childtheme_add_default_ops( $defaults ) {
$defaults['childtheme_textarea'] = 'Bacon!';
return $defaults;
}
/**
* Add validation of the child options to thematic
*
* Thematic takes care of the thematic form data, we only need
* to worry about the childtheme settings we have created.
*
* @param array $output The prepared array from thematic
* @param array $input The raw data from the form
* @return array $output The fully sanitized array
**/
function childtheme_add_validation( $output, $input ) {
if ( isset( $input['childtheme_textarea'] ) ) {
$output['childtheme_textarea'] = wp_kses_post( $input['childtheme_textarea'] ) ;
}
return $output;
}
/**
* Do the title of settings section: childtheme_section
*
* Would be an optional description
**/
function childtheme_section_html() {
// sound of one hand clapping
}
/**
* Render the textarea for childtheme option: childtheme_textarea
*/
function childtheme_textarea_html() {
/* grab options from the database */
$options = thematic_get_wp_opt( 'thematic_theme_opt', thematic_default_opt() );
/* grab the default options */
$defaults = thematic_default_opt();
/* use default option if none exist in database */
$options['childtheme_textarea'] = ( isset( $options['childtheme_textarea'] ) ? $options['childtheme_textarea'] : $defaults['childtheme_textarea'] );
/* print the html */
?>
<textarea rows="5" cols="94" id="childtheme_textarea" name="thematic_theme_opt[childtheme_textarea]"><?php echo $options['childtheme_textarea']; ?></textarea>
<?php
}
@Talkless
Copy link

Looks like it's a bug where callback is specified as childtheme_pagetitle_top_html. I have changed it into childtheme_textarea_html and my custom textarea appeared!

Thank you for example!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment