Skip to content

Commit

Permalink
Working post-activate-largo activation of the options framework
Browse files Browse the repository at this point in the history
  • Loading branch information
benlk committed Oct 24, 2016
1 parent a3034dd commit 87553a9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
30 changes: 26 additions & 4 deletions inc/update.php
Expand Up @@ -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' );
Expand Down Expand Up @@ -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 {
Expand Down
9 changes: 6 additions & 3 deletions options.php
Expand Up @@ -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;
}
}


Expand Down

0 comments on commit 87553a9

Please sign in to comment.