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 +305 -123 1.10.91.10.21 View file →
@@ -198,10 +198,132 @@
198 198 {
199 199 return plugin_dir_url(dirname(__FILE__, 2)) . "assets/" . $path;
200 200 }
201 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 +
202 320 public static function adminEnqueueStyles($hook = '')
203 321 {
322 + if (!self::isWoosalamRelatedAdminScreen($hook)) {
323 + return;
324 + }
325 +
204 326 $version = syncbasalamplugin()->getVersion();
205 327
206 328 wp_enqueue_style(
207 329 "basalam-admin-style",
@@ -214,27 +336,35 @@
214 336 self::assetsUrl("css/font.css"),
215 337 array(),
216 338 $version
217 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 + }
218 366 wp_enqueue_style(
219 - "basalam-admin-social-style",
220 - self::assetsUrl("css/social.css"),
221 - array(),
222 - $version
223 - );
224 - wp_enqueue_style(
225 - "basalam-admin-logs-style",
226 - self::assetsUrl("css/logs.css"),
227 - array(),
228 - $version
229 - );
230 - wp_enqueue_style(
231 - "basalam-admin-onboarding-style",
232 - self::assetsUrl("css/onboarding.css"),
233 - array(),
234 - $version
235 - );
236 - wp_enqueue_style(
237 367 "basalam-admin-toast-style",
238 368 self::assetsUrl("css/toast.css"),
239 369 array(),
240 370 $version
@@ -246,11 +376,33 @@
246 376 }
247 377
248 378 public static function adminEnqueueScripts($hook = '')
249 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 +
250 392 $shouldLoadPointerTour = PointerTour::shouldLoadPointerTour((string) $hook);
251 - $version = syncbasalamplugin()->getVersion();
393 + $shouldLoadAssets = self::isWoosalamRelatedAdminScreen($hook);
252 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 +
253 405 if ($shouldLoadPointerTour) {
254 406 wp_enqueue_script('wp-pointer');
255 407 }
256 408
@@ -261,8 +413,20 @@
261 413 $version,
262 414 true
263 415 );
264 416
417 + $vendorStatusScriptPath = syncbasalamplugin()->pluginPath() . '/assets/js/vendor-status.js';
418 + $vendorStatusScriptVersion = file_exists($vendorStatusScriptPath)
419 + ? $version . '-' . filemtime($vendorStatusScriptPath)
420 + : $version;
421 + wp_enqueue_script(
422 + "basalam-vendor-status-script",
423 + self::assetsUrl("js/vendor-status.js"),
424 + ["basalam-admin-toast-script"],
425 + $vendorStatusScriptVersion,
426 + true
427 + );
428 +
265 429 $ticketNotice = TicketFlashNotice::pull();
266 430 if ($ticketNotice !== null) {
267 431 wp_add_inline_script(
268 432 "basalam-admin-toast-script",
@@ -285,125 +449,143 @@
285 449 ),
286 450 'after'
287 451 );
288 452 }
289 - wp_enqueue_script(
290 - "basalam-admin-logs-script",
291 - self::assetsUrl("js/logs.js"),
292 - ["jquery", "basalam-admin-toast-script"],
293 - $version,
294 - true
295 - );
296 - wp_enqueue_script(
297 - "basalam-admin-help-script",
298 - self::assetsUrl("js/help.js"),
299 - ["jquery", "basalam-admin-toast-script"],
300 - $version,
301 - true
302 - );
303 - wp_enqueue_script(
304 - "basalam-admin-product-fields-script",
305 - self::assetsUrl("js/product-fields.js"),
306 - ["jquery", "basalam-admin-toast-script"],
307 - $version,
308 - true
309 - );
310 - wp_enqueue_script(
311 - "basalam-admin-manage-box-script",
312 - self::assetsUrl("js/manage-box.js"),
313 - ["jquery", "basalam-admin-toast-script"],
314 - $version,
315 - true
316 - );
317 - wp_enqueue_script(
318 - "basalam-admin-connect-modal-script",
319 - self::assetsUrl("js/connect-modal.js"),
320 - ["jquery", "basalam-admin-toast-script"],
321 - $version,
322 - true
323 - );
324 - wp_enqueue_script(
325 - "basalam-round-script",
326 - self::assetsUrl("js/round.js"),
327 - ["jquery", "basalam-admin-toast-script"],
328 - $version,
329 - true
330 - );
331 - wp_enqueue_script(
332 - "basalam-get-category-script",
333 - self::assetsUrl("js/get-category.js"),
334 - ["jquery", "basalam-admin-toast-script"],
335 - $version,
336 - true
337 - );
338 - wp_enqueue_script(
339 - "basalam-order-script",
340 - self::assetsUrl("js/order.js"),
341 - ["jquery", "basalam-admin-toast-script"],
342 - $version,
343 - true
344 - );
345 - $adminScriptPath = syncBasalamPlugin()->pluginPath() . '/assets/js/admin.js';
346 - $adminScriptVersion = file_exists($adminScriptPath)
347 - ? $version . '-' . filemtime($adminScriptPath)
348 - : $version;
349 - wp_enqueue_script(
350 - "basalam-admin-script",
351 - self::assetsUrl("js/admin.js"),
352 - $shouldLoadPointerTour ? ["jquery", "wp-pointer", "basalam-admin-toast-script"] : ["jquery", "basalam-admin-toast-script"],
353 - $adminScriptVersion,
354 - true
355 - );
356 - wp_enqueue_script(
357 - "basalam-check-sync-script",
358 - self::assetsUrl("js/check-sync.js"),
359 - ["jquery", "basalam-admin-toast-script"],
360 - $version,
361 - true
362 - );
363 - wp_enqueue_script(
364 - "basalam-map-category-option-script",
365 - self::assetsUrl("js/map-category-option.js"),
366 - ["jquery", "basalam-admin-toast-script"],
367 - $version,
368 - true
369 - );
370 453
371 - wp_enqueue_script(
372 - "basalam-generate-product-variation-script",
373 - self::assetsUrl("js/generate-product-variation.js"),
374 - ["jquery", "basalam-admin-toast-script"],
375 - $version,
376 - true
377 - );
454 + if (self::isPluginPage('sync_basalam_logs')) {
455 + wp_enqueue_script(
456 + "basalam-admin-logs-script",
457 + self::assetsUrl("js/logs.js"),
458 + ["jquery", "basalam-admin-toast-script"],
459 + $version,
460 + true
461 + );
462 + }
378 463
379 - $ticketScriptPath = syncBasalamPlugin()->pluginPath() . '/assets/js/ticket.js';
380 - $ticketScriptVersion = file_exists($ticketScriptPath)
381 - ? $version . '-' . filemtime($ticketScriptPath)
382 - : $version;
383 - wp_enqueue_script(
384 - "basalam-ticket-script",
385 - self::assetsUrl("js/ticket.js"),
386 - ["basalam-admin-toast-script"],
387 - $ticketScriptVersion,
388 - true
389 - );
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 + }
390 473
391 - if (ChatWidget::shouldLoadWidget()) {
474 + if ($isProductEditScreen) {
392 475 wp_enqueue_script(
393 - "basalam-chat-widget-script",
394 - self::assetsUrl("chat/widget-loader.js"),
395 - [],
476 + "basalam-admin-product-fields-script",
477 + self::assetsUrl("js/product-fields.js"),
478 + ["jquery", "basalam-admin-toast-script"],
396 479 $version,
397 480 true
398 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 + );
399 503 }
400 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 +
401 583 if ($shouldLoadPointerTour) {
402 584 wp_localize_script('basalam-admin-script', 'basalamPointerTour', PointerTour::getPointerTourConfig());
403 585 }
404 586
405 - if (AnnouncementCenter::shouldLoadAnnouncement()) {
587 + if (wp_script_is('basalam-admin-script', 'enqueued') && AnnouncementCenter::shouldLoadAnnouncement()) {
406 588 wp_localize_script('basalam-admin-script', 'basalamAnnouncements', AnnouncementCenter::getConfig());
407 589 }
408 590 }
409 591