Created
January 30, 2014 16:49
-
-
Save stormwarning/8713032 to your computer and use it in GitHub Desktop.
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 | |
function _s_theme_options_init() { | |
register_setting( | |
'_s_options', // Options group, see settings_fields() call in _s_theme_options_render_page() | |
'_s_theme_options', // Database option, see _s_get_theme_options() | |
'_s_theme_options_validate' // The sanitization callback, see _s_theme_options_validate() | |
); | |
// Register our settings field group | |
add_settings_section( | |
'general', // Unique identifier for the settings section | |
'', // Section title (we don't want one) | |
'__return_false', // Section callback (we don't want anything) | |
'theme_options' // Menu slug, used to uniquely identify the page; see _s_theme_options_add_page() | |
); | |
add_settings_field( 'facebook_input', __( 'Facebook', '_s' ), '_s_settings_field_facebook_input', 'theme_options', 'general' ); | |
add_settings_field( 'twitter_input', __( 'Twitter', '_s' ), '_s_settings_field_twitter_input', 'theme_options', 'general' ); | |
add_settings_field( 'youtube_input', __( 'YouTube', '_s' ), '_s_settings_field_youtube_input', 'theme_options', 'general' ); | |
add_settings_field( 'linkedin_input', __( 'LinkedIn', '_s' ), '_s_settings_field_linkedin_input', 'theme_options', 'general' ); | |
add_settings_field( 'video_input', __( 'Video URL', '_s' ), '_s_settings_field_video_input', 'theme_options', 'general' ); | |
add_settings_field( 'appstore_input', __( 'AppStore Link', '_s' ), '_s_settings_field_appstore_input', 'theme_options', 'general' ); | |
add_settings_field( 'googleplay_input', __( 'Google Play Link', '_s' ), '_s_settings_field_googleplay_input', 'theme_options', 'general' ); | |
} | |
add_action( 'admin_init', '_s_theme_options_init' ); | |
function _s_option_page_capability( $capability ) { | |
return 'edit_theme_options'; | |
} | |
add_filter( 'option_page_capability__s_options', '_s_option_page_capability' ); | |
function _s_theme_options_add_page() { | |
$theme_page = add_theme_page( | |
__( 'Theme Options', '_s' ), // Name of page | |
__( 'Theme Options', '_s' ), // Label in menu | |
'edit_theme_options', // Capability required | |
'theme_options', // Menu slug, used to uniquely identify the page | |
'_s_theme_options_render_page' // Function that renders the options page | |
); | |
} | |
add_action( 'admin_menu', '_s_theme_options_add_page' ); | |
function _s_get_theme_options() { | |
$saved = (array) get_option( '_s_theme_options' ); | |
$defaults = array( | |
'facebook_input' => '', | |
'twitter_input' => '', | |
'youtube_input' => '', | |
'linkedin_input' => '', | |
'video_input' => '', | |
'appstore_input' => '', | |
'googleplay_input' => '' | |
); | |
$defaults = apply_filters( '_s_default_theme_options', $defaults ); | |
$options = wp_parse_args( $saved, $defaults ); | |
$options = array_intersect_key( $options, $defaults ); | |
return $options; | |
} | |
function _s_settings_field_facebook_input() { | |
$options = _s_get_theme_options(); | |
?> | |
<input type="text" name="_s_theme_options[facebook_input]" id="facebook-input" value="<?php echo esc_attr( $options['facebook_input'] ); ?>" /> | |
<p class="description" for="facebook-input"><?php _e( 'Enter your facebook fan page ID', '_s' ); ?></p> | |
<?php | |
} | |
function _s_settings_field_twitter_input() { | |
$options = _s_get_theme_options(); | |
?> | |
<input type="text" name="_s_theme_options[twitter_input]" id="twitter-input" value="<?php echo esc_attr( $options['twitter_input'] ); ?>" /> | |
<p class="description" for="twitter-input"><?php _e( 'Enter your twitter account ID', '_s' ); ?></p> | |
<?php | |
} | |
function _s_settings_field_youtube_input() { | |
$options = _s_get_theme_options(); | |
?> | |
<input type="text" name="_s_theme_options[youtube_input]" id="youtube-input" value="<?php echo esc_attr( $options['youtube_input'] ); ?>" /> | |
<p class="description" for="youtube-input"><?php _e( 'Enter your youtube ID', '_s' ); ?></p> | |
<?php | |
} | |
function _s_settings_field_linkedin_input() { | |
$options = _s_get_theme_options(); | |
?> | |
<input type="text" name="_s_theme_options[linkedin_input]" id="linkedin-input" value="<?php echo esc_attr( $options['linkedin_input'] ); ?>" /> | |
<p class="description" for="linkedin-input"><?php _e( 'Enter your LinkedIn ID', '_s' ); ?></p> | |
<?php | |
} | |
function _s_settings_field_video_input() { | |
$options = _s_get_theme_options(); | |
?> | |
<input type="text" name="_s_theme_options[video_input]" id="video-input" value="<?php echo esc_attr( $options['video_input'] ); ?>" /> | |
<p class="description" for="video-input"><?php _e( 'Enter the link for the home page video', '_s' ); ?></p> | |
<?php | |
} | |
function _s_settings_field_appstore_input() { | |
$options = _s_get_theme_options(); | |
?> | |
<input type="text" name="_s_theme_options[appstore_input]" id="appstore-input" value="<?php echo esc_attr( $options['appstore_input'] ); ?>" /> | |
<p class="description" for="appstore-input"><?php _e( 'Enter the AppStore application link', '_s' ); ?></p> | |
<?php | |
} | |
function _s_settings_field_googleplay_input() { | |
$options = _s_get_theme_options(); | |
?> | |
<input type="text" name="_s_theme_options[googleplay_input]" id="googleplay-input" value="<?php echo esc_attr( $options['googleplay_input'] ); ?>" /> | |
<p class="description" for="googleplay-input"><?php _e( 'Enter the Google Play application link', '_s' ); ?></p> | |
<?php | |
} | |
function _s_theme_options_render_page() { | |
?> | |
<div class="wrap"> | |
<?php screen_icon(); ?> | |
<?php $theme_name = function_exists( 'wp_get_theme' ) ? wp_get_theme() : get_current_theme(); ?> | |
<h2><?php printf( __( '%s Theme Options', '_s' ), $theme_name ); ?></h2> | |
<?php settings_errors(); ?> | |
<form method="post" action="options.php"> | |
<?php | |
settings_fields( '_s_options' ); | |
do_settings_sections( 'theme_options' ); | |
submit_button(); | |
?> | |
</form> | |
</div> | |
<?php | |
} | |
function _s_theme_options_validate( $input ) { | |
$output = array(); | |
// The sample text input must be safe text with no HTML tags | |
if ( isset( $input['facebook_input'] ) && ! empty( $input['facebook_input'] ) ) | |
$output['facebook_input'] = wp_filter_nohtml_kses( $input['facebook_input'] ); | |
if ( isset( $input['twitter_input'] ) && ! empty( $input['twitter_input'] ) ) | |
$output['twitter_input'] = wp_filter_nohtml_kses( $input['twitter_input'] ); | |
if ( isset( $input['youtube_input'] ) && ! empty( $input['youtube_input'] ) ) | |
$output['youtube_input'] = wp_filter_nohtml_kses( $input['youtube_input'] ); | |
if ( isset( $input['linkedin_input'] ) && ! empty( $input['linkedin_input'] ) ) | |
$output['linkedin_input'] = wp_filter_nohtml_kses( $input['linkedin_input'] ); | |
if ( isset( $input['video_input'] ) && ! empty( $input['video_input'] ) ) | |
$output['video_input'] = wp_filter_nohtml_kses( $input['video_input'] ); | |
if ( isset( $input['appstore_input'] ) && ! empty( $input['appstore_input'] ) ) | |
$output['appstore_input'] = wp_filter_nohtml_kses( $input['appstore_input'] ); | |
if ( isset( $input['googleplay_input'] ) && ! empty( $input['googleplay_input'] ) ) | |
$output['googleplay_input'] = wp_filter_nohtml_kses( $input['googleplay_input'] ); | |
return apply_filters( '_s_theme_options_validate', $output, $input ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment