$bundle['type'] ) );
if( array_key_exists( 'options', $bundle ) )
$options = array_merge( $options, array( $bundle['id'] => $bundle['options'] ) );
}
// check by type
foreach( $input as $key => $value ) :
// check boxes
if( $types[$key] == 'checkbox' ) :
$input[$key] = ( $value ? 1 : '' );
// text boxes
elseif( $types[$key] == 'text' || $types[$key] == 'text-short' || $types[$key] == 'textarea' ) :
$input[$key] = esc_attr( $value );
// number only textbox
elseif( $types[$key] == 'text-number' || $types[$key] == 'text-numbers' || $types[$key] == 'text-num' ) :
$input[$key] = preg_replace( '/[^0-9]/', '', $value );
// radio / select boxes
elseif( $types[$key] == 'radio' || $types[$key] == 'select' ) :
if( !array_key_exists( $value, $options[$key] ) )
$input[$key] = $defaults[$key];
endif;
endforeach;
if( $input['content_width'] < 200 ) $input['content_width'] = 200;
if( $input['sidebar_width'] < 120 ) $input['sidebar_width'] = 120;
if( $input['content_width'] < 6 ) $input['padding'] = 6;
return $input;
}
// gets array of all theme options
function bitLumen_get_options( $use_global=true ) {
if( $use_global ) global $bitLumen_options;
if( !isset( $bitLumen_options ) )
$bitLumen_options = get_option( BITLUMEN_OPTIONS_NAME );
if( !$bitLumen_options )
$bitLumen_options = bitLumen_get_defaults();
return $bitLumen_options;
}
// get an option value from the theme's options array
function bitLumen_get_option( $option_slug, $use_global=true ) {
if( $use_global ) global $bitLumen_options;
if( !isset( $bitLumen_options ) )
$bitLumen_options = bitLumen_get_options();
if( !array_key_exists( $option_slug, $bitLumen_options ) ) return false;
else return $bitLumen_options[$option_slug];
}
// delete theme options
function bitLumen_delete_options() {
delete_option( BITLUMEN_OPTIONS_NAME );
}
// adds theme options page
function bitLumen_create_menu() {
add_theme_page( 'bitLumen Theme Options', 'Theme Options', 'edit_theme_options', BITLUMEN_OPTIONS_NAME, 'bitLumen_do_options_page' );
}
// draws options pageadd_action( 'wp_head', 'add_our_scripts',0);
function bitLumen_do_options_page() {
// check for special functions
if( array_key_exists( 'special_action', $_POST ) ) :
// reset options
if( $_POST['special_action'] == 'reset' ) {
bitLumen_delete_options();
bitLumen_settings_message( 'Theme settings restored to default state.' );
}
endif;
// echo updated message
if( isset( $_REQUEST['settings-updated'] ) )
bitLumen_settings_message( 'Theme options successfully saved.' );
?>
$bundle['default'] ) );
return $defaults;
}
// options structure
function bitLumen_options_struct() {
$output = array (
// POST INFORMATION
array(
'type' => 'section',
'name' => 'Post Information',
'desc' => 'Set the post information shown at the top of each post' ),
// show authors
array(
'id' => 'entry_post_author',
'type' => 'radio',
'name' => 'Post Author',
'desc' => 'Display post author name or link',
'options' => array(
'none' => 'Don\'t display any author information',
'text' => 'Display name as text',
'link' => 'Display name as link to author page' ),
'default' => 'link' ),
// show post date
array(
'id' => 'entry_post_date',
'type' => 'radio',
'name' => 'Post date',
'desc' => 'Display the date when each post or page was last created/updated',
'options' => array(
'none' => 'Don\'t display any post date',
'created' => 'Display date post was first published',
'updated' => 'Display date post was last updated' ),
'default' => 'created' ),
// additional post options fieldset
array(
'type' => 'fieldset',
'name' => 'Additional Post Options',
'desc' => 'More settings for post meta information' ),
// show post times
array(
'id' => 'entry_post_time',
'type' => 'checkbox',
'name' => 'Include the time in post date',
'desc' => 'Display the date when each post or page was last created/updated',
'default' => '' ),
// hide edit link
array(
'id' => 'entry_edit_link',
'type' => 'checkbox',
'name' => 'Include "edit post" link for administrators',
'desc' => 'Show the edit post link to logged in admin users',
'default' => 1 ),
// hide trash link
array(
'id' => 'entry_trash_link',
'type' => 'checkbox',
'name' => 'Include "trash post" link for administrators',
'desc' => 'Show a trash post link to logged in admin users',
'type' => 'checkbox',
'default' => '' ),
array( 'type' => 'close-fieldset' ),
array( 'type' => 'close' ),
// SITE TEXT
array(
'type' => 'section',
'name' => 'Site text',
'desc' => 'Custom text used on your site' ),
// header fieldset
array(
'type' => 'fieldset',
'name' => 'Header',
'desc' => 'Text settings for the site header' ),
// subtitle
array(
'id' => 'blog_subtitle',
'type' => 'checkbox',
'name' => 'Show blog description under title in the header',
'desc' => 'Should the description be shown under the title in the header',
'notice' => 'This option is ignored if “Show header text with your image” is unchecked on the Header options page.',
'default' => 1 ),
// close fieldset header
array( 'type' => 'close-fieldset' ),
// title separator
array(
'id' => 'title_sep',
'type' => 'text-short',
'name' => 'Title Separator',
'desc' => 'The character used to seperate pieces of information in the title',
'default' => '»' ),
array(
'id' => 'entry_meta_sep',
'type' => 'text-short',
'name' => 'Post Meta Separator',
'desc' => 'The character used to seperate text or links in the post information',
'default' => '|' ),
array(
'id' => 'footer_sep',
'type' => 'text-short',
'name' => 'Footer Seperator',
'desc' => 'The character used to seperate strings of text or links in the footer.',
'default' => '|' ),
array(
'id' => 'keep_reading_text',
'type' => 'text',
'name' => '“Continue Reading” Text',
'desc' => 'The text used for the “continue reading” link when using the <--more--> tag.',
'default' => 'Keep reading' ),
array( 'type' => 'close' ),
// SITE LAYOUT
array(
'type' => 'section',
'name' => 'Site Layout',
'desc' => 'Styling and layout settings' ),
// web fonts
array(
'id' => 'web_fonts',
'type' => 'radio',
'name' => 'Web Fonts',
'desc' => 'Use local or remote web fonts, or web safe fonts.',
'options' => array(
'none' => 'Don\'t use web fonts',
'local' => 'Use local web fonts',
'remote' => 'Use remote Google Web Fonts' ),
'default' => 'local',
'notice' => 'The “local web fonts” option uses the same web fonts as Google, but uses locally hosted files included in the theme instead of those on Google\'s servers.' ),
// content width
array(
'id' => 'content_width',
'type' => 'text-numbers',
'name' => 'Content Width (in pixels)',
'desc' => 'How many pixels wide the main content area should be?',
'default' => 700 ),
// sidebar width
array(
'id' => 'sidebar_width',
'type' => 'text-numbers',
'name' => 'Sidebar Width (in pixels)',
'desc' => 'How many pixels wide the sidebar should be?',
'default' => 180 ),
// padding
array(
'id' => 'padding',
'type' => 'text-numbers',
'name' => 'Padding (in pixels)',
'desc' => 'How many pixels of space should the content and sidebar be from the edges of the layout?',
'default' => 6 ),
array( 'type' => 'close' )
);
return $output;
}
// returns dynamic style sheet options struct
function bitLumen_get_dynamic_options( $urlencode_and_serialize=false ) {
$output = array(
'src' => get_header_image(),
'height' => get_custom_header()->height,
'width' => get_custom_header()->width,
'text_color' => get_header_textcolor(),
'bg_color' => get_background_color(),
'web_fonts' => bitLumen_get_option( 'web_fonts' ),
'content_width' => bitLumen_get_option( 'content_width' ),
'sidebar_width' => bitLumen_get_option( 'sidebar_width' ),
'padding' => bitLumen_get_option( 'padding' )
);
if( $urlencode_and_serialize ) return urlencode( serialize( $output ) );
else return $output;
}
// ACTIONS
add_action( 'admin_init', 'bitLumen_register_options' ); // register theme settings
add_action( 'admin_menu', 'bitLumen_create_menu' ); // add link to settings