Extend the WordPress bridge plugin to provide seamless integration with the backend wallet system. This update introduces user-specific functionality via shortcodes and AJAX. - feat(bridge): implement `IFNEX_User_Bridge` for Sanctum token management - feat(bridge): add `[ifnex_wallet_balance]` shortcode for balance display - feat(bridge): add `[ifnex_transactions]` shortcode for transaction history - feat(bridge): implement AJAX handlers for real-time balance and transaction updates - feat(bridge): add plugin-specific CSS assets and enqueueing logic - docs: update project status with new bridge capabilities - chore: add plugin testing utility and asset directory structure
192 lines
7.7 KiB
PHP
192 lines
7.7 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();
|
|
}
|
|
|
|
// شورتکد موجودی کیف پول
|
|
add_shortcode('ifnex_wallet_balance', 'ifnex_wallet_balance_shortcode');
|
|
|
|
function ifnex_wallet_balance_shortcode($atts) {
|
|
if (!is_user_logged_in()) {
|
|
return '<p class="ifnex-error">برای مشاهده موجودی باید وارد شوید.</p>';
|
|
}
|
|
|
|
$atts = shortcode_atts(array(
|
|
'show_details' => 'no',
|
|
), $atts);
|
|
|
|
$bridge = new IFNEX_User_Bridge();
|
|
$balance = $bridge->get_wallet_balance(get_current_user_id());
|
|
|
|
if (is_wp_error($balance)) {
|
|
return '<p class="ifnex-error">' . esc_html($balance->get_error_message()) . '</p>';
|
|
}
|
|
|
|
ob_start();
|
|
?>
|
|
<div class="ifnex-wallet-balance">
|
|
<div class="ifnex-balance-main">
|
|
<span class="ifnex-balance-label">موجودی کیف پول:</span>
|
|
<span class="ifnex-balance-amount"><?php echo number_format($balance['balance']); ?> ریال</span>
|
|
</div>
|
|
<?php if ($atts['show_details'] === 'yes'): ?>
|
|
<div class="ifnex-balance-details">
|
|
<p><strong>مجموع واریزی:</strong> <?php echo number_format($balance['total_deposited']); ?> ریال</p>
|
|
<p><strong>مجموع برداشت:</strong> <?php echo number_format($balance['total_withdrawn']); ?> ریال</p>
|
|
<?php if ($balance['is_frozen']): ?>
|
|
<p class="ifnex-wallet-frozen">⚠️ کیف پول شما مسدود است.</p>
|
|
<?php endif; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
<?php
|
|
return ob_get_clean();
|
|
}
|
|
|
|
// شورتکد لیست تراکنشها
|
|
add_shortcode('ifnex_transactions', 'ifnex_transactions_shortcode');
|
|
|
|
function ifnex_transactions_shortcode($atts) {
|
|
if (!is_user_logged_in()) {
|
|
return '<p class="ifnex-error">برای مشاهده تراکنشها باید وارد شوید.</p>';
|
|
}
|
|
|
|
$atts = shortcode_atts(array(
|
|
'per_page' => 10,
|
|
'show_pagination' => 'no',
|
|
), $atts);
|
|
|
|
$bridge = new IFNEX_User_Bridge();
|
|
$transactions = $bridge->get_transactions(get_current_user_id(), intval($atts['per_page']));
|
|
|
|
if (is_wp_error($transactions)) {
|
|
return '<p class="ifnex-error">' . esc_html($transactions->get_error_message()) . '</p>';
|
|
}
|
|
|
|
if (empty($transactions['transactions'])) {
|
|
return '<p>هنوز تراکنشی ثبت نشده است.</p>';
|
|
}
|
|
|
|
ob_start();
|
|
?>
|
|
<div class="ifnex-transactions">
|
|
<h3>تاریخچه تراکنشها</h3>
|
|
<div class="ifnex-transactions-list">
|
|
<?php foreach ($transactions['transactions'] as $transaction): ?>
|
|
<div class="ifnex-transaction-item">
|
|
<div class="ifnex-transaction-header">
|
|
<span class="ifnex-transaction-type <?php echo esc_attr($transaction['type']); ?>">
|
|
<?php echo esc_html($transaction['type']); ?>
|
|
</span>
|
|
<span class="ifnex-transaction-amount <?php echo $transaction['amount'] >= 0 ? 'positive' : 'negative'; ?>">
|
|
<?php echo $transaction['amount'] >= 0 ? '+' : ''; ?>
|
|
<?php echo number_format($transaction['amount']); ?> ریال
|
|
</span>
|
|
</div>
|
|
<div class="ifnex-transaction-details">
|
|
<p class="ifnex-transaction-description"><?php echo esc_html($transaction['description']); ?></p>
|
|
<div class="ifnex-transaction-meta">
|
|
<span class="ifnex-transaction-status"><?php echo esc_html($transaction['status']); ?></span>
|
|
<span class="ifnex-transaction-date"><?php echo esc_html($transaction['created_at_jalali']); ?></span>
|
|
</div>
|
|
<?php if (!empty($transaction['reference_id'])): ?>
|
|
<p class="ifnex-transaction-ref">کد پیگیری: <?php echo esc_html($transaction['reference_id']); ?></p>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
<?php if ($atts['show_pagination'] === 'yes' && $transactions['last_page'] > 1): ?>
|
|
<div class="ifnex-pagination">
|
|
<!-- Pagination can be added here -->
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
<?php
|
|
return ob_get_clean();
|
|
}
|