PluginProbe
ووسلام – همگام سازی ووکامرس و باسلام / 1.10.18
ووسلام – همگام سازی ووکامرس و باسلام v1.10.18
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 1.8.7 1.8.4 All 51 releases
sync-basalam / includes / Actions / ActionHandler.php

ActionHandler.php in ووسلام – همگام سازی ووکامرس و باسلام 1.10.18, at includes/Actions/ActionHandler.php

70 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\Actions;
4
5 defined('ABSPATH') || exit;
6
7 class ActionHandler
8 {
9 public static function postAction($actionName, $className)
10 {
11 add_action('admin_post_' . $actionName, function () use ($actionName, $className) {
12 $nonce = isset($_POST['_wpnonce']) ? sanitize_text_field(wp_unslash($_POST['_wpnonce'])) : '';
13
14 if (!wp_verify_nonce($nonce, $actionName . '_nonce')) {
15 wp_die('دسترسی غیر�
16 جاز!');
17 }
18 $handler = syncBasalamContainer()->get($className);
19
20 do_action('before_' . $actionName, $_POST);
21
22 $result = $handler();
23
24 do_action('after_' . $actionName, $result, $_POST);
25 $redirectTo = isset($_POST['redirect_to']) ? esc_url_raw($_POST['redirect_to']) : wp_get_referer();
26 wp_redirect($redirectTo ?: admin_url()); // phpcs:ignore WordPress.Security.SafeRedirect.wp_redirect_wp_redirect -- Intentional external/user-provided redirect.
27 exit;
28 });
29 }
30
31 public static function postAjax($actionName, $className)
32 {
33 add_action('wp_ajax_' . $actionName, function () use ($actionName, $className) {
34 $nonce = isset($_POST['_wpnonce']) ? sanitize_text_field(wp_unslash($_POST['_wpnonce'])) : '';
35
36 if (!wp_verify_nonce($nonce, $actionName . '_nonce')) {
37 wp_send_json_error([
38 'message' => 'دسترسی غیر�
39 جاز!',
40 ]);
41 }
42
43 if (!current_user_can('manage_woocommerce')) {
44 wp_send_json_error([
45 'message' => 'ش�
46 ا �
47 جاز به انجا�
48 این ع�
49 لیات نیستید.',
50 ], 403);
51 }
52
53 try {
54 $handler = syncBasalamContainer()->get($className);
55
56 do_action('before_' . $actionName, $_POST);
57
58 $result = $handler();
59
60 do_action('after_' . $actionName, $result, $_POST);
61 } catch (\Exception $e) {
62 wp_send_json_error([
63 'message' => 'خطا در پردازش درخواست: ' . $e->getMessage(),
64 ]);
65 }
66 });
67 }
68
69 }
70