From 97e641de427db6a0f9caa4a513d9f283d572117b Mon Sep 17 00:00:00 2001 From: Kazem Alghasi Date: Tue, 4 Aug 2026 11:38:36 +0330 Subject: [PATCH] feat(wp): add ifnex-bridge plugin for Laravel API integration Implement a new WordPress plugin to bridge the frontend with the Laravel logistics API. This includes: - API client for secure shipment tracking via Bearer token - Admin settings page for configuring API URL and Key - Shortcodes for embedding tracking forms and status displays - AJAX-based tracking form with real-time results and timeline view --- .../plugins/ifnex-bridge/ifnex-bridge.php | 52 +++++ .../ifnex-bridge/includes/api-client.php | 54 +++++ .../ifnex-bridge/includes/shortcodes.php | 88 ++++++++ .../ifnex-bridge/includes/tracking-form.php | 206 ++++++++++++++++++ 4 files changed, 400 insertions(+) create mode 100644 03_WordPress/wp-content/plugins/ifnex-bridge/ifnex-bridge.php create mode 100644 03_WordPress/wp-content/plugins/ifnex-bridge/includes/api-client.php create mode 100644 03_WordPress/wp-content/plugins/ifnex-bridge/includes/shortcodes.php create mode 100644 03_WordPress/wp-content/plugins/ifnex-bridge/includes/tracking-form.php diff --git a/03_WordPress/wp-content/plugins/ifnex-bridge/ifnex-bridge.php b/03_WordPress/wp-content/plugins/ifnex-bridge/ifnex-bridge.php new file mode 100644 index 0000000..e5638fb --- /dev/null +++ b/03_WordPress/wp-content/plugins/ifnex-bridge/ifnex-bridge.php @@ -0,0 +1,52 @@ +

تنظیمات ذخیره شد.

'; + } + + $api_url = get_option('ifnex_api_url', 'http://localhost:8000/api/v1'); + $api_key = get_option('ifnex_api_key', ''); + ?> +
+

تنظیمات IFNEX Logistics Bridge

+
+ + + + + + + + + + +
+ +
+
+ api_url = rtrim(get_option('ifnex_api_url', 'http://localhost:8000/api/v1'), '/'); + $this->api_key = get_option('ifnex_api_key', ''); + } + + public function track_shipment($awb_no) { + if (empty($this->api_key)) { + return new WP_Error('no_api_key', 'API Key تنظیم نشده است.'); + } + + $url = $this->api_url . '/track/' . urlencode($awb_no); + + $args = array( + 'headers' => array( + 'Authorization' => 'Bearer ' . $this->api_key, + 'Accept' => 'application/json', + ), + 'timeout' => 30, + ); + + $response = wp_remote_get($url, $args); + + if (is_wp_error($response)) { + return $response; + } + + $body = wp_remote_retrieve_body($response); + $data = json_decode($body, true); + + if ($response['response']['code'] === 404) { + return new WP_Error('not_found', 'مرسوله‌ای با این کد پیدا نشد.'); + } + + if ($response['response']['code'] !== 200) { + return new WP_Error('api_error', 'خطا در ارتباط با API: ' . ($data['message'] ?? 'Unknown error')); + } + + return $data; + } +} diff --git a/03_WordPress/wp-content/plugins/ifnex-bridge/includes/shortcodes.php b/03_WordPress/wp-content/plugins/ifnex-bridge/includes/shortcodes.php new file mode 100644 index 0000000..d9f5651 --- /dev/null +++ b/03_WordPress/wp-content/plugins/ifnex-bridge/includes/shortcodes.php @@ -0,0 +1,88 @@ + 'رهگیری مرسوله', + 'placeholder' => 'شماره بارنامه را وارد کنید', + 'button_text' => 'رهگیری', + ), $atts); + + ob_start(); + ?> +
+

+
+
+ + +
+
+ +
+ '', + ), $atts); + + if (empty($atts['awb'])) { + return '

شماره بارنامه وارد نشده است.

'; + } + + $client = new IFNEX_API_Client(); + $result = $client->track_shipment($atts['awb']); + + if (is_wp_error($result)) { + return '

' . esc_html($result->get_error_message()) . '

'; + } + + ob_start(); + ?> +
+

وضعیت مرسوله

+
+ +
+
+

نوع:

+

جهت:

+

فرستنده:

+

گیرنده:

+
+ +
+

تاریخچه رهگیری

+
    + +
  • + + + + + +
  • + +
+
+ +
+ post_content, 'ifnex_tracking_form')) { + ?> + + + false, 'message' => 'شماره بارنامه وارد نشده است.')); + return; + } + + $client = new IFNEX_API_Client(); + $result = $client->track_shipment($awb); + + if (is_wp_error($result)) { + wp_send_json(array('success' => false, 'message' => $result->get_error_message())); + return; + } + + // ساخت HTML نتیجه + ob_start(); + ?> +
+

وضعیت مرسوله

+
+ +
+
+

نوع:

+

جهت:

+ +

فرستنده:

+ + +

گیرنده:

+ +
+ +
+

تاریخچه رهگیری

+
    + +
  • + + + + + +
  • + +
+
+ +
+ true, 'html' => $html)); +}