diff --git a/src/Admin/Provisioning.php b/src/Admin/Provisioning.php index be43b464..209d7229 100644 --- a/src/Admin/Provisioning.php +++ b/src/Admin/Provisioning.php @@ -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 ); diff --git a/src/Admin/Upgrades.php b/src/Admin/Upgrades.php index b88678c4..5f31c5f1 100644 --- a/src/Admin/Upgrades.php +++ b/src/Admin/Upgrades.php @@ -28,7 +28,7 @@ class Upgrades { * @return void */ public function __construct() { - add_action( 'init', [ $this, 'register_routines' ] ); + add_action( 'init', [ $this, 'run' ] ); } /** @@ -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`. diff --git a/src/Client.php b/src/Client.php index 3347f385..ff61f152 100644 --- a/src/Client.php +++ b/src/Client.php @@ -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