PluginProbe
ووسلام – همگام سازی ووکامرس و باسلام / 1.10.21
ووسلام – همگام سازی ووکامرس و باسلام v1.10.21
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 1.8.5 All 54 releases
← All changes | includes/Registrar/AdminRegistrar.php +329 -112 1.10.61.10.21 View file →
@@ -23,8 +23,10 @@
23 23 use SyncBasalam\Services\Products\ProductConnection;
24 24 use SyncBasalam\Services\SystemResourceMonitor;
25 25 use SyncBasalam\Utilities\ProductMetaKey;
26 26 use SyncBasalam\Utilities\ChatWidget;
27 +use SyncBasalam\Utilities\TicketFlashNotice;
28 +use SyncBasalam\Admin\Settings\SettingsPageHandler;
27 29 use SyncBasalam\Admin\FinancialManagement\Menu as FinancialManagementMenu;
28 30 use SyncBasalam\Admin\FinancialManagement\BalanceSettlement;
29 31 use SyncBasalam\Admin\FinancialManagement\FinancialManagementHistory;
30 32
@@ -196,10 +198,132 @@
196 198 {
197 199 return plugin_dir_url(dirname(__FILE__, 2)) . "assets/" . $path;
198 200 }
199 201
202 + public static function isWoosalamRelatedAdminScreen($hook = ''): bool
203 + {
204 + return self::isPluginAdminPage($hook)
205 + || self::isProductAdminScreen($hook)
206 + || self::isOrderAdminScreen($hook);
207 + }
208 +
209 + private static function isPluginAdminPage($hook = ''): bool
210 + {
211 + $page = self::currentAdminPage();
212 +
213 + if ($page !== '' && in_array($page, self::pluginAdminPages(), true)) {
214 + return true;
215 + }
216 +
217 + return is_string($hook) && strpos($hook, 'sync_basalam') !== false;
218 + }
219 +
220 + private static function isProductAdminScreen($hook = ''): bool
221 + {
222 + $screen = function_exists('get_current_screen') ? get_current_screen() : null;
223 +
224 + if ($screen && isset($screen->post_type) && $screen->post_type === 'product') {
225 + return true;
226 + }
227 +
228 + $postType = isset($_GET['post_type']) ? sanitize_key(wp_unslash($_GET['post_type'])) : '';
229 + if ($postType === 'product') {
230 + return true;
231 + }
232 +
233 + $postId = isset($_GET['post']) ? absint($_GET['post']) : 0;
234 + if ($postId > 0 && function_exists('get_post_type') && get_post_type($postId) === 'product') {
235 + return true;
236 + }
237 +
238 + return in_array((string) $hook, ['edit-product', 'product'], true);
239 + }
240 +
241 + private static function isOrderAdminScreen($hook = ''): bool
242 + {
243 + $screen = function_exists('get_current_screen') ? get_current_screen() : null;
244 +
245 + if ($screen) {
246 + $screenId = isset($screen->id) ? (string) $screen->id : '';
247 + $postType = isset($screen->post_type) ? (string) $screen->post_type : '';
248 +
249 + if ($postType === 'shop_order' || $screenId === 'woocommerce_page_wc-orders') {
250 + return true;
251 + }
252 + }
253 +
254 + $page = self::currentAdminPage();
255 + if ($page === 'wc-orders') {
256 + return true;
257 + }
258 +
259 + $postType = isset($_GET['post_type']) ? sanitize_key(wp_unslash($_GET['post_type'])) : '';
260 + if ($postType === 'shop_order') {
261 + return true;
262 + }
263 +
264 + $postId = isset($_GET['post']) ? absint($_GET['post']) : 0;
265 + if ($postId > 0 && function_exists('get_post_type') && get_post_type($postId) === 'shop_order') {
266 + return true;
267 + }
268 +
269 + return in_array((string) $hook, ['edit-shop_order', 'shop_order', 'woocommerce_page_wc-orders'], true);
270 + }
271 +
272 + private static function isProductEditScreen($hook = ''): bool
273 + {
274 + $screen = function_exists('get_current_screen') ? get_current_screen() : null;
275 +
276 + if ($screen && isset($screen->post_type, $screen->base)) {
277 + return $screen->post_type === 'product' && in_array($screen->base, ['post', 'post-new'], true);
278 + }
279 +
280 + return self::isProductAdminScreen($hook) && in_array((string) $hook, ['post.php', 'post-new.php', 'product'], true);
281 + }
282 +
283 + private static function isPluginPage(string $page): bool
284 + {
285 + return self::currentAdminPage() === $page;
286 + }
287 +
288 + private static function isTicketPage(): bool
289 + {
290 + return in_array(self::currentAdminPage(), [
291 + 'sync_basalam_tickets',
292 + 'sync_basalam_ticket',
293 + 'sync_basalam_new_ticket',
294 + ], true);
295 + }
296 +
297 + private static function currentAdminPage(): string
298 + {
299 + return isset($_GET['page']) ? sanitize_key(wp_unslash($_GET['page'])) : '';
300 + }
301 +
302 + private static function pluginAdminPages(): array
303 + {
304 + return [
305 + 'sync_basalam',
306 + 'sync_basalam_logs',
307 + 'sync_basalam_vendor_info',
308 + 'sync_basalam_help',
309 + 'sync_basalam_category_mapping',
310 + FinancialManagementMenu::PAGE_SLUG,
311 + 'basalam-onboarding',
312 + 'basalam-save-token',
313 + 'basalam-show-products',
314 + 'sync_basalam_tickets',
315 + 'sync_basalam_ticket',
316 + 'sync_basalam_new_ticket',
317 + ];
318 + }
319 +
200 320 public static function adminEnqueueStyles($hook = '')
201 321 {
322 + if (!self::isWoosalamRelatedAdminScreen($hook)) {
323 + return;
324 + }
325 +
202 326 $version = syncbasalamplugin()->getVersion();
203 327
204 328 wp_enqueue_style(
205 329 "basalam-admin-style",
@@ -212,27 +336,35 @@
212 336 self::assetsUrl("css/font.css"),
213 337 array(),
214 338 $version
215 339 );
340 + if (self::isPluginPage('sync_basalam_vendor_info')) {
341 + wp_enqueue_style(
342 + "basalam-admin-social-style",
343 + self::assetsUrl("css/social.css"),
344 + array(),
345 + $version
346 + );
347 + }
348 +
349 + if (self::isPluginPage('sync_basalam_logs')) {
350 + wp_enqueue_style(
351 + "basalam-admin-logs-style",
352 + self::assetsUrl("css/logs.css"),
353 + array(),
354 + $version
355 + );
356 + }
357 +
358 + if (self::isPluginPage('basalam-onboarding')) {
359 + wp_enqueue_style(
360 + "basalam-admin-onboarding-style",
361 + self::assetsUrl("css/onboarding.css"),
362 + array(),
363 + $version
364 + );
365 + }
216 366 wp_enqueue_style(
217 - "basalam-admin-social-style",
218 - self::assetsUrl("css/social.css"),
219 - array(),
220 - $version
221 - );
222 - wp_enqueue_style(
223 - "basalam-admin-logs-style",
224 - self::assetsUrl("css/logs.css"),
225 - array(),
226 - $version
227 - );
228 - wp_enqueue_style(
229 - "basalam-admin-onboarding-style",
230 - self::assetsUrl("css/onboarding.css"),
231 - array(),
232 - $version
233 - );
234 - wp_enqueue_style(
235 367 "basalam-admin-toast-style",
236 368 self::assetsUrl("css/toast.css"),
237 369 array(),
238 370 $version
@@ -244,11 +376,33 @@
244 376 }
245 377
246 378 public static function adminEnqueueScripts($hook = '')
247 379 {
380 + $version = syncbasalamplugin()->getVersion();
381 +
382 + if (ChatWidget::shouldLoadWidget()) {
383 + wp_enqueue_script(
384 + "basalam-chat-widget-script",
385 + self::assetsUrl("chat/widget-loader.js"),
386 + [],
387 + $version,
388 + true
389 + );
390 + }
391 +
248 392 $shouldLoadPointerTour = PointerTour::shouldLoadPointerTour((string) $hook);
249 - $version = syncbasalamplugin()->getVersion();
393 + $shouldLoadAssets = self::isWoosalamRelatedAdminScreen($hook);
250 394
395 + if (!$shouldLoadAssets && !$shouldLoadPointerTour) {
396 + return;
397 + }
398 +
399 + $isPluginPage = self::isPluginAdminPage($hook);
400 + $isMainPage = self::isPluginPage('sync_basalam');
401 + $isProductScreen = self::isProductAdminScreen($hook);
402 + $isProductEditScreen = self::isProductEditScreen($hook);
403 + $isOrderScreen = self::isOrderAdminScreen($hook);
404 +
251 405 if ($shouldLoadPointerTour) {
252 406 wp_enqueue_script('wp-pointer');
253 407 }
254 408
@@ -258,117 +412,180 @@
258 412 [],
259 413 $version,
260 414 true
261 415 );
416 +
417 + $vendorStatusScriptPath = syncbasalamplugin()->pluginPath() . '/assets/js/vendor-status.js';
418 + $vendorStatusScriptVersion = file_exists($vendorStatusScriptPath)
419 + ? $version . '-' . filemtime($vendorStatusScriptPath)
420 + : $version;
262 421 wp_enqueue_script(
263 - "basalam-admin-logs-script",
264 - self::assetsUrl("js/logs.js"),
265 - ["jquery", "basalam-admin-toast-script"],
266 - $version,
422 + "basalam-vendor-status-script",
423 + self::assetsUrl("js/vendor-status.js"),
424 + ["basalam-admin-toast-script"],
425 + $vendorStatusScriptVersion,
267 426 true
268 427 );
269 - wp_enqueue_script(
270 - "basalam-admin-help-script",
271 - self::assetsUrl("js/help.js"),
272 - ["jquery", "basalam-admin-toast-script"],
273 - $version,
274 - true
275 - );
276 - wp_enqueue_script(
277 - "basalam-admin-product-fields-script",
278 - self::assetsUrl("js/product-fields.js"),
279 - ["jquery", "basalam-admin-toast-script"],
280 - $version,
281 - true
282 - );
283 - wp_enqueue_script(
284 - "basalam-admin-manage-box-script",
285 - self::assetsUrl("js/manage-box.js"),
286 - ["jquery", "basalam-admin-toast-script"],
287 - $version,
288 - true
289 - );
290 - wp_enqueue_script(
291 - "basalam-admin-connect-modal-script",
292 - self::assetsUrl("js/connect-modal.js"),
293 - ["jquery", "basalam-admin-toast-script"],
294 - $version,
295 - true
296 - );
297 - wp_enqueue_script(
298 - "basalam-round-script",
299 - self::assetsUrl("js/round.js"),
300 - ["jquery", "basalam-admin-toast-script"],
301 - $version,
302 - true
303 - );
304 - wp_enqueue_script(
305 - "basalam-get-category-script",
306 - self::assetsUrl("js/get-category.js"),
307 - ["jquery", "basalam-admin-toast-script"],
308 - $version,
309 - true
310 - );
311 - wp_enqueue_script(
312 - "basalam-order-script",
313 - self::assetsUrl("js/order.js"),
314 - ["jquery", "basalam-admin-toast-script"],
315 - $version,
316 - true
317 - );
318 - wp_enqueue_script(
319 - "basalam-admin-script",
320 - self::assetsUrl("js/admin.js"),
321 - $shouldLoadPointerTour ? ["jquery", "wp-pointer", "basalam-admin-toast-script"] : ["jquery", "basalam-admin-toast-script"],
322 - $version,
323 - true
324 - );
325 - wp_enqueue_script(
326 - "basalam-check-sync-script",
327 - self::assetsUrl("js/check-sync.js"),
328 - ["jquery", "basalam-admin-toast-script"],
329 - $version,
330 - true
331 - );
332 - wp_enqueue_script(
333 - "basalam-map-category-option-script",
334 - self::assetsUrl("js/map-category-option.js"),
335 - ["jquery", "basalam-admin-toast-script"],
336 - $version,
337 - true
338 - );
339 428
340 - wp_enqueue_script(
341 - "basalam-generate-product-variation-script",
342 - self::assetsUrl("js/generate-product-variation.js"),
343 - ["jquery", "basalam-admin-toast-script"],
344 - $version,
345 - true
346 - );
429 + $ticketNotice = TicketFlashNotice::pull();
430 + if ($ticketNotice !== null) {
431 + wp_add_inline_script(
432 + "basalam-admin-toast-script",
433 + sprintf(
434 + 'window.addEventListener("DOMContentLoaded",function(){if(window.BasalamToast){window.BasalamToast.show(%s,%s);}});',
435 + wp_json_encode($ticketNotice['message'], JSON_UNESCAPED_UNICODE),
436 + wp_json_encode($ticketNotice['type'])
437 + ),
438 + 'after'
439 + );
440 + }
347 441
348 - wp_enqueue_script(
349 - "basalam-ticket-script",
350 - self::assetsUrl("js/ticket.js"),
351 - ["basalam-admin-toast-script"],
352 - $version,
353 - true
354 - );
442 + $settingsValidationError = SettingsPageHandler::pullValidationError();
443 + if ($settingsValidationError !== '') {
444 + wp_add_inline_script(
445 + "basalam-admin-toast-script",
446 + sprintf(
447 + 'window.addEventListener("DOMContentLoaded",function(){if(window.BasalamToast){window.BasalamToast.error(%s);}});',
448 + wp_json_encode($settingsValidationError, JSON_UNESCAPED_UNICODE)
449 + ),
450 + 'after'
451 + );
452 + }
355 453
356 - if (ChatWidget::shouldLoadWidget()) {
454 + if (self::isPluginPage('sync_basalam_logs')) {
357 455 wp_enqueue_script(
358 - "basalam-chat-widget-script",
359 - self::assetsUrl("chat/widget-loader.js"),
360 - [],
456 + "basalam-admin-logs-script",
457 + self::assetsUrl("js/logs.js"),
458 + ["jquery", "basalam-admin-toast-script"],
361 459 $version,
362 460 true
363 461 );
364 462 }
365 463
464 + if (self::isPluginPage('sync_basalam_help')) {
465 + wp_enqueue_script(
466 + "basalam-admin-help-script",
467 + self::assetsUrl("js/help.js"),
468 + ["jquery", "basalam-admin-toast-script"],
469 + $version,
470 + true
471 + );
472 + }
473 +
474 + if ($isProductEditScreen) {
475 + wp_enqueue_script(
476 + "basalam-admin-product-fields-script",
477 + self::assetsUrl("js/product-fields.js"),
478 + ["jquery", "basalam-admin-toast-script"],
479 + $version,
480 + true
481 + );
482 + wp_enqueue_script(
483 + "basalam-admin-connect-modal-script",
484 + self::assetsUrl("js/connect-modal.js"),
485 + ["jquery", "basalam-admin-toast-script"],
486 + $version,
487 + true
488 + );
489 + wp_enqueue_script(
490 + "basalam-get-category-script",
491 + self::assetsUrl("js/get-category.js"),
492 + ["jquery", "basalam-admin-toast-script"],
493 + $version,
494 + true
495 + );
496 + wp_enqueue_script(
497 + "basalam-generate-product-variation-script",
498 + self::assetsUrl("js/generate-product-variation.js"),
499 + ["jquery", "basalam-admin-toast-script"],
500 + $version,
501 + true
502 + );
503 + }
504 +
505 + if ($isMainPage || $isProductEditScreen) {
506 + wp_enqueue_script(
507 + "basalam-admin-manage-box-script",
508 + self::assetsUrl("js/manage-box.js"),
509 + ["jquery", "basalam-admin-toast-script"],
510 + $version,
511 + true
512 + );
513 + }
514 +
515 + if ($isMainPage) {
516 + wp_enqueue_script(
517 + "basalam-map-category-option-script",
518 + self::assetsUrl("js/map-category-option.js"),
519 + ["jquery", "basalam-admin-toast-script"],
520 + $version,
521 + true
522 + );
523 + }
524 +
525 + if ($isMainPage || $isProductScreen) {
526 + wp_enqueue_script(
527 + "basalam-round-script",
528 + self::assetsUrl("js/round.js"),
529 + ["jquery", "basalam-admin-toast-script"],
530 + $version,
531 + true
532 + );
533 + }
534 +
535 + if ($isOrderScreen) {
536 + wp_enqueue_script(
537 + "basalam-order-script",
538 + self::assetsUrl("js/order.js"),
539 + ["jquery", "basalam-admin-toast-script"],
540 + $version,
541 + true
542 + );
543 + }
544 +
545 + if ($isMainPage || $isOrderScreen) {
546 + wp_enqueue_script(
547 + "basalam-check-sync-script",
548 + self::assetsUrl("js/check-sync.js"),
549 + ["jquery", "basalam-admin-toast-script"],
550 + $version,
551 + true
552 + );
553 + }
554 +
555 + if ($isPluginPage || $isProductScreen || $isOrderScreen || $shouldLoadPointerTour) {
556 + $adminScriptPath = syncBasalamPlugin()->pluginPath() . '/assets/js/admin.js';
557 + $adminScriptVersion = file_exists($adminScriptPath)
558 + ? $version . '-' . filemtime($adminScriptPath)
559 + : $version;
560 + wp_enqueue_script(
561 + "basalam-admin-script",
562 + self::assetsUrl("js/admin.js"),
563 + $shouldLoadPointerTour ? ["jquery", "wp-pointer", "basalam-admin-toast-script"] : ["jquery", "basalam-admin-toast-script"],
564 + $adminScriptVersion,
565 + true
566 + );
567 + }
568 +
569 + if (self::isTicketPage()) {
570 + $ticketScriptPath = syncBasalamPlugin()->pluginPath() . '/assets/js/ticket.js';
571 + $ticketScriptVersion = file_exists($ticketScriptPath)
572 + ? $version . '-' . filemtime($ticketScriptPath)
573 + : $version;
574 + wp_enqueue_script(
575 + "basalam-ticket-script",
576 + self::assetsUrl("js/ticket.js"),
577 + ["basalam-admin-toast-script"],
578 + $ticketScriptVersion,
579 + true
580 + );
581 + }
582 +
366 583 if ($shouldLoadPointerTour) {
367 584 wp_localize_script('basalam-admin-script', 'basalamPointerTour', PointerTour::getPointerTourConfig());
368 585 }
369 586
370 - if (AnnouncementCenter::shouldLoadAnnouncement()) {
587 + if (wp_script_is('basalam-admin-script', 'enqueued') && AnnouncementCenter::shouldLoadAnnouncement()) {
371 588 wp_localize_script('basalam-admin-script', 'basalamAnnouncements', AnnouncementCenter::getConfig());
372 589 }
373 590 }
374 591