__( '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 );
}
?>