PluginProbe
ووسلام – همگام سازی ووکامرس و باسلام / 1.10.22
ووسلام – همگام سازی ووکامرس و باسلام v1.10.22
1.10.22 1.10.21 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 All 55 releases
← All changes | includes/Admin/Settings/SettingsPageHandler.php +59 -8 1.8.8 → 1.10.22 View file →
@@ -5,39 +5,90 @@
5 5 use SyncBasalam\Queue\Tasks\Debug;
6 6 use SyncBasalam\Actions\Controller\ProductActions\CancelDebug;
7 7 use SyncBasalam\Services\WebhookService;
8 8 use SyncBasalam\Services\VendorInfoService;
9 +use SyncBasalam\Services\ScheduledProductSync;
9 10
10 11 defined('ABSPATH') || exit;
11 12
12 13 class SettingsPageHandler
13 14 {
15 + private const VALIDATION_ERROR_TRANSIENT_PREFIX = 'sync_basalam_settings_validation_error_';
16 +
14 17 public static function saveSettings()
15 18 {
16 19 $data = isset($_POST['sync_basalam_settings']) ? array_map('sanitize_text_field', wp_unslash($_POST['sync_basalam_settings'])) : [];
17 20
18 21 if ($data) {
22 + if (!SettingsManager::isProductUpdateSelectionValid($data)) {
23 + self::pushValidationError(SettingsConfig::CUSTOM_PRODUCT_UPDATE_REQUIRED_MESSAGE);
24 + return false;
25 + }
26 +
19 27 SettingsManager::updateSettings($data);
20 28
21 - if (!empty($data[SettingsConfig::DEVELOPER_MODE]) && $data[SettingsConfig::DEVELOPER_MODE] === 'true') {
22 - $debugTask = new Debug();
23 - $debugTask->schedule();
24 - } else {
25 - (new CancelDebug())();
29 + if (array_key_exists(SettingsConfig::AUTO_FULL_UPDATE_INTERVAL, $data)) {
30 + (new ScheduledProductSync())->ensureScheduled();
26 31 }
32 +
33 + if (array_key_exists(SettingsConfig::DEVELOPER_MODE, $data)) {
34 + if ($data[SettingsConfig::DEVELOPER_MODE] === 'true') {
35 + $debugTask = new Debug();
36 + $debugTask->schedule();
37 + } else {
38 + (new CancelDebug())();
39 + }
40 + }
27 41 }
28 42
29 43 if (isset($_POST['get_token']) && $_POST['get_token'] == 1) {
30 44 self::redirectToOAuth();
31 45 }
46 +
47 + return true;
32 48 }
33 49
50 + public static function pullValidationError(): string
51 + {
52 + $userId = get_current_user_id();
53 + if ($userId <= 0) return '';
54 +
55 + $key = self::VALIDATION_ERROR_TRANSIENT_PREFIX . $userId;
56 + $message = get_transient($key);
57 + delete_transient($key);
58 +
59 + return is_string($message) ? $message : '';
60 + }
61 +
62 + private static function pushValidationError(string $message): void
63 + {
64 + $userId = get_current_user_id();
65 + if ($userId <= 0) return;
66 +
67 + set_transient(
68 + self::VALIDATION_ERROR_TRANSIENT_PREFIX . $userId,
69 + wp_strip_all_tags($message),
70 + 2 * MINUTE_IN_SECONDS
71 + );
72 + }
73 +
34 74 private static function redirectToOAuth()
35 75 {
36 76 $OAuthManger = new OAuthManager();
37 77 $oauthUrls = $OAuthManger->getOAuthUrls();
38 78
39 - wp_redirect($oauthUrls['url_req_token']);
79 + // Mark this authorization as started by the current (authenticated) admin
80 + // so the OAuth callback can reject forged requests. This runs only after
81 + // the nonce-protected settings POST, so it cannot be triggered cross-site.
82 + if (! OAuthManager::issueOauthState()) {
83 + wp_die(
84 + esc_html__('امکان شروع فرایند دریافت دسترسی وجود ندارد. لطفاً دوباره تلاش کنید.', 'sync-basalam'),
85 + esc_html__('خطای دریافت دسترسی', 'sync-basalam'),
86 + ['response' => 500]
87 + );
88 + }
89 +
90 + wp_redirect($oauthUrls['url_req_token']); // phpcs:ignore WordPress.Security.SafeRedirect.wp_redirect_wp_redirect -- Intentional external/user-provided redirect.
40 91 exit();
41 92 }
42 93
43 94 public static function handleOauthCallback()
@@ -53,11 +104,11 @@
53 104
54 105 $onboardingCompleted = get_option('sync_basalam_onboarding_completed');
55 106
56 107 if (!$onboardingCompleted) {
57 - wp_redirect(admin_url('admin.php?page=basalam-onboarding&step=3'));
108 + wp_safe_redirect(admin_url('admin.php?page=basalam-onboarding&step=3'));
58 109 } else {
59 - wp_redirect(admin_url('admin.php?page=sync_basalam'));
110 + wp_safe_redirect(admin_url('admin.php?page=sync_basalam'));
60 111 }
61 112 exit();
62 113 }
63 114 }