ifnex/03_WordPress/wp-content/plugins/ifnex-bridge/includes/shortcodes.php
Kazem Alghasi 97e641de42 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
2026-08-04 11:38:36 +03:30

89 lines
3.3 KiB
PHP

<?php
/**
* IFNEX Shortcodes
* شورت‌کدهای پلاگین IFNEX Bridge
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
// شورت‌کد فرم ترکینگ
add_shortcode('ifnex_tracking_form', 'ifnex_tracking_form_shortcode');
function ifnex_tracking_form_shortcode($atts) {
$atts = shortcode_atts(array(
'title' => 'رهگیری مرسوله',
'placeholder' => 'شماره بارنامه را وارد کنید',
'button_text' => 'رهگیری',
), $atts);
ob_start();
?>
<div class="ifnex-tracking-container">
<h2><?php echo esc_html($atts['title']); ?></h2>
<form id="ifnex-tracking-form" class="ifnex-tracking-form">
<div class="ifnex-form-group">
<input type="text" id="ifnex-awb-input" placeholder="<?php echo esc_attr($atts['placeholder']); ?>" required>
<button type="submit" id="ifnex-track-btn"><?php echo esc_html($atts['button_text']); ?></button>
</div>
</form>
<div id="ifnex-tracking-result" class="ifnex-tracking-result" style="display: none;"></div>
</div>
<?php
return ob_get_clean();
}
// شورت‌کد نمایش وضعیت مستقیم
add_shortcode('ifnex_tracking_status', 'ifnex_tracking_status_shortcode');
function ifnex_tracking_status_shortcode($atts) {
$atts = shortcode_atts(array(
'awb' => '',
), $atts);
if (empty($atts['awb'])) {
return '<p>شماره بارنامه وارد نشده است.</p>';
}
$client = new IFNEX_API_Client();
$result = $client->track_shipment($atts['awb']);
if (is_wp_error($result)) {
return '<p class="ifnex-error">' . esc_html($result->get_error_message()) . '</p>';
}
ob_start();
?>
<div class="ifnex-tracking-status">
<h3>وضعیت مرسوله <?php echo esc_html($result['awb_no'] ?? ''); ?></h3>
<div class="ifnex-status-badge">
<?php echo esc_html($result['status'] ?? 'نامشخص'); ?>
</div>
<div class="ifnex-details">
<p><strong>نوع:</strong> <?php echo esc_html($result['type'] ?? ''); ?></p>
<p><strong>جهت:</strong> <?php echo esc_html($result['direction'] ?? ''); ?></p>
<p><strong>فرستنده:</strong> <?php echo esc_html($result['sender']['name'] ?? ''); ?></p>
<p><strong>گیرنده:</strong> <?php echo esc_html($result['receiver']['name'] ?? ''); ?></p>
</div>
<?php if (!empty($result['timeline']) && is_array($result['timeline'])): ?>
<div class="ifnex-timeline">
<h4>تاریخچه رهگیری</h4>
<ul>
<?php foreach ($result['timeline'] as $event): ?>
<li>
<strong><?php echo esc_html($event['event_date'] ?? ''); ?></strong>
<span><?php echo esc_html($event['event_description'] ?? ''); ?></span>
<?php if (!empty($event['location'])): ?>
<small><?php echo esc_html($event['location']); ?></small>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
</div>
<?php
return ob_get_clean();
}