From 719959157841066c9e20735555f93ae7748f0cd4 Mon Sep 17 00:00:00 2001 From: Halil Beycan <50718965+BeycanDeveloper@users.noreply.github.com> Date: Sun, 7 May 2023 13:50:31 +0300 Subject: [PATCH] added some setting and fixed miss debug problem --- app/Loader.php | 6 ++++-- app/Settings.php | 15 ++++++++++++++- vendor/beycanpress/freshbooks/src/Connection.php | 10 ++++++++++ 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/app/Loader.php b/app/Loader.php index 434db32..cc4e475 100644 --- a/app/Loader.php +++ b/app/Loader.php @@ -34,7 +34,7 @@ public function __construct($pluginFile) home_url('/wp-json/wcfb/get-access-token') ); - if ($authenticate) { + if ($authenticate && file_exists($this->conn->getTokenFile())) { $this->conn->refreshAuthentication(); $this->updateSetting('connected', true); $this->conn->setAccount($this->setting('account')); @@ -55,7 +55,9 @@ public function __construct($pluginFile) } }); - new WooCommerce(); + if ($this->setting('createInvoice')) { + new WooCommerce(); + } } public function adminProcess() : void diff --git a/app/Settings.php b/app/Settings.php index 441868b..8154f89 100644 --- a/app/Settings.php +++ b/app/Settings.php @@ -11,6 +11,11 @@ public function __construct() parent::__construct(esc_html__('WC FreshBooks Settings', 'wcfb')); $conn = $this->callFunc('initFbConnection', true); + if (isset($_GET['disconnect'])) { + $conn->deleteTokenFile(); + $this->updateSetting('connected', false); + $this->redirect(admin_url('admin.php?page=wcfb_settings')); + } $accounts = []; if ($conn && $this->setting('connected')) { @@ -56,7 +61,8 @@ public function __construct() 'id' => 'connectedStatus', 'title' => esc_html__('Connect', 'wcfb'), 'type' => 'content', - 'content' => '' . esc_html__('Connected', 'wcfb') . '', + 'content' => '' . esc_html__('Connected', 'wcfb') . '
+ ' . esc_html__('Disconnect', 'wcfb') . '', 'dependency' => array('connected', '==', true) ), array( @@ -82,6 +88,13 @@ public function __construct() 'title' => esc_html__('Invoice settings', 'wcfb'), 'icon' => 'fas fa-file-alt', 'fields' => array( + array( + 'id' => 'createInvoice', + 'title' => esc_html__('Create invoice', 'wcfb'), + 'type' => 'switcher', + 'default' => false, + 'help' => esc_html__('If you want create invoice for order, you can enable this setting.', 'wcfb') + ), array( 'id' => 'sendToEmail', 'title' => esc_html__('Send to email', 'wcfb'), diff --git a/vendor/beycanpress/freshbooks/src/Connection.php b/vendor/beycanpress/freshbooks/src/Connection.php index 34b1298..a70dbaa 100644 --- a/vendor/beycanpress/freshbooks/src/Connection.php +++ b/vendor/beycanpress/freshbooks/src/Connection.php @@ -115,6 +115,16 @@ public function getTokenFile() : string return $this->tokenFile; } + /** + * @return void + */ + public function deleteTokenFile() + { + if (file_exists($this->tokenFile)) { + unlink($this->tokenFile); + } + } + /** * @return object|null */