PluginProbe
ووسلام – همگام سازی ووکامرس و باسلام / 1.10.7
ووسلام – همگام سازی ووکامرس و باسلام v1.10.7
1.10.19 1.10.20 1.10.18 1.10.17 1.10.15 1.10.14 1.10.13 1.10.12 1.10.10 1.10.9 1.10.8 1.10.7 1.10.6 1.10.5 1.10.4 1.10.3 1.10.2 1.10.1 1.10.0 1.9.2 1.9.1 1.9.0 1.8.8 1.8.5 1.8.6 All 53 releases
sync-basalam / includes / Admin / Settings / SettingsPageHandler.php

SettingsPageHandler.php in ووسلام – همگام سازی ووکامرس و باسلام 1.10.7, at includes/Admin/Settings/SettingsPageHandler.php

69 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace SyncBasalam\Admin\Settings;
4
5 use SyncBasalam\Queue\Tasks\Debug;
6 use SyncBasalam\Actions\Controller\ProductActions\CancelDebug;
7 use SyncBasalam\Services\WebhookService;
8 use SyncBasalam\Services\VendorInfoService;
9
10 defined('ABSPATH') || exit;
11
12 class SettingsPageHandler
13 {
14 public static function saveSettings()
15 {
16 $data = isset($_POST['sync_basalam_settings']) ? array_map('sanitize_text_field', wp_unslash($_POST['sync_basalam_settings'])) : [];
17
18 if ($data) {
19 SettingsManager::updateSettings($data);
20
21 if (!empty($data[SettingsConfig::DEVELOPER_MODE]) && $data[SettingsConfig::DEVELOPER_MODE] === 'true') {
22 $debugTask = new Debug();
23 $debugTask->schedule();
24 } else {
25 (new CancelDebug())();
26 }
27 }
28
29 if (isset($_POST['get_token']) && $_POST['get_token'] == 1) {
30 self::redirectToOAuth();
31 }
32 }
33
34 private static function redirectToOAuth()
35 {
36 $OAuthManger = new OAuthManager();
37 $oauthUrls = $OAuthManger->getOAuthUrls();
38
39 // Mark this authorization as started by the current (authenticated) admin
40 // so the OAuth callback can reject forged requests. This runs only after
41 // the nonce-protected settings POST, so it cannot be triggered cross-site.
42 OAuthManager::issueOauthState();
43
44 wp_redirect($oauthUrls['url_req_token']); // phpcs:ignore WordPress.Security.SafeRedirect.wp_redirect_wp_redirect -- Intentional external/user-provided redirect.
45 exit();
46 }
47
48 public static function handleOauthCallback()
49 {
50 $oauthSaved = OAuthManager::saveOauthData();
51
52 if ($oauthSaved) {
53 $webhookService = new WebhookService();
54 $webhookService->setupWebhook();
55 $vendorInfoService = new VendorInfoService();
56 $vendorInfoService->FetchVendorInfo();
57 }
58
59 $onboardingCompleted = get_option('sync_basalam_onboarding_completed');
60
61 if (!$onboardingCompleted) {
62 wp_safe_redirect(admin_url('admin.php?page=basalam-onboarding&step=3'));
63 } else {
64 wp_safe_redirect(admin_url('admin.php?page=sync_basalam'));
65 }
66 exit();
67 }
68 }
69