Skip to content

Commit

Permalink
Don't attempt run auto-provisioning action hooks if an API token is n…
Browse files Browse the repository at this point in the history
…ot yet provided.
  • Loading branch information
Dan0sz committed Jan 24, 2024
1 parent e99863b commit 2c59953
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/Admin/Provisioning.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ public function __construct() {
* @return void
*/
private function init() {
if ( ! $this->client->check_password() ) {
return;
}

add_action( 'update_option_plausible_analytics_settings', [ $this, 'create_shared_link' ], 10, 2 );
add_action( 'update_option_plausible_analytics_settings', [ $this, 'create_goals' ], 10, 2 );
add_action( 'update_option_plausible_analytics_settings', [ $this, 'maybe_delete_goals' ], 11, 2 );
Expand Down
4 changes: 2 additions & 2 deletions src/Admin/Upgrades.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Upgrades {
* @return void
*/
public function __construct() {
add_action( 'init', [ $this, 'register_routines' ] );
add_action( 'init', [ $this, 'run' ] );
}

/**
Expand All @@ -38,7 +38,7 @@ public function __construct() {
* @access public
* @return void
*/
public function register_routines() {
public function run() {
$plausible_analytics_version = get_option( 'plausible_analytics_version' );

// If version doesn't exist, then consider it `1.0.0`.
Expand Down
10 changes: 10 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ public function __construct() {
$this->api_instance = new DefaultApi( new GuzzleClient(), $config );
}

/**
* Checks if a password is set. It doesn't validate the password!
* @return bool
*/
public function check_password() {
$password = $this->api_instance->getConfig()->getPassword();

return ! empty( $password );
}

/**
* Create Shared Link in Plausible Dashboard.
* @return void
Expand Down

0 comments on commit 2c59953

Please sign in to comment.