Skip to content

Commit

Permalink
Merge pull request #112 from ThematicTheme/feature/default_options_no…
Browse files Browse the repository at this point in the history
…t_in_database

Feature/default options not in database

Close #110
  • Loading branch information
middlesister committed Jul 26, 2014
2 parents deebd99 + 8a87bfe commit 5ab1c5d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 28 deletions.
4 changes: 3 additions & 1 deletion library/extensions/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,10 @@ function thematic_available_layout_slugs() {
*/
function thematic_default_theme_layout() {

$options = thematic_get_wp_opt( 'thematic_theme_opt' );

// use a default layout of right-sidebar if no theme option has been set
$thematic_default_layout = thematic_get_theme_opt( 'layout' ) ? thematic_get_theme_opt( 'layout' ) : 'right-sidebar';
$thematic_default_layout = isset( $options['layout'] ) ? $options['layout'] : 'right-sidebar';

/**
* Filter for the default layout
Expand Down
46 changes: 19 additions & 27 deletions library/extensions/theme-options.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,20 @@ function thematic_opt_init() {
$current_options = thematic_get_wp_opt('thematic_theme_opt');
$legacy_options = thematic_convert_legacy_opt();

// If no current settings exist
if ( false === $current_options ) {
// Check for legacy options
if ( false !== ( $legacy_options ) ) {
// Theme upgrade: Convert legacy to current format and add to database
add_option( 'thematic_theme_opt', $legacy_options );
} else {
// Fresh theme installation: Add default settings to database
add_option( 'thematic_theme_opt', thematic_default_opt() );
}

// Check for pre-1.0 options
if ( false !== ( $legacy_options ) ) {
// Theme upgrade: Convert legacy to current format and add to database
add_option( 'thematic_theme_opt', $legacy_options );
}


// If we are missing a 2.0 option, this is an upgrade from previous version
if ( !isset( $current_options['layout'] ) && isset( $current_options['footer_txt'] ) ) {
$thematic_upgrade_opt = array(
'index_insert' => 2,
'author_info' => 0, // 0 = not checked 1 = checked
'footer_txt' => 'Powered by [wp-link]. Built on the [theme-link].',
'del_legacy_opt'=> 0, // 0 = not checked 1 = check
'legacy_xhtml' => 1, // 0 = not checked 1 = check
'layout' => thematic_default_theme_layout()
);
update_option( 'thematic_theme_opt', $thematic_upgrade_opt );
$current_options = wp_parse_args( $current_options, thematic_default_opt() );
// enable xhtml mode by default on theme upgrades
$current_options['legacy_xhtml'] = 1;
update_option( 'thematic_theme_opt', $current_options );
}

register_setting ('thematic_opt_group', 'thematic_theme_opt', 'thematic_validate_opt');
Expand Down Expand Up @@ -115,17 +106,18 @@ function thematic_get_wp_opt( $option_name, $default = false ) {
*/
function thematic_get_theme_opt( $opt_key, $echo = false ) {

$theme_opt = thematic_get_wp_opt( 'thematic_theme_opt' );
$theme_opt = wp_parse_args( thematic_get_wp_opt( 'thematic_theme_opt', array() ), thematic_default_opt() );

if ( isset( $theme_opt[$opt_key] ) ) {
if ( false === $echo ) {
return $theme_opt[$opt_key] ;
} else {
echo $theme_opt[$opt_key];
}
} else {
if ( !isset( $theme_opt[$opt_key] ) ) {
return false;
}

if ( false === $echo ) {
return $theme_opt[$opt_key];
} else {
echo $theme_opt[$opt_key];
}

}


Expand Down

0 comments on commit 5ab1c5d

Please sign in to comment.