diff --git a/inc/update.php b/inc/update.php index 91910f7d5..2d3a6d906 100644 --- a/inc/update.php +++ b/inc/update.php @@ -16,16 +16,36 @@ */ function largo_activation_maybe_setup() { var_log( "Should setup be done?" ); - if ( of_get_option( 'largo_version' ) ) { - var_log( "No."); + if ( of_get_option( 'largo_version', false ) ) { return false; } - var_log( "Yes."); + + // We must make sure some things are enqueued first in order to run these functions + $requires = array( + // included for the definition of the defaults in optionsframework_options() + '/options.php', + ); + // after_switch_theme appears to run before after_setup_theme, which is what calls Largo::get_instance calls Largo::load calls Largo::require_files + foreach ( $requires as $required ) { + require_once( get_template_directory() . $required ); + } + + // We assume here that since this action runs on after_switch_theme, + // and since switching themes requires admin privileges, + // that this user has the permissions to run optionsframework_init + // @see optionsframework_rolescheck() in lib/options-framework/options-framework.php + if ( current_user_can( 'edit_theme_options' ) ) { + optionsframework_init(); + } // this must run before any other function that makes use of of_set_option() largo_set_new_option_defaults(); - of_set_option( 'largo_version', largo_version() ); + var_log( "if this returns false it is because there is no get_option( 'optionsframework' )" ); + var_log( of_set_option( 'largo_version', largo_version() ) ); + + var_log( get_option( 'optionsframework' ) ); + var_log( largo_version() ); return true; } add_action( 'after_switch_theme', 'largo_activation_maybe_setup' ); @@ -101,6 +121,8 @@ function largo_need_updates() { // try to figure out which versions of the options are stored. Implemented in 0.3 if ( of_get_option( 'largo_version' ) ) { $compare = version_compare( largo_version(), of_get_option( 'largo_version' ) ); + var_log( largo_version() ); + var_log( of_get_option( 'largo_version' ) ); if ( $compare == 1 ) { return true; } else { diff --git a/options.php b/options.php index 729784b51..9d481dc09 100644 --- a/options.php +++ b/options.php @@ -589,9 +589,12 @@ function optionsframework_options() { 'class' => 'hidden'); - $screen = get_current_screen(); - if ( is_object( $screen ) && $screen->base == 'widgets' ) { - return $widget_options; + // this is wrapped in a function_exists because optionsframework_options is called during after_switch_theme, which is not yet an admin screen, so the function is not defined + if ( function_exists( 'get_current_screen' ) ) { + $screen = get_current_screen(); + if ( is_object( $screen ) && $screen->base == 'widgets' ) { + return $widget_options; + } }