Skip to content

Instantly share code, notes, and snippets.

@greatislander
Last active January 9, 2017 16:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save greatislander/14629a925ff34cff0bdb0f193572ade5 to your computer and use it in GitHub Desktop.
Save greatislander/14629a925ff34cff0bdb0f193572ade5 to your computer and use it in GitHub Desktop.
Custom theme options in existing tab for Pressbooks.
<?php
add_action( 'pb_theme_options_web_add_settings_fields', 'add_custom_web_settings', 10, 2 );
add_filter( 'pb_theme_options_web_booleans', 'get_custom_booleans' );
/**
* Add the setting itself.
*
* @param string $_page The settings identifier, e.g. pressbooks_theme_options_web
* @param string $_section The settings section identifier, e.g. web_options_section
*/
function add_custom_web_settings( $_page, $_section ) {
add_settings_field(
'custom_web_setting',
__( 'Custom Web Setting', 'pressbooks' ),
'render_custom_web_setting',
$_page,
$_section,
array(
__( 'Display a custom web setting', 'pressbooks' )
)
);
}
/**
* Call the render function for a checkbox from the \Pressbooks\Options class.
*
* @param array $args
*/
function render_custom_web_setting( $args ) {
$options = get_option( 'pressbooks_theme_options_web', \Pressbooks\Modules\ThemeOptions\WebOptions::getDefaults() );
\Pressbooks\Options::renderCheckbox( 'custom_web_setting', 'pressbooks_theme_options_web', 'custom_web_setting', @$options['custom_web_setting'], $args[0] );
}
/**
* Add our (boolean) option to the \Pressbooks\Options sanitization routines.
*
* @param array $settings
*/
function get_custom_booleans( $settings ) {
$settings[] = 'custom_web_setting';
return $settings;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment