Skip to content

Commit

Permalink
Changing order that embedded config is applied.
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Adams committed May 11, 2020
1 parent 25948a4 commit 1074e5d
Showing 1 changed file with 35 additions and 29 deletions.
64 changes: 35 additions & 29 deletions wp_plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,18 +189,17 @@ private function initOptions() {
$this->options = array_merge($this->options, $user_defaults);
}


// needed for backwards compatability of old style embedded installs.
// must go after user default merge
$this->setEmbeddedOptions();

// fetch plugin options from DB and combine them with defaults.
$options = get_option( 'owa_wp' );
//echo 'options from DB: '. print_r( $options, true );
if ( $options ) {

$this->options = array_merge($this->options, $options);
}

// needed for backwards compatability of old style embedded installs.
// must go after user default merge
$this->setEmbeddedOptions();
}

/**
Expand Down Expand Up @@ -410,7 +409,9 @@ function isOwaAvailable() {

if ( $this->getOption( 'owaPath' ) ) {

return true;
$owa = owa_wp_plugin::getOwaInstance();

return $owa->isOwaInstalled();
}

}
Expand Down Expand Up @@ -799,7 +800,7 @@ function trackFeedRequest() {
// backward compatability for old style embedded installs.
private function setEmbeddedOptions() {

// check for presense of OWA in same directory.
// check for presence of OWA in same directory.
// used by isOwaAvailable method.
$path = plugin_dir_path(__FILE__) ;

Expand All @@ -814,8 +815,13 @@ private function setEmbeddedOptions() {
$this->setOption('trackAdminActions', true);

$owa = self::getOwaInstance();
$cu = owa_coreAPI::getCurrentUser();
$this->setOption('apiKey', $cu->getUserData('api_key') );

if ( ! $this->getOption('apiKey') ) {

$cu = owa_coreAPI::getCurrentUser();
$this->setOption('apiKey', $cu->getUserData('api_key') );
}

$this->setOption('owaEndpoint', $owa->getSetting('base', 'public_url') );

// set site iD, if not already set from the DB
Expand Down Expand Up @@ -1143,29 +1149,29 @@ public static function getOwaInstance() {

// create owa instance w/ config
$owa = new owa_php();
$owa->setSiteId( self::generateSiteId() );
//$owa->setSetting( 'base', 'report_wrapper', 'wrapper_wordpress.tpl' );
//$owa->setSetting( 'base', 'link_template', '%s&%s' );
//$owa->setSetting( 'base', 'main_url', '../wp-admin/admin.php?page=owa-analytics' );
//$owa->setSetting( 'base', 'main_absolute_url', get_bloginfo('url').'/wp-admin/admin.php?page=owa-analytics' );

//$owa->setSetting( 'base', 'rest_api_url', $owa->getSetting( 'base', 'rest_api_url' ).'?');
$owa->setSetting( 'base', 'is_embedded', true );
if ( $owa->isOwaInstalled() ) {

$current_user = wp_get_current_user();
owa_coreAPI::debug( 'get owa instance curent user obj' );
owa_coreAPI::debug( 'WordPrerss login: '.$current_user->user_login );
if ( $current_user->user_login ) {
owa_coreAPI::debug('loading OWA current user');
$cu = owa_coreAPI::getCurrentUser();
$cu->load( $current_user->user_login );
}
$owa->setSiteId( self::generateSiteId() );

$owa->setSetting( 'base', 'is_embedded', true );

// register allowedSitesList filter
$dispatch = owa_coreAPI::getEventDispatch();
// alternative auth method, sets auth status, role, and allowed sites list.
$dispatch->attachFilter('auth_status', 'owa_wp_plugin::wpAuthUser', 0);

$current_user = wp_get_current_user();
owa_coreAPI::debug( 'get owa instance curent user obj' );
owa_coreAPI::debug( 'WordPress login: '.$current_user->user_login );
if ( $current_user->user_login ) {


owa_coreAPI::debug('loading OWA current user');
$cu = owa_coreAPI::getCurrentUser();
$cu->load( $current_user->user_login );
}

// register allowedSitesList filter
$dispatch = owa_coreAPI::getEventDispatch();
// alternative auth method, sets auth status, role, and allowed sites list.
$dispatch->attachFilter('auth_status', 'owa_wp_plugin::wpAuthUser', 0);
}
}

return $owa;
Expand Down

0 comments on commit 1074e5d

Please sign in to comment.