Abandoned
1 month ago
AffiliationClicks
1 month ago
AffiliationPayoutGroups
2 years ago
AffiliationPayouts
9 months ago
AffiliationReferrals
6 months ago
AffiliationRequests
1 month ago
Affiliations
1 month ago
AutoFees
1 month ago
Bumps
1 month ago
CancellationInsights
1 month ago
Cart
3 years ago
Checkouts
2 months ago
Coupons
2 months ago
Customers
1 month ago
Dashboard
9 months ago
Invoices
1 month ago
Learn
2 months ago
Licenses
1 month ago
Onboarding
10 months ago
Orders
1 month ago
ProductCollections
1 year ago
ProductGroups
1 year ago
Products
1 month ago
Restore
2 years ago
Reviews
1 month ago
Settings
3 weeks ago
Subscriptions
1 month ago
Tables
4 months ago
Upsells
1 month ago
.gitkeep
3 years ago
Account.php
3 years ago
AdminController.php
9 months ago
PluginSettings.php
3 years ago
PluginSettings.php
50 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SureCart\Controllers\Admin; |
| 4 | |
| 5 | use SureCart\Models\ApiToken; |
| 6 | |
| 7 | /** |
| 8 | * Handles the plugin settings page. |
| 9 | */ |
| 10 | class PluginSettings { |
| 11 | /** |
| 12 | * Show the page. |
| 13 | * |
| 14 | * @param \SureCartCore\Requests\RequestInterface $request Request. |
| 15 | * @return function |
| 16 | */ |
| 17 | public function show( \SureCartCore\Requests\RequestInterface $request ) { |
| 18 | return \SureCart::view( 'admin/plugin' )->with( |
| 19 | [ |
| 20 | 'api_token' => ApiToken::get(), |
| 21 | 'uninstall' => get_option( 'sc_uninstall', false ), |
| 22 | 'use_esm_loader' => get_option( 'surecart_use_esm_loader', false ), |
| 23 | 'status' => $request->query( 'status' ), |
| 24 | ] |
| 25 | ); |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * Save the page. |
| 30 | * |
| 31 | * @param \SureCartCore\Requests\RequestInterface $request Request. |
| 32 | * @return function |
| 33 | */ |
| 34 | public function save( \SureCartCore\Requests\RequestInterface $request ) { |
| 35 | $url = $request->getHeaderLine( 'Referer' ); |
| 36 | $api_token = $request->body( 'api_token' ); |
| 37 | |
| 38 | // update uninstall option. |
| 39 | update_option( 'sc_uninstall', $request->body( 'uninstall' ) === 'on' ); |
| 40 | |
| 41 | // update uninstall option. |
| 42 | update_option( 'surecart_use_esm_loader', $request->body( 'use_esm_loader' ) === 'on' ); |
| 43 | |
| 44 | // save token. |
| 45 | ApiToken::save( $api_token ); |
| 46 | |
| 47 | return \SureCart::redirect()->to( esc_url_raw( add_query_arg( 'status', 'saved', $url ) ) ); |
| 48 | } |
| 49 | } |
| 50 |