Last active
January 9, 2017 16:37
-
-
Save greatislander/14629a925ff34cff0bdb0f193572ade5 to your computer and use it in GitHub Desktop.
Custom theme options in existing tab for Pressbooks.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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