Skip to content

Commit

Permalink
added some setting and fixed miss debug problem
Browse files Browse the repository at this point in the history
  • Loading branch information
BeycanDeveloper committed May 7, 2023
1 parent 500e576 commit 7199591
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
6 changes: 4 additions & 2 deletions app/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand All @@ -55,7 +55,9 @@ public function __construct($pluginFile)
}
});

new WooCommerce();
if ($this->setting('createInvoice')) {
new WooCommerce();
}
}

public function adminProcess() : void
Expand Down
15 changes: 14 additions & 1 deletion app/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand Down Expand Up @@ -56,7 +61,8 @@ public function __construct()
'id' => 'connectedStatus',
'title' => esc_html__('Connect', 'wcfb'),
'type' => 'content',
'content' => '<span class="connected-status">' . esc_html__('Connected', 'wcfb') . '</span>',
'content' => '<span class="connected-status">' . esc_html__('Connected', 'wcfb') . '</span><br>
<a href="'.$this->getCurrentUrl().'&disconnect=1" class="disconnect-from-freshbooks">' . esc_html__('Disconnect', 'wcfb') . '</a>',
'dependency' => array('connected', '==', true)
),
array(
Expand All @@ -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'),
Expand Down
10 changes: 10 additions & 0 deletions vendor/beycanpress/freshbooks/src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit 7199591

Please sign in to comment.