__( 'Are you really sure you want to set all the options to their default values?', 'shiword' ) ); wp_localize_script( 'sw-options-script', 'sw_l10n', $data ); } } // print a reminder message for set the options after the theme is installed if ( !function_exists( 'shiword_setopt_admin_notice' ) ) { function shiword_setopt_admin_notice() { echo '

' . sprintf( __( "Shiword theme says: \"Don't forget to set my options and the header image!\" ", 'shiword' ), get_admin_url() . 'themes.php?page=tb_shiword_functions' ) . '

'; } } if ( current_user_can( 'manage_options' ) && $shiword_opt['version'] < $shiword_current_theme['Version'] ) { add_action( 'admin_notices', 'shiword_setopt_admin_notice' ); } if ( !function_exists( 'shiword_register_settings' ) ) { function shiword_register_settings() { //register general settings register_setting( 'shiw_settings_group', 'shiword_options', 'shiword_sanitize_options' ); //register colors settings register_setting( 'shiw_colors_group', 'shiword_colors' ); } } // check and set default options function shiword_default_options() { global $shiword_current_theme; $shiword_opt = get_option( 'shiword_options' ); $shiword_coa = shiword_get_coa(); // if options are empty, sets the default values if ( empty( $shiword_opt ) || !isset( $shiword_opt ) ) { foreach ( $shiword_coa as $key => $val ) { $shiword_opt[$key] = $shiword_coa[$key]['default']; } $shiword_opt['version'] = ''; //null value to keep admin notice alive and invite user to discover theme options update_option( 'shiword_options' , $shiword_opt ); } else if ( !isset( $shiword_opt['version'] ) || $shiword_opt['version'] < $shiword_current_theme['Version'] ) { // check for unset values and set them to default value -> when updated to new version foreach ( $shiword_coa as $key => $val ) { if ( !isset( $shiword_opt[$key] ) ) $shiword_opt[$key] = $shiword_coa[$key]['default']; } $shiword_opt['version'] = ''; //null value to keep admin notice alive and invite user to discover theme options update_option( 'shiword_options' , $shiword_opt ); } } // sanitize options value if ( !function_exists( 'shiword_sanitize_options' ) ) { function shiword_sanitize_options( $input ){ global $shiword_current_theme; $shiword_coa = shiword_get_coa(); // check for updated values and return 0 for disabled ones <- index notice prevention foreach ( $shiword_coa as $key => $val ) { if( $shiword_coa[$key]['type'] == 'chk' ) { if( !isset( $input[$key] ) ) { $input[$key] = 0; } else { $input[$key] = ( $input[$key] == 1 ? 1 : 0 ); } } elseif( $shiword_coa[$key]['type'] == 'sel' ) { if ( !in_array( $input[$key], $shiword_coa[$key]['options'] ) ) $input[$key] = $shiword_coa[$key]['default']; } elseif( $shiword_coa[$key]['type'] == 'opt' ) { if ( !in_array( $input[$key], $shiword_coa[$key]['options'] ) ) $input[$key] = $shiword_coa[$key]['default']; } elseif( $shiword_coa[$key]['type'] == 'txt' ) { if( !isset( $input[$key] ) ) { $input[$key] = ''; } else { $input[$key] = trim( strip_tags( $input[$key] ) ); } } elseif( $shiword_coa[$key]['type'] == 'txtarea' ) { if( !isset( $input[$key] ) ) { $input[$key] = ''; } else { $input[$key] = trim( strip_tags( $input[$key] ) ); } } elseif( $shiword_coa[$key]['type'] == 'int' ) { if( !isset( $input[$key] ) ) { $input[$key] = $shiword_coa[$key]['default']; } else { $input[$key] = (int) $input[$key] ; } } elseif( $shiword_coa[$key]['type'] == 'col' ) { $color = str_replace( '#' , '' , $input[$key] ); $color = preg_replace( '/[^0-9a-fA-F]/' , '' , $color ); $input[$key] = '#' . $color; } } // check for required options foreach ( $shiword_coa as $key => $val ) { if ( $shiword_coa[$key]['req'] != '' ) { if ( $input[$shiword_coa[$key]['req']] == 0 ) $input[$key] = 0; } } $input['version'] = $shiword_current_theme['Version']; // keep version number return $input; } } // the option page if ( !function_exists( 'shiword_edit_options' ) ) { function shiword_edit_options() { if ( !current_user_can( 'edit_theme_options' ) ) { wp_die( __( 'You do not have sufficient permissions to access this page.', 'shiword' ) ); } global $shiword_opt, $shiword_current_theme; if ( isset( $_GET['erase'] ) && ! isset( $_REQUEST['settings-updated'] ) ) { delete_option( 'shiword_options' ); shiword_default_options(); $shiword_opt = get_option( 'shiword_options' ); } $shiword_coa = shiword_get_coa(); // update version value when admin visit options page if ( $shiword_opt['version'] < $shiword_current_theme['Version'] ) { $shiword_opt['version'] = $shiword_current_theme['Version']; update_option( 'shiword_options' , $shiword_opt ); } ?>

' . __( 'Options saved.', 'shiword' ) . '

'; } // return options save message if ( isset( $_GET['erase'] ) && ! isset( $_REQUEST['settings-updated'] ) ) { echo '

' . __( 'Defaults values loaded.', 'shiword' ) . '

'; } ?>

$val ) { ?>
/> $option ) { ?>
' . __('requires','shiword') . ': ' . $shiword_coa[$shiword_coa[$key]['req']]['description']; ?>
$subval ) { ?> /> : : : $option ) { ?> :
-
|


Support the theme in your language, provide a translation.
'', 'device_color' => '#000000', 'device_opacity' => '100', 'device_textcolor' => '#ffffff', 'device_button' => '#ff8d39', 'device_button_style' => 'light' ); // Holds default inside colors $shiword_default_device_colors = array( 'main3' => '#21759b', 'main4' => '#ff8d39', 'menu1' => '#21759b', 'menu2' => '#cccccc', 'menu3' => '#262626', 'menu4' => '#ffffff', 'menu5' => '#ff8d39', 'menu6' => '#cccccc', ); if ( $type == 'out') { return $shiword_default_device_bg; } elseif ( $type == 'in') { return $shiword_default_device_colors; } else { return array_merge( $shiword_default_device_bg , $shiword_default_device_colors ); } } //get the theme color values. uses default values if options are empty or unset function shiword_get_colors() { /* Holds default colors. */ $default_device_colors = shiword_get_default_colors('all'); $shiword_colors = get_option( 'shiword_colors' ); foreach ( $default_device_colors as $key => $val ) { if ( ( !isset( $shiword_colors[$key] ) ) || empty( $shiword_colors[$key] ) ) { $shiword_colors[$key] = $default_device_colors[$key]; } } return $shiword_colors; } // Styles the header image displayed on the Appearance > Header admin panel. if ( !function_exists( 'shiword_admin_header_style' ) ) { function shiword_admin_header_style() { echo '' . "\n"; } } // Register a selection of default images to be displayed as device backgrounds by the custom device color admin UI. based on WP theme.php -> register_default_headers() if ( !function_exists( 'shiword_register_default_device_images' ) ) { function shiword_register_default_device_images( $headers ) { global $shiword_default_device_images; $shiword_default_device_images = array_merge( (array) $shiword_default_device_images , (array) $headers ); } } // Add callbacks for device color display. based on WP theme.php -> add_custom_image_header() if ( !function_exists( 'shiword_add_custom_device_image' ) ) { function shiword_add_custom_device_image() { if ( ! is_admin() ) return; require_once( 'custom-device-color.php' ); $GLOBALS['custom_device_color'] =& new Custom_device_color(); add_action( 'admin_menu' , array(&$GLOBALS['custom_device_color'] , 'init' )); } } //Add callbacks for background image display. based on WP theme.php -> add_custom_background() if ( !function_exists( 'shiword_add_custom_background' ) ) { function shiword_add_custom_background( $header_callback = '', $admin_header_callback = '', $admin_image_div_callback = '' ) { if ( isset( $GLOBALS['custom_background'] ) ) return; if ( empty( $header_callback ) ) $header_callback = '_custom_background_cb'; add_action( 'wp_head', $header_callback ); if ( ! is_admin() ) return; require_once( 'my-custom-background.php' ); $GLOBALS['custom_background'] =& new Custom_Background( $admin_header_callback, $admin_image_div_callback ); add_action( 'admin_menu', array( &$GLOBALS['custom_background'], 'init' ) ); } } //Add new contact methods to author panel if ( !function_exists( 'shiword_new_contactmethods' ) ) { function shiword_new_contactmethods( $contactmethods ) { //add Twitter $contactmethods['twitter'] = 'Twitter'; //add Facebook $contactmethods['facebook'] = 'Facebook'; return $contactmethods; } } //add a default gravatar if ( !function_exists( 'shiword_addgravatar' ) ) { function shiword_addgravatar( $avatar_defaults ) { $myavatar = get_template_directory_uri() . '/images/user.png'; $avatar_defaults[$myavatar] = __( 'shiword Default Gravatar', 'shiword' ); return $avatar_defaults; } } ?>