Merge pull request 'refactor(admin): split pay menus modules; plate icon/sort fields' (#154) from worktree-zibll-native-admin-menus into main
Reviewed-on: CYL/wordpress-theme-aksrt#154
This commit is contained in:
@@ -99,8 +99,8 @@ Note: zibll「商品管理」`zibpay_product_page` is **paid article sales**, no
|
||||
| 2b Shipping/after-sale/coupons/income/rebate | done |
|
||||
| 3 users.php submenus | done |
|
||||
| 4 SPA strip | done (ops routes redirect to native) |
|
||||
| 5+ behavior parity | in progress — shipping list create + pending-to-ship board + express timeline query; after-sale filters/actions; order note/quick actions; coupons field parity + batch/enable + product_scope create/edit/batch (native module split); charge-cards expires + code dump + search/labels; product meta shipping/service/limit fields; plate allow_view/add_limit/follow/role + moderator roles UI; topic visibility column |
|
||||
| 5 remaining | optional plate icon/sort native fields; further pay-menus modular split (shipping/charge-card still in shell); zibll pay-hide/points plate options out of scope |
|
||||
| 5+ behavior parity | done for ops shell — shipping/pending/express; after-sale; order note/actions; coupons create/edit/batch + product_scope; charge-cards; product commerce meta; plate allow_view/add_limit/follow/role + moderator roles + icon/sort; topic visibility; pay-menus modular split (coupons/charge-cards/shipping/after-sale) |
|
||||
| 5 remaining | zibll pay-hide/points plate options out of scope; optional further shell trim (orders/income still in pay-menus ~1k lines) |
|
||||
|
||||
## Dual-UI rule
|
||||
|
||||
|
||||
@@ -359,6 +359,15 @@ if (is_admin() && class_exists('AKSRT_Admin_Pay_Menus')) {
|
||||
if (is_admin() && class_exists('AKSRT_Admin_Pay_Coupons')) {
|
||||
AKSRT_Admin_Pay_Coupons::get_instance()->init();
|
||||
}
|
||||
if (is_admin() && class_exists('AKSRT_Admin_Pay_Charge_Cards')) {
|
||||
AKSRT_Admin_Pay_Charge_Cards::get_instance()->init();
|
||||
}
|
||||
if (is_admin() && class_exists('AKSRT_Admin_Pay_Shipping')) {
|
||||
AKSRT_Admin_Pay_Shipping::get_instance()->init();
|
||||
}
|
||||
if (is_admin() && class_exists('AKSRT_Admin_Pay_After_Sale')) {
|
||||
AKSRT_Admin_Pay_After_Sale::get_instance()->init();
|
||||
}
|
||||
|
||||
// WordPress 原生用户菜单:消息/邀请码/认证/禁封(zibll users.php 子菜单对齐)
|
||||
if (is_admin() && class_exists('AKSRT_Admin_Users_Menus')) {
|
||||
|
||||
@@ -174,6 +174,9 @@ require_once AKSRT_DIR . '/inc/classes/class-aksrt-category-rewrite.php';
|
||||
require_once AKSRT_DIR . '/inc/classes/admin/class-aksrt-admin-message-controller.php';
|
||||
require_once AKSRT_DIR . '/inc/classes/admin/native/class-aksrt-admin-pay-menus.php';
|
||||
require_once AKSRT_DIR . '/inc/classes/admin/native/class-aksrt-admin-pay-coupons.php';
|
||||
require_once AKSRT_DIR . '/inc/classes/admin/native/class-aksrt-admin-pay-charge-cards.php';
|
||||
require_once AKSRT_DIR . '/inc/classes/admin/native/class-aksrt-admin-pay-shipping.php';
|
||||
require_once AKSRT_DIR . '/inc/classes/admin/native/class-aksrt-admin-pay-after-sale.php';
|
||||
require_once AKSRT_DIR . '/inc/classes/admin/native/class-aksrt-admin-users-menus.php';
|
||||
|
||||
require_once AKSRT_DIR . '/inc/classes/class-aksrt-admin.php';
|
||||
|
||||
@@ -0,0 +1,365 @@
|
||||
<?php
|
||||
/**
|
||||
* Native WP admin: AKSRT_Admin_Pay_After_Sale.
|
||||
*
|
||||
* Extracted from AKSRT_Admin_Pay_Menus.
|
||||
*
|
||||
* @package AKSRT
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
class AKSRT_Admin_Pay_After_Sale {
|
||||
|
||||
public const CAPABILITY = 'manage_options';
|
||||
public const PAGE_SLUG = 'aksrt_after_sale';
|
||||
|
||||
private static $instance = null;
|
||||
|
||||
public static function get_instance(): self {
|
||||
if (null === self::$instance) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
public function init(): void {
|
||||
if (!is_admin()) {
|
||||
return;
|
||||
}
|
||||
add_action('admin_post_aksrt_pay_update_after_sale', [$this, 'handle_update_after_sale']);
|
||||
add_action('admin_post_aksrt_pay_create_after_sale', [$this, 'handle_create_after_sale']);
|
||||
add_action('admin_post_aksrt_pay_after_sale_action', [$this, 'handle_after_sale_action']);
|
||||
}
|
||||
|
||||
public function handle_create_after_sale(): void {
|
||||
if (!current_user_can(self::CAPABILITY)) {
|
||||
wp_die(esc_html__('权限不足', 'aksrt'));
|
||||
}
|
||||
$order_number = isset($_POST['order_number']) ? sanitize_text_field((string) wp_unslash($_POST['order_number'])) : '';
|
||||
$redirect_page = isset($_POST['redirect_page']) ? sanitize_key((string) wp_unslash($_POST['redirect_page'])) : 'order';
|
||||
$nonce_action = $redirect_page === 'after_sale' ? 'aksrt_pay_create_after_sale' : ('aksrt_pay_create_after_sale_' . $order_number);
|
||||
check_admin_referer($nonce_action);
|
||||
|
||||
$ok = false;
|
||||
if ($order_number !== '' && class_exists('AKSRT_After_Sale')) {
|
||||
$user_id = isset($_POST['user_id']) ? (int) $_POST['user_id'] : 0;
|
||||
if ($user_id <= 0 && class_exists('AKSRT_Order_Repository')) {
|
||||
$order = AKSRT_Order_Repository::get_instance()->get($order_number);
|
||||
$user_id = (int) ($order['user_id'] ?? 0);
|
||||
}
|
||||
$id = AKSRT_After_Sale::get_instance()->create([
|
||||
'order_number' => $order_number,
|
||||
'user_id' => $user_id,
|
||||
'type' => sanitize_key((string) wp_unslash($_POST['type'] ?? 'refund')),
|
||||
'reason' => sanitize_textarea_field((string) wp_unslash($_POST['reason'] ?? '')),
|
||||
'amount' => (float) ($_POST['amount'] ?? 0),
|
||||
'note' => sanitize_textarea_field((string) wp_unslash($_POST['note'] ?? '')),
|
||||
]);
|
||||
$ok = $id > 0;
|
||||
}
|
||||
|
||||
$msg = $ok ? 'after_sale_created' : 'after_sale_create_failed';
|
||||
if ($redirect_page === 'after_sale') {
|
||||
wp_safe_redirect($this->page_url('aksrt_after_sale', ['aksrt_pay_msg' => $msg, 's' => $order_number]));
|
||||
exit;
|
||||
}
|
||||
wp_safe_redirect($this->page_url('aksrt_orders', [
|
||||
'order' => $order_number,
|
||||
'aksrt_pay_msg' => $msg,
|
||||
]));
|
||||
exit;
|
||||
}
|
||||
|
||||
public function render_after_sale_page(): void {
|
||||
$this->ensure_cap();
|
||||
$this->render_header(__('售后管理', 'aksrt'));
|
||||
|
||||
if (!class_exists('AKSRT_After_Sale')) {
|
||||
echo '<div class="notice notice-error"><p>' . esc_html__('售后模块未初始化。', 'aksrt') . '</p></div>';
|
||||
$this->render_footer();
|
||||
return;
|
||||
}
|
||||
|
||||
$status = isset($_GET['status']) ? sanitize_key((string) wp_unslash($_GET['status'])) : '';
|
||||
$type = isset($_GET['type']) ? sanitize_key((string) wp_unslash($_GET['type'])) : '';
|
||||
$search = isset($_GET['s']) ? sanitize_text_field((string) wp_unslash($_GET['s'])) : '';
|
||||
if ($search === '' && isset($_GET['order_number'])) {
|
||||
$search = sanitize_text_field((string) wp_unslash($_GET['order_number']));
|
||||
}
|
||||
$page_num = max(1, (int) ($_GET['paged'] ?? 1));
|
||||
$per_page = 20;
|
||||
$svc = AKSRT_After_Sale::get_instance();
|
||||
$stats = $svc->get_stats();
|
||||
$status_options = $this->after_sale_status_options(true);
|
||||
$type_options = $this->after_sale_type_options(true);
|
||||
|
||||
echo '<p>' . esc_html(sprintf(
|
||||
/* translators: 1: total 2: pending */
|
||||
__('售后工单共 %1$d · 待处理 %2$d', 'aksrt'),
|
||||
(int) ($stats['total'] ?? 0),
|
||||
(int) ($stats['pending'] ?? 0)
|
||||
)) . '</p>';
|
||||
|
||||
echo '<h2>' . esc_html__('新建售后', 'aksrt') . '</h2>';
|
||||
echo '<form method="post" action="' . esc_url(admin_url('admin-post.php')) . '" style="margin:8px 0 20px;display:flex;flex-wrap:wrap;gap:8px;align-items:end;">';
|
||||
echo '<input type="hidden" name="action" value="aksrt_pay_create_after_sale" />';
|
||||
echo '<input type="hidden" name="redirect_page" value="after_sale" />';
|
||||
wp_nonce_field('aksrt_pay_create_after_sale');
|
||||
echo '<p><label>' . esc_html__('订单号', 'aksrt') . '<br><input type="text" name="order_number" value="' . esc_attr($search) . '" required class="regular-text" /></label></p>';
|
||||
echo '<p><label>' . esc_html__('类型', 'aksrt') . '<br><select name="type">';
|
||||
foreach ($this->after_sale_type_options(false) as $k => $label) {
|
||||
printf('<option value="%s">%s</option>', esc_attr($k), esc_html($label));
|
||||
}
|
||||
echo '</select></label></p>';
|
||||
echo '<p><label>' . esc_html__('金额', 'aksrt') . '<br><input type="number" step="0.01" min="0" name="amount" value="0" /></label></p>';
|
||||
echo '<p><label>' . esc_html__('原因', 'aksrt') . '<br><input type="text" name="reason" required class="regular-text" /></label></p>';
|
||||
echo '<p><label>' . esc_html__('备注', 'aksrt') . '<br><input type="text" name="note" /></label></p>';
|
||||
submit_button(__('创建售后', 'aksrt'), 'primary', '', false);
|
||||
echo '</form>';
|
||||
|
||||
echo '<form method="get" style="margin:12px 0;">';
|
||||
echo '<input type="hidden" name="page" value="aksrt_after_sale" />';
|
||||
echo '<select name="status">';
|
||||
foreach ($status_options as $key => $label) {
|
||||
printf('<option value="%s"%s>%s</option>', esc_attr($key), selected($status, $key, false), esc_html($label));
|
||||
}
|
||||
echo '</select> ';
|
||||
echo '<select name="type">';
|
||||
foreach ($type_options as $key => $label) {
|
||||
printf('<option value="%s"%s>%s</option>', esc_attr($key), selected($type, $key, false), esc_html($label));
|
||||
}
|
||||
echo '</select> ';
|
||||
echo '<input type="search" name="s" value="' . esc_attr($search) . '" placeholder="' . esc_attr__('订单号', 'aksrt') . '" /> ';
|
||||
submit_button(__('筛选', 'aksrt'), 'secondary', '', false);
|
||||
echo '</form>';
|
||||
|
||||
$list_args = [
|
||||
'status' => $status,
|
||||
'type' => $type,
|
||||
'limit' => $per_page,
|
||||
'offset' => ($page_num - 1) * $per_page,
|
||||
];
|
||||
if ($search !== '') {
|
||||
$list_args['order_number'] = $search;
|
||||
}
|
||||
$result = $svc->get_list($list_args);
|
||||
$items = $result['items'] ?? [];
|
||||
$total = (int) ($result['total'] ?? 0);
|
||||
$pages = max(1, (int) ceil(max(1, $total) / $per_page));
|
||||
$row_status_options = $this->after_sale_status_options(false);
|
||||
|
||||
echo '<table class="wp-list-table widefat fixed striped"><thead><tr>';
|
||||
echo '<th>ID</th><th>' . esc_html__('订单号', 'aksrt') . '</th><th>' . esc_html__('类型', 'aksrt') . '</th><th>' . esc_html__('用户', 'aksrt') . '</th><th>' . esc_html__('状态', 'aksrt') . '</th><th>' . esc_html__('时间', 'aksrt') . '</th><th>' . esc_html__('操作', 'aksrt') . '</th>';
|
||||
echo '</tr></thead><tbody>';
|
||||
if (!$items) {
|
||||
echo '<tr><td colspan="7">' . esc_html__('暂无售后工单', 'aksrt') . '</td></tr>';
|
||||
}
|
||||
foreach ($items as $row) {
|
||||
$id = (int) ($row['id'] ?? 0);
|
||||
$user_id = (int) ($row['user_id'] ?? 0);
|
||||
$user = $user_id > 0 ? get_userdata($user_id) : null;
|
||||
$st = (string) ($row['status'] ?? '');
|
||||
$order_number = (string) ($row['order_number'] ?? '');
|
||||
echo '<tr>';
|
||||
echo '<td>' . esc_html((string) $id) . '</td>';
|
||||
echo '<td><a href="' . esc_url($this->page_url('aksrt_orders', ['order' => $order_number])) . '"><code>' . esc_html($order_number) . '</code></a></td>';
|
||||
echo '<td>' . esc_html((string) ($row['type_label'] ?? $type_options[$row['type'] ?? ''] ?? $row['type'] ?? '')) . '</td>';
|
||||
echo '<td>' . ($user ? esc_html($user->display_name) : esc_html((string) $user_id)) . '</td>';
|
||||
echo '<td>' . esc_html((string) ($row['status_label'] ?? $row_status_options[$st] ?? $st)) . '</td>';
|
||||
echo '<td>' . esc_html((string) ($row['created_at'] ?? '')) . '</td>';
|
||||
echo '<td style="display:flex;gap:6px;flex-wrap:wrap;align-items:center;">';
|
||||
if ($st === 'pending') {
|
||||
echo '<form method="post" action="' . esc_url(admin_url('admin-post.php')) . '">';
|
||||
echo '<input type="hidden" name="action" value="aksrt_pay_after_sale_action" />';
|
||||
echo '<input type="hidden" name="ticket_id" value="' . esc_attr((string) $id) . '" />';
|
||||
echo '<input type="hidden" name="as_action" value="approve" />';
|
||||
wp_nonce_field('aksrt_pay_after_sale_action_' . $id);
|
||||
submit_button(__('同意', 'aksrt'), 'small', '', false);
|
||||
echo '</form>';
|
||||
echo '<form method="post" action="' . esc_url(admin_url('admin-post.php')) . '">';
|
||||
echo '<input type="hidden" name="action" value="aksrt_pay_after_sale_action" />';
|
||||
echo '<input type="hidden" name="ticket_id" value="' . esc_attr((string) $id) . '" />';
|
||||
echo '<input type="hidden" name="as_action" value="reject" />';
|
||||
wp_nonce_field('aksrt_pay_after_sale_action_' . $id);
|
||||
echo '<button type="submit" class="button button-small" onclick="return confirm(\'' . esc_js(__('确认拒绝该售后?', 'aksrt')) . '\');">' . esc_html__('拒绝', 'aksrt') . '</button>';
|
||||
echo '</form>';
|
||||
}
|
||||
if ($st === 'processing') {
|
||||
echo '<form method="post" action="' . esc_url(admin_url('admin-post.php')) . '">';
|
||||
echo '<input type="hidden" name="action" value="aksrt_pay_after_sale_action" />';
|
||||
echo '<input type="hidden" name="ticket_id" value="' . esc_attr((string) $id) . '" />';
|
||||
echo '<input type="hidden" name="as_action" value="confirm_return" />';
|
||||
wp_nonce_field('aksrt_pay_after_sale_action_' . $id);
|
||||
submit_button(__('确认收货', 'aksrt'), 'small', '', false);
|
||||
echo '</form>';
|
||||
}
|
||||
echo '<form method="post" action="' . esc_url(admin_url('admin-post.php')) . '" style="display:flex;gap:4px;align-items:center;flex-wrap:wrap;">';
|
||||
echo '<input type="hidden" name="action" value="aksrt_pay_update_after_sale" />';
|
||||
echo '<input type="hidden" name="ticket_id" value="' . esc_attr((string) $id) . '" />';
|
||||
wp_nonce_field('aksrt_pay_update_after_sale_' . $id);
|
||||
echo '<select name="new_status">';
|
||||
foreach ($row_status_options as $key => $label) {
|
||||
printf('<option value="%s"%s>%s</option>', esc_attr($key), selected($st, $key, false), esc_html($label));
|
||||
}
|
||||
echo '</select>';
|
||||
echo '<input type="text" name="note" placeholder="' . esc_attr__('备注', 'aksrt') . '" />';
|
||||
submit_button(__('更新', 'aksrt'), 'small', '', false);
|
||||
echo '</form>';
|
||||
echo '</td></tr>';
|
||||
}
|
||||
echo '</tbody></table>';
|
||||
$this->render_pagination($pages, $page_num);
|
||||
$this->render_footer();
|
||||
}
|
||||
|
||||
public function handle_update_after_sale(): void {
|
||||
if (!current_user_can(self::CAPABILITY)) {
|
||||
wp_die(esc_html__('权限不足', 'aksrt'));
|
||||
}
|
||||
$id = isset($_POST['ticket_id']) ? (int) $_POST['ticket_id'] : 0;
|
||||
$new_status = isset($_POST['new_status']) ? sanitize_key((string) wp_unslash($_POST['new_status'])) : '';
|
||||
$note = isset($_POST['note']) ? sanitize_textarea_field((string) wp_unslash($_POST['note'])) : '';
|
||||
check_admin_referer('aksrt_pay_update_after_sale_' . $id);
|
||||
|
||||
$ok = false;
|
||||
if ($id > 0 && $new_status !== '' && class_exists('AKSRT_After_Sale')) {
|
||||
$ok = AKSRT_After_Sale::get_instance()->update_status($id, $new_status, get_current_user_id(), $note);
|
||||
}
|
||||
wp_safe_redirect($this->page_url('aksrt_after_sale', ['aksrt_pay_msg' => $ok ? 'after_sale_updated' : 'after_sale_failed']));
|
||||
exit;
|
||||
}
|
||||
|
||||
public function handle_after_sale_action(): void {
|
||||
if (!current_user_can(self::CAPABILITY)) {
|
||||
wp_die(esc_html__('权限不足', 'aksrt'));
|
||||
}
|
||||
$id = isset($_POST['ticket_id']) ? (int) $_POST['ticket_id'] : 0;
|
||||
$as_action = isset($_POST['as_action']) ? sanitize_key((string) wp_unslash($_POST['as_action'])) : '';
|
||||
check_admin_referer('aksrt_pay_after_sale_action_' . $id);
|
||||
|
||||
$ok = false;
|
||||
if ($id > 0 && class_exists('AKSRT_After_Sale')) {
|
||||
$svc = AKSRT_After_Sale::get_instance();
|
||||
$operator_id = get_current_user_id();
|
||||
if ($as_action === 'approve') {
|
||||
$ok = $svc->merchant_approve($id, $operator_id);
|
||||
} elseif ($as_action === 'reject') {
|
||||
$ok = $svc->merchant_reject($id, $operator_id, __('商家拒绝', 'aksrt'));
|
||||
} elseif ($as_action === 'confirm_return') {
|
||||
$ok = $svc->merchant_confirm_return($id, $operator_id);
|
||||
}
|
||||
}
|
||||
|
||||
wp_safe_redirect($this->page_url('aksrt_after_sale', [
|
||||
'aksrt_pay_msg' => $ok ? 'after_sale_action_ok' : 'after_sale_action_failed',
|
||||
]));
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
private function after_sale_status_options(bool $include_all = false): array {
|
||||
$options = [];
|
||||
if ($include_all) {
|
||||
$options[''] = __('全部状态', 'aksrt');
|
||||
}
|
||||
if (class_exists('AKSRT_After_Sale')) {
|
||||
foreach (AKSRT_After_Sale::get_status_options() as $item) {
|
||||
$value = (string) ($item['value'] ?? '');
|
||||
if ($value === '') {
|
||||
continue;
|
||||
}
|
||||
$options[$value] = (string) ($item['label'] ?? $value);
|
||||
}
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public function after_sale_type_options_public(bool $include_all = false): array {
|
||||
return $this->after_sale_type_options($include_all);
|
||||
}
|
||||
|
||||
private function after_sale_type_options(bool $include_all = false): array {
|
||||
$options = [];
|
||||
if ($include_all) {
|
||||
$options[''] = __('全部类型', 'aksrt');
|
||||
}
|
||||
// Keep operational create options broader than public get_type_options().
|
||||
$defaults = [
|
||||
'refund' => __('仅退款', 'aksrt'),
|
||||
'refund_return' => __('退货退款', 'aksrt'),
|
||||
'exchange' => __('换货', 'aksrt'),
|
||||
'repair' => __('维修', 'aksrt'),
|
||||
];
|
||||
if (class_exists('AKSRT_After_Sale')) {
|
||||
foreach (AKSRT_After_Sale::get_type_options() as $item) {
|
||||
$value = (string) ($item['value'] ?? '');
|
||||
if ($value === '') {
|
||||
continue;
|
||||
}
|
||||
$defaults[$value] = (string) ($item['label'] ?? $value);
|
||||
}
|
||||
}
|
||||
return array_merge($options, $defaults);
|
||||
}
|
||||
|
||||
|
||||
private function ensure_cap(): void {
|
||||
if (!current_user_can(self::CAPABILITY)) {
|
||||
wp_die(esc_html__('您没有权限访问此页面。', 'aksrt'));
|
||||
}
|
||||
}
|
||||
|
||||
private function render_header(string $title): void {
|
||||
echo '<div class="wrap">';
|
||||
echo '<h1>' . esc_html($title) . '</h1>';
|
||||
$this->render_flash();
|
||||
}
|
||||
|
||||
private function render_footer(): void {
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
private function render_flash(): void {
|
||||
if (empty($_GET['aksrt_pay_msg'])) {
|
||||
return;
|
||||
}
|
||||
$code = sanitize_key((string) wp_unslash($_GET['aksrt_pay_msg']));
|
||||
$map = [
|
||||
'after_sale_updated' => __('售后状态已更新。', 'aksrt'),
|
||||
'after_sale_failed' => __('售后状态更新失败。', 'aksrt'),
|
||||
'after_sale_created' => __('售后工单已创建。', 'aksrt'),
|
||||
'after_sale_create_failed' => __('售后工单创建失败。', 'aksrt'),
|
||||
'after_sale_action_ok' => __('售后操作已完成。', 'aksrt'),
|
||||
'after_sale_action_failed' => __('售后操作失败。', 'aksrt'),
|
||||
];
|
||||
if (!isset($map[$code])) {
|
||||
return;
|
||||
}
|
||||
$class = str_contains($code, 'failed') ? 'notice-error' : 'notice-success';
|
||||
echo '<div class="notice ' . esc_attr($class) . ' is-dismissible"><p>' . esc_html($map[$code]) . '</p></div>';
|
||||
}
|
||||
|
||||
private function page_url(string $slug, array $args = []): string {
|
||||
return add_query_arg(array_merge(['page' => $slug], $args), admin_url('admin.php'));
|
||||
}
|
||||
|
||||
private function render_pagination(int $pages, int $page_num): void {
|
||||
if ($pages <= 1) {
|
||||
return;
|
||||
}
|
||||
echo '<div class="tablenav"><div class="tablenav-pages">';
|
||||
echo paginate_links([
|
||||
'base' => add_query_arg('paged', '%#%'),
|
||||
'format' => '',
|
||||
'prev_text' => '«',
|
||||
'next_text' => '»',
|
||||
'total' => $pages,
|
||||
'current' => $page_num,
|
||||
]);
|
||||
echo '</div></div>';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,350 @@
|
||||
<?php
|
||||
/**
|
||||
* Native WP admin: AKSRT_Admin_Pay_Charge_Cards.
|
||||
*
|
||||
* Extracted from AKSRT_Admin_Pay_Menus.
|
||||
*
|
||||
* @package AKSRT
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
class AKSRT_Admin_Pay_Charge_Cards {
|
||||
|
||||
public const CAPABILITY = 'manage_options';
|
||||
public const PAGE_SLUG = 'aksrt_charge_cards';
|
||||
|
||||
private static $instance = null;
|
||||
|
||||
public static function get_instance(): self {
|
||||
if (null === self::$instance) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
public function init(): void {
|
||||
if (!is_admin()) {
|
||||
return;
|
||||
}
|
||||
add_action('admin_post_aksrt_pay_disable_charge_card', [$this, 'handle_disable_charge_card']);
|
||||
add_action('admin_post_aksrt_pay_batch_charge_cards', [$this, 'handle_batch_charge_cards']);
|
||||
}
|
||||
|
||||
public function render_charge_cards_page(): void {
|
||||
$this->ensure_cap();
|
||||
$this->render_header(__('卡密管理', 'aksrt'));
|
||||
|
||||
if (!class_exists('AKSRT_Charge_Card')) {
|
||||
echo '<div class="notice notice-error"><p>' . esc_html__('卡密模块未初始化。', 'aksrt') . '</p></div>';
|
||||
$this->render_footer();
|
||||
return;
|
||||
}
|
||||
|
||||
$status = isset($_GET['status']) ? sanitize_key((string) wp_unslash($_GET['status'])) : '';
|
||||
$type = isset($_GET['type']) ? sanitize_key((string) wp_unslash($_GET['type'])) : '';
|
||||
$search = isset($_GET['s']) ? sanitize_text_field((string) wp_unslash($_GET['s'])) : '';
|
||||
$page_num = max(1, (int) ($_GET['paged'] ?? 1));
|
||||
$per_page = 20;
|
||||
$svc = AKSRT_Charge_Card::get_instance();
|
||||
$stats = $svc->get_stats();
|
||||
$type_labels = [
|
||||
'balance' => __('余额', 'aksrt'),
|
||||
'vip' => __('VIP', 'aksrt'),
|
||||
'credits' => __('积分', 'aksrt'),
|
||||
'points' => __('积分', 'aksrt'),
|
||||
];
|
||||
$status_labels = [
|
||||
'active' => __('可用', 'aksrt'),
|
||||
'used' => __('已用', 'aksrt'),
|
||||
'disabled' => __('已禁用', 'aksrt'),
|
||||
'expired' => __('已过期', 'aksrt'),
|
||||
];
|
||||
|
||||
echo '<p>' . esc_html(sprintf(
|
||||
/* translators: 1: total 2: active 3: used */
|
||||
__('共 %1$d 张 · 可用 %2$d · 已用 %3$d', 'aksrt'),
|
||||
(int) ($stats['total'] ?? 0),
|
||||
(int) ($stats['active'] ?? 0),
|
||||
(int) ($stats['used'] ?? 0)
|
||||
)) . '</p>';
|
||||
|
||||
echo '<h2>' . esc_html__('批量生成卡密', 'aksrt') . '</h2>';
|
||||
echo '<form method="post" action="' . esc_url(admin_url('admin-post.php')) . '" style="margin:12px 0 20px;display:flex;flex-wrap:wrap;gap:8px;align-items:end;">';
|
||||
echo '<input type="hidden" name="action" value="aksrt_pay_batch_charge_cards" />';
|
||||
wp_nonce_field('aksrt_pay_batch_charge_cards');
|
||||
echo '<p><label>' . esc_html__('类型', 'aksrt') . '<br><select name="type">';
|
||||
echo '<option value="balance">' . esc_html__('余额', 'aksrt') . '</option>';
|
||||
echo '<option value="vip">' . esc_html__('VIP', 'aksrt') . '</option>';
|
||||
echo '<option value="credits">' . esc_html__('积分', 'aksrt') . '</option>';
|
||||
echo '</select></label></p>';
|
||||
echo '<p><label>' . esc_html__('数量', 'aksrt') . '<br><input type="number" name="count" min="1" max="500" value="10" /></label></p>';
|
||||
echo '<p><label>' . esc_html__('长度', 'aksrt') . '<br><input type="number" name="length" min="8" max="32" value="16" /></label></p>';
|
||||
echo '<p><label>' . esc_html__('前缀', 'aksrt') . '<br><input type="text" name="prefix" value="" /></label></p>';
|
||||
echo '<p><label>' . esc_html__('面额/积分', 'aksrt') . '<br><input type="number" step="0.01" name="amount" value="10" /></label></p>';
|
||||
echo '<p><label>' . esc_html__('VIP等级', 'aksrt') . '<br><input type="number" name="vip_level" min="1" max="2" value="1" /></label></p>';
|
||||
echo '<p><label>' . esc_html__('VIP天数', 'aksrt') . '<br><input type="number" name="vip_days" min="1" value="30" /></label></p>';
|
||||
echo '<p><label>' . esc_html__('过期时间', 'aksrt') . '<br><input type="datetime-local" name="expires_at" /></label></p>';
|
||||
echo '<p><label>' . esc_html__('备注', 'aksrt') . '<br><input type="text" name="note" value="" /></label></p>';
|
||||
submit_button(__('生成', 'aksrt'), 'primary', '', false);
|
||||
echo '</form>';
|
||||
|
||||
if (!empty($_GET['aksrt_generated'])) {
|
||||
$generated = (int) $_GET['aksrt_generated'];
|
||||
echo '<div class="notice notice-success"><p>' . esc_html(sprintf(
|
||||
/* translators: %d count */
|
||||
__('成功生成 %d 张卡密。', 'aksrt'),
|
||||
$generated
|
||||
)) . '</p></div>';
|
||||
}
|
||||
|
||||
$generated_codes = get_transient('aksrt_pay_card_codes_' . get_current_user_id());
|
||||
if (is_array($generated_codes) && $generated_codes) {
|
||||
delete_transient('aksrt_pay_card_codes_' . get_current_user_id());
|
||||
echo '<div class="notice notice-info"><p><strong>' . esc_html__('本次生成卡密(请及时复制保存):', 'aksrt') . '</strong></p>';
|
||||
echo '<textarea class="large-text code" rows="' . esc_attr((string) min(12, max(3, count($generated_codes)))) . '" readonly onclick="this.select();">' . esc_textarea(implode("\n", $generated_codes)) . '</textarea>';
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
echo '<form method="get" style="margin:12px 0;">';
|
||||
echo '<input type="hidden" name="page" value="aksrt_charge_cards" />';
|
||||
echo '<select name="status">';
|
||||
foreach ([
|
||||
'' => __('全部状态', 'aksrt'),
|
||||
'active' => __('可用', 'aksrt'),
|
||||
'used' => __('已用', 'aksrt'),
|
||||
'disabled' => __('已禁用', 'aksrt'),
|
||||
'expired' => __('已过期', 'aksrt'),
|
||||
] as $key => $label) {
|
||||
printf(
|
||||
'<option value="%s"%s>%s</option>',
|
||||
esc_attr($key),
|
||||
selected($status, $key, false),
|
||||
esc_html($label)
|
||||
);
|
||||
}
|
||||
echo '</select> ';
|
||||
echo '<select name="type">';
|
||||
foreach ([
|
||||
'' => __('全部类型', 'aksrt'),
|
||||
'balance' => __('余额', 'aksrt'),
|
||||
'vip' => __('VIP', 'aksrt'),
|
||||
'credits' => __('积分', 'aksrt'),
|
||||
] as $key => $label) {
|
||||
printf(
|
||||
'<option value="%s"%s>%s</option>',
|
||||
esc_attr($key),
|
||||
selected($type, $key, false),
|
||||
esc_html($label)
|
||||
);
|
||||
}
|
||||
echo '</select> ';
|
||||
echo '<input type="search" name="s" value="' . esc_attr($search) . '" placeholder="' . esc_attr__('密码 / 卡号 / 备注', 'aksrt') . '" /> ';
|
||||
submit_button(__('筛选', 'aksrt'), 'secondary', '', false);
|
||||
echo '</form>';
|
||||
|
||||
$result = $svc->get_list([
|
||||
'status' => $status,
|
||||
'type' => $type,
|
||||
'search' => $search,
|
||||
'limit' => $per_page,
|
||||
'offset' => ($page_num - 1) * $per_page,
|
||||
]);
|
||||
$items = $result['items'] ?? [];
|
||||
$total = (int) ($result['total'] ?? 0);
|
||||
$pages = max(1, (int) ($result['max_pages'] ?? 1));
|
||||
|
||||
echo '<table class="wp-list-table widefat fixed striped">';
|
||||
echo '<thead><tr>';
|
||||
echo '<th>ID</th>';
|
||||
echo '<th>' . esc_html__('类型', 'aksrt') . '</th>';
|
||||
echo '<th>' . esc_html__('密码', 'aksrt') . '</th>';
|
||||
echo '<th>' . esc_html__('面额', 'aksrt') . '</th>';
|
||||
echo '<th>' . esc_html__('状态', 'aksrt') . '</th>';
|
||||
echo '<th>' . esc_html__('过期', 'aksrt') . '</th>';
|
||||
echo '<th>' . esc_html__('使用者', 'aksrt') . '</th>';
|
||||
echo '<th>' . esc_html__('创建时间', 'aksrt') . '</th>';
|
||||
echo '<th>' . esc_html__('操作', 'aksrt') . '</th>';
|
||||
echo '</tr></thead><tbody>';
|
||||
|
||||
if (!$items) {
|
||||
echo '<tr><td colspan="9">' . esc_html__('暂无卡密', 'aksrt') . '</td></tr>';
|
||||
}
|
||||
|
||||
foreach ($items as $row) {
|
||||
$id = (int) ($row['id'] ?? 0);
|
||||
$st = (string) ($row['status'] ?? '');
|
||||
$row_type = (string) ($row['type'] ?? '');
|
||||
$user_id = (int) ($row['used_by'] ?? $row['user_id'] ?? 0);
|
||||
$user = $user_id > 0 ? get_userdata($user_id) : null;
|
||||
|
||||
echo '<tr>';
|
||||
echo '<td>' . esc_html((string) $id) . '</td>';
|
||||
echo '<td>' . esc_html($type_labels[$row_type] ?? $row_type) . '</td>';
|
||||
echo '<td><code>' . esc_html((string) ($row['password'] ?? $row['code'] ?? '')) . '</code></td>';
|
||||
echo '<td>' . esc_html((string) ($row['amount'] ?? '')) . '</td>';
|
||||
echo '<td>' . esc_html($status_labels[$st] ?? $st) . '</td>';
|
||||
echo '<td>' . esc_html((string) ($row['expires_at'] ?? '—')) . '</td>';
|
||||
echo '<td>' . ($user ? esc_html($user->display_name) : '—') . '</td>';
|
||||
echo '<td>' . esc_html((string) ($row['created_at'] ?? '')) . '</td>';
|
||||
echo '<td>';
|
||||
if ($st === 'active') {
|
||||
echo '<form method="post" action="' . esc_url(admin_url('admin-post.php')) . '">';
|
||||
echo '<input type="hidden" name="action" value="aksrt_pay_disable_charge_card" />';
|
||||
echo '<input type="hidden" name="card_id" value="' . esc_attr((string) $id) . '" />';
|
||||
wp_nonce_field('aksrt_pay_disable_charge_card_' . $id);
|
||||
submit_button(__('禁用', 'aksrt'), 'small', '', false);
|
||||
echo '</form>';
|
||||
} else {
|
||||
echo '—';
|
||||
}
|
||||
echo '</td>';
|
||||
echo '</tr>';
|
||||
}
|
||||
|
||||
echo '</tbody></table>';
|
||||
|
||||
if ($pages > 1) {
|
||||
echo '<div class="tablenav"><div class="tablenav-pages">';
|
||||
echo paginate_links([
|
||||
'base' => add_query_arg('paged', '%#%'),
|
||||
'format' => '',
|
||||
'prev_text' => '«',
|
||||
'next_text' => '»',
|
||||
'total' => $pages,
|
||||
'current' => $page_num,
|
||||
]);
|
||||
echo '</div></div>';
|
||||
}
|
||||
|
||||
$this->render_footer();
|
||||
}
|
||||
|
||||
public function handle_disable_charge_card(): void {
|
||||
if (!current_user_can(self::CAPABILITY)) {
|
||||
wp_die(esc_html__('权限不足', 'aksrt'));
|
||||
}
|
||||
|
||||
$id = isset($_POST['card_id']) ? (int) $_POST['card_id'] : 0;
|
||||
check_admin_referer('aksrt_pay_disable_charge_card_' . $id);
|
||||
|
||||
$ok = false;
|
||||
if ($id > 0 && class_exists('AKSRT_Charge_Card')) {
|
||||
$ok = AKSRT_Charge_Card::get_instance()->disable($id);
|
||||
}
|
||||
|
||||
wp_safe_redirect($this->page_url('aksrt_charge_cards', [
|
||||
'aksrt_pay_msg' => $ok ? 'card_disabled' : 'card_failed',
|
||||
]));
|
||||
exit;
|
||||
}
|
||||
|
||||
public function handle_batch_charge_cards(): void {
|
||||
if (!current_user_can(self::CAPABILITY)) {
|
||||
wp_die(esc_html__('权限不足', 'aksrt'));
|
||||
}
|
||||
check_admin_referer('aksrt_pay_batch_charge_cards');
|
||||
|
||||
if (!class_exists('AKSRT_Charge_Card')) {
|
||||
wp_safe_redirect($this->page_url('aksrt_charge_cards', ['aksrt_pay_msg' => 'card_batch_failed']));
|
||||
exit;
|
||||
}
|
||||
|
||||
$type = isset($_POST['type']) ? sanitize_key((string) wp_unslash($_POST['type'])) : 'balance';
|
||||
$count = isset($_POST['count']) ? (int) $_POST['count'] : 10;
|
||||
$length = isset($_POST['length']) ? (int) $_POST['length'] : 16;
|
||||
$prefix = isset($_POST['prefix']) ? sanitize_text_field((string) wp_unslash($_POST['prefix'])) : '';
|
||||
$amount = isset($_POST['amount']) ? (float) wp_unslash($_POST['amount']) : 0;
|
||||
$note = isset($_POST['note']) ? sanitize_textarea_field((string) wp_unslash($_POST['note'])) : '';
|
||||
$level = isset($_POST['vip_level']) ? max(1, min(2, (int) $_POST['vip_level'])) : 1;
|
||||
$days = isset($_POST['vip_days']) ? max(1, (int) $_POST['vip_days']) : 30;
|
||||
$expires = isset($_POST['expires_at']) ? sanitize_text_field((string) wp_unslash($_POST['expires_at'])) : '';
|
||||
if ($expires !== '') {
|
||||
$expires = str_replace('T', ' ', $expires);
|
||||
if (strlen($expires) === 16) {
|
||||
$expires .= ':00';
|
||||
}
|
||||
}
|
||||
|
||||
if ($type === 'points') {
|
||||
$type = 'credits';
|
||||
}
|
||||
|
||||
$meta = [];
|
||||
if ($type === 'balance') {
|
||||
$meta['amount'] = max(0, $amount);
|
||||
} elseif ($type === 'credits') {
|
||||
$meta['points'] = max(0, (int) $amount);
|
||||
} elseif ($type === 'vip') {
|
||||
$meta['level'] = $level;
|
||||
$meta['days'] = $days;
|
||||
}
|
||||
|
||||
$codes = AKSRT_Charge_Card::get_instance()->batch_create($type, $meta, $count, $length, $prefix, $expires, $note);
|
||||
$ok = !empty($codes);
|
||||
if ($ok) {
|
||||
set_transient('aksrt_pay_card_codes_' . get_current_user_id(), $codes, 10 * MINUTE_IN_SECONDS);
|
||||
}
|
||||
|
||||
wp_safe_redirect($this->page_url('aksrt_charge_cards', [
|
||||
'aksrt_pay_msg' => $ok ? 'card_batch_ok' : 'card_batch_failed',
|
||||
'aksrt_generated' => count($codes),
|
||||
]));
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
private function ensure_cap(): void {
|
||||
if (!current_user_can(self::CAPABILITY)) {
|
||||
wp_die(esc_html__('您没有权限访问此页面。', 'aksrt'));
|
||||
}
|
||||
}
|
||||
|
||||
private function render_header(string $title): void {
|
||||
echo '<div class="wrap">';
|
||||
echo '<h1>' . esc_html($title) . '</h1>';
|
||||
$this->render_flash();
|
||||
}
|
||||
|
||||
private function render_footer(): void {
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
private function render_flash(): void {
|
||||
if (empty($_GET['aksrt_pay_msg'])) {
|
||||
return;
|
||||
}
|
||||
$code = sanitize_key((string) wp_unslash($_GET['aksrt_pay_msg']));
|
||||
$map = [
|
||||
'card_disabled' => __('充值卡已禁用。', 'aksrt'),
|
||||
'card_failed' => __('充值卡禁用失败。', 'aksrt'),
|
||||
'card_batch_ok' => __('卡密批量生成完成。', 'aksrt'),
|
||||
'card_batch_failed' => __('卡密批量生成失败。', 'aksrt'),
|
||||
];
|
||||
if (!isset($map[$code])) {
|
||||
return;
|
||||
}
|
||||
$class = str_contains($code, 'failed') ? 'notice-error' : 'notice-success';
|
||||
echo '<div class="notice ' . esc_attr($class) . ' is-dismissible"><p>' . esc_html($map[$code]) . '</p></div>';
|
||||
}
|
||||
|
||||
private function page_url(string $slug, array $args = []): string {
|
||||
return add_query_arg(array_merge(['page' => $slug], $args), admin_url('admin.php'));
|
||||
}
|
||||
|
||||
private function render_pagination(int $pages, int $page_num): void {
|
||||
if ($pages <= 1) {
|
||||
return;
|
||||
}
|
||||
echo '<div class="tablenav"><div class="tablenav-pages">';
|
||||
echo paginate_links([
|
||||
'base' => add_query_arg('paged', '%#%'),
|
||||
'format' => '',
|
||||
'prev_text' => '«',
|
||||
'next_text' => '»',
|
||||
'total' => $pages,
|
||||
'current' => $page_num,
|
||||
]);
|
||||
echo '</div></div>';
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,509 @@
|
||||
<?php
|
||||
/**
|
||||
* Native WP admin: AKSRT_Admin_Pay_Shipping.
|
||||
*
|
||||
* Extracted from AKSRT_Admin_Pay_Menus.
|
||||
*
|
||||
* @package AKSRT
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
class AKSRT_Admin_Pay_Shipping {
|
||||
|
||||
public const CAPABILITY = 'manage_options';
|
||||
public const PAGE_SLUG = 'aksrt_shipping';
|
||||
|
||||
private static $instance = null;
|
||||
|
||||
public static function get_instance(): self {
|
||||
if (null === self::$instance) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
public function init(): void {
|
||||
if (!is_admin()) {
|
||||
return;
|
||||
}
|
||||
add_action('admin_post_aksrt_pay_update_shipping', [$this, 'handle_update_shipping']);
|
||||
add_action('admin_post_aksrt_pay_query_express', [$this, 'handle_query_express']);
|
||||
add_action('admin_post_aksrt_pay_create_shipping', [$this, 'handle_create_shipping']);
|
||||
}
|
||||
|
||||
public function render_shipping_page(): void {
|
||||
$this->ensure_cap();
|
||||
$this->render_header(__('发货及物流', 'aksrt'));
|
||||
|
||||
if (!class_exists('AKSRT_Shipping')) {
|
||||
echo '<div class="notice notice-error"><p>' . esc_html__('物流模块未初始化。', 'aksrt') . '</p></div>';
|
||||
$this->render_footer();
|
||||
return;
|
||||
}
|
||||
|
||||
$view = isset($_GET['view']) ? sanitize_key((string) wp_unslash($_GET['view'])) : 'records';
|
||||
if (!in_array($view, ['records', 'pending'], true)) {
|
||||
$view = 'records';
|
||||
}
|
||||
$status = isset($_GET['status']) ? sanitize_key((string) wp_unslash($_GET['status'])) : '';
|
||||
$search = isset($_GET['s']) ? sanitize_text_field((string) wp_unslash($_GET['s'])) : '';
|
||||
$page_num = max(1, (int) ($_GET['paged'] ?? 1));
|
||||
$per_page = 20;
|
||||
$svc = AKSRT_Shipping::get_instance();
|
||||
$stats = $svc->get_stats();
|
||||
$status_options = $this->shipping_status_options(true);
|
||||
|
||||
$pending_total = 0;
|
||||
if (class_exists('AKSRT_Order_Repository')) {
|
||||
$pending_total = (int) (AKSRT_Order_Repository::get_instance()->get_pending_shipment_orders(['limit' => 1, 'search' => ''])['total'] ?? 0);
|
||||
}
|
||||
|
||||
echo '<p>' . esc_html(sprintf(
|
||||
/* translators: 1: shipping records 2: pending shipment orders */
|
||||
__('物流记录 %1$d 条 · 待发货订单 %2$d', 'aksrt'),
|
||||
(int) ($stats['total'] ?? 0),
|
||||
$pending_total
|
||||
)) . '</p>';
|
||||
|
||||
echo '<h2 class="nav-tab-wrapper" style="margin:12px 0 16px;">';
|
||||
printf(
|
||||
'<a href="%s" class="nav-tab%s">%s</a>',
|
||||
esc_url($this->page_url('aksrt_shipping', ['view' => 'pending'])),
|
||||
$view === 'pending' ? ' nav-tab-active' : '',
|
||||
esc_html(sprintf(__('待发货 (%d)', 'aksrt'), $pending_total))
|
||||
);
|
||||
printf(
|
||||
'<a href="%s" class="nav-tab%s">%s</a>',
|
||||
esc_url($this->page_url('aksrt_shipping', ['view' => 'records'])),
|
||||
$view === 'records' ? ' nav-tab-active' : '',
|
||||
esc_html__('物流记录', 'aksrt')
|
||||
);
|
||||
echo '</h2>';
|
||||
|
||||
if ($view === 'pending') {
|
||||
$this->render_pending_shipment_board($search, $page_num, $per_page);
|
||||
$this->render_footer();
|
||||
return;
|
||||
}
|
||||
|
||||
echo '<h2>' . esc_html__('新建发货', 'aksrt') . '</h2>';
|
||||
echo '<form method="post" action="' . esc_url(admin_url('admin-post.php')) . '" style="margin:8px 0 20px;display:flex;flex-wrap:wrap;gap:8px;align-items:end;">';
|
||||
echo '<input type="hidden" name="action" value="aksrt_pay_create_shipping" />';
|
||||
echo '<input type="hidden" name="redirect_page" value="shipping" />';
|
||||
wp_nonce_field('aksrt_pay_create_shipping');
|
||||
echo '<p><label>' . esc_html__('订单号', 'aksrt') . '<br><input type="text" name="order_number" value="' . esc_attr($search) . '" required class="regular-text" /></label></p>';
|
||||
echo '<p><label>' . esc_html__('承运商', 'aksrt') . '<br>';
|
||||
$this->render_carrier_field('');
|
||||
echo '</label></p>';
|
||||
echo '<p><label>' . esc_html__('运单号', 'aksrt') . '<br><input type="text" name="tracking_no" required /></label></p>';
|
||||
echo '<p><label>' . esc_html__('备注', 'aksrt') . '<br><input type="text" name="note" /></label></p>';
|
||||
submit_button(__('创建发货', 'aksrt'), 'primary', '', false);
|
||||
echo '</form>';
|
||||
|
||||
echo '<form method="get" style="margin:12px 0;">';
|
||||
echo '<input type="hidden" name="page" value="aksrt_shipping" />';
|
||||
echo '<input type="hidden" name="view" value="records" />';
|
||||
echo '<select name="status">';
|
||||
foreach ($status_options as $key => $label) {
|
||||
printf('<option value="%s"%s>%s</option>', esc_attr($key), selected($status, $key, false), esc_html($label));
|
||||
}
|
||||
echo '</select> ';
|
||||
echo '<input type="search" name="s" value="' . esc_attr($search) . '" placeholder="' . esc_attr__('订单号 / 运单号', 'aksrt') . '" /> ';
|
||||
submit_button(__('筛选', 'aksrt'), 'secondary', '', false);
|
||||
echo '</form>';
|
||||
|
||||
$args = [
|
||||
'status' => $status,
|
||||
'limit' => $per_page,
|
||||
'offset' => ($page_num - 1) * $per_page,
|
||||
];
|
||||
if ($search !== '') {
|
||||
if (preg_match('/^[A-Za-z0-9_-]+$/', $search)) {
|
||||
$args['order_number'] = $search;
|
||||
} else {
|
||||
$args['tracking_no'] = $search;
|
||||
}
|
||||
}
|
||||
$result = $svc->get_list($args);
|
||||
$items = $result['items'] ?? [];
|
||||
$total = (int) ($result['total'] ?? 0);
|
||||
$pages = max(1, (int) ceil(max(1, $total) / $per_page));
|
||||
$row_status_options = $this->shipping_status_options(false);
|
||||
$show_express_id = isset($_GET['express_id']) ? (int) $_GET['express_id'] : 0;
|
||||
|
||||
echo '<table class="wp-list-table widefat fixed striped"><thead><tr>';
|
||||
echo '<th>ID</th><th>' . esc_html__('订单号', 'aksrt') . '</th><th>' . esc_html__('承运商', 'aksrt') . '</th><th>' . esc_html__('运单号', 'aksrt') . '</th><th>' . esc_html__('状态', 'aksrt') . '</th><th>' . esc_html__('时间', 'aksrt') . '</th><th>' . esc_html__('操作', 'aksrt') . '</th>';
|
||||
echo '</tr></thead><tbody>';
|
||||
if (!$items) {
|
||||
echo '<tr><td colspan="7">' . esc_html__('暂无物流记录', 'aksrt') . '</td></tr>';
|
||||
}
|
||||
foreach ($items as $row) {
|
||||
$id = (int) ($row['id'] ?? 0);
|
||||
$st = (string) ($row['status'] ?? '');
|
||||
$order_number = (string) ($row['order_number'] ?? '');
|
||||
echo '<tr>';
|
||||
echo '<td>' . esc_html((string) $id) . '</td>';
|
||||
echo '<td><a href="' . esc_url($this->page_url('aksrt_orders', ['order' => $order_number])) . '"><code>' . esc_html($order_number) . '</code></a></td>';
|
||||
echo '<td>' . esc_html((string) ($row['carrier'] ?? '')) . '</td>';
|
||||
echo '<td>' . esc_html((string) ($row['tracking_no'] ?? '')) . '</td>';
|
||||
echo '<td>' . esc_html($row_status_options[$st] ?? $st) . '</td>';
|
||||
echo '<td>' . esc_html((string) ($row['created_at'] ?? '')) . '</td>';
|
||||
echo '<td style="display:flex;gap:6px;flex-wrap:wrap;align-items:center;">';
|
||||
echo '<form method="post" action="' . esc_url(admin_url('admin-post.php')) . '" style="display:flex;gap:4px;align-items:center;">';
|
||||
echo '<input type="hidden" name="action" value="aksrt_pay_update_shipping" />';
|
||||
echo '<input type="hidden" name="shipping_id" value="' . esc_attr((string) $id) . '" />';
|
||||
wp_nonce_field('aksrt_pay_update_shipping_' . $id);
|
||||
echo '<select name="new_status">';
|
||||
foreach ($row_status_options as $key => $label) {
|
||||
printf('<option value="%s"%s>%s</option>', esc_attr($key), selected($st, $key, false), esc_html($label));
|
||||
}
|
||||
echo '</select>';
|
||||
echo '<input type="text" name="note" placeholder="' . esc_attr__('备注', 'aksrt') . '" />';
|
||||
submit_button(__('更新', 'aksrt'), 'small', '', false);
|
||||
echo '</form>';
|
||||
echo '<form method="post" action="' . esc_url(admin_url('admin-post.php')) . '">';
|
||||
echo '<input type="hidden" name="action" value="aksrt_pay_query_express" />';
|
||||
echo '<input type="hidden" name="shipping_id" value="' . esc_attr((string) $id) . '" />';
|
||||
echo '<input type="hidden" name="force" value="1" />';
|
||||
wp_nonce_field('aksrt_pay_query_express_' . $id);
|
||||
submit_button(__('查物流', 'aksrt'), 'small', '', false);
|
||||
echo '</form>';
|
||||
echo '<a class="button button-small" href="' . esc_url($this->page_url('aksrt_shipping', ['view' => 'records', 'express_id' => $id, 's' => $order_number])) . '">' . esc_html__('轨迹', 'aksrt') . '</a>';
|
||||
echo '</td></tr>';
|
||||
if ($show_express_id === $id) {
|
||||
echo '<tr class="aksrt-express-row"><td colspan="7">';
|
||||
$this->render_express_timeline_panel($id);
|
||||
echo '</td></tr>';
|
||||
}
|
||||
}
|
||||
echo '</tbody></table>';
|
||||
$this->render_pagination($pages, $page_num);
|
||||
$this->render_footer();
|
||||
}
|
||||
|
||||
private function render_pending_shipment_board(string $search, int $page_num, int $per_page): void {
|
||||
if (!class_exists('AKSRT_Order_Repository')) {
|
||||
echo '<div class="notice notice-error"><p>' . esc_html__('订单服务不可用。', 'aksrt') . '</p></div>';
|
||||
return;
|
||||
}
|
||||
|
||||
echo '<form method="get" style="margin:12px 0;">';
|
||||
echo '<input type="hidden" name="page" value="aksrt_shipping" />';
|
||||
echo '<input type="hidden" name="view" value="pending" />';
|
||||
echo '<input type="search" name="s" value="' . esc_attr($search) . '" placeholder="' . esc_attr__('订单号 / 类型', 'aksrt') . '" /> ';
|
||||
submit_button(__('筛选', 'aksrt'), 'secondary', '', false);
|
||||
echo '</form>';
|
||||
|
||||
$result = AKSRT_Order_Repository::get_instance()->get_pending_shipment_orders([
|
||||
'search' => $search,
|
||||
'limit' => $per_page,
|
||||
'offset' => ($page_num - 1) * $per_page,
|
||||
]);
|
||||
$items = $result['items'] ?? [];
|
||||
$total = (int) ($result['total'] ?? 0);
|
||||
$pages = max(1, (int) ($result['max_pages'] ?? 1));
|
||||
$labels = class_exists('AKSRT_Domain_Model')
|
||||
? AKSRT_Domain_Model::order_status_labels()
|
||||
: [];
|
||||
|
||||
echo '<table class="wp-list-table widefat fixed striped"><thead><tr>';
|
||||
echo '<th>' . esc_html__('订单号', 'aksrt') . '</th>';
|
||||
echo '<th>' . esc_html__('用户', 'aksrt') . '</th>';
|
||||
echo '<th>' . esc_html__('类型', 'aksrt') . '</th>';
|
||||
echo '<th>' . esc_html__('金额', 'aksrt') . '</th>';
|
||||
echo '<th>' . esc_html__('状态', 'aksrt') . '</th>';
|
||||
echo '<th>' . esc_html__('支付时间', 'aksrt') . '</th>';
|
||||
echo '<th>' . esc_html__('立即发货', 'aksrt') . '</th>';
|
||||
echo '</tr></thead><tbody>';
|
||||
|
||||
if (!$items) {
|
||||
echo '<tr><td colspan="7">' . esc_html__('暂无待发货订单', 'aksrt') . '</td></tr>';
|
||||
}
|
||||
|
||||
foreach ($items as $row) {
|
||||
$order_number = (string) ($row['order_number'] ?? '');
|
||||
$user_id = (int) ($row['user_id'] ?? 0);
|
||||
$user = $user_id > 0 ? get_userdata($user_id) : null;
|
||||
$status_key = (string) ($row['status'] ?? '');
|
||||
echo '<tr>';
|
||||
echo '<td><a href="' . esc_url($this->page_url('aksrt_orders', ['order' => $order_number])) . '"><code>' . esc_html($order_number) . '</code></a></td>';
|
||||
echo '<td>' . ($user ? esc_html($user->display_name . ' (#' . $user_id . ')') : esc_html((string) $user_id)) . '</td>';
|
||||
echo '<td>' . esc_html((string) ($row['product_type'] ?? '')) . '</td>';
|
||||
echo '<td>' . esc_html(number_format((float) ($row['amount'] ?? 0), 2)) . ' ' . esc_html((string) ($row['currency'] ?? '')) . '</td>';
|
||||
echo '<td>' . esc_html($labels[$status_key] ?? $status_key) . '</td>';
|
||||
echo '<td>' . esc_html((string) ($row['paid_at'] ?? $row['created_at'] ?? '')) . '</td>';
|
||||
echo '<td>';
|
||||
echo '<form method="post" action="' . esc_url(admin_url('admin-post.php')) . '" style="display:flex;flex-wrap:wrap;gap:4px;align-items:center;">';
|
||||
echo '<input type="hidden" name="action" value="aksrt_pay_create_shipping" />';
|
||||
echo '<input type="hidden" name="order_number" value="' . esc_attr($order_number) . '" />';
|
||||
echo '<input type="hidden" name="redirect_page" value="pending" />';
|
||||
wp_nonce_field('aksrt_pay_create_shipping_' . $order_number);
|
||||
$this->render_carrier_field('');
|
||||
echo '<input type="text" name="tracking_no" required placeholder="' . esc_attr__('运单号', 'aksrt') . '" />';
|
||||
echo '<input type="text" name="note" placeholder="' . esc_attr__('备注', 'aksrt') . '" />';
|
||||
submit_button(__('发货', 'aksrt'), 'primary small', '', false);
|
||||
echo '</form>';
|
||||
echo '</td>';
|
||||
echo '</tr>';
|
||||
}
|
||||
echo '</tbody></table>';
|
||||
$this->render_pagination($pages, $page_num);
|
||||
}
|
||||
|
||||
public function handle_update_shipping(): void {
|
||||
if (!current_user_can(self::CAPABILITY)) {
|
||||
wp_die(esc_html__('权限不足', 'aksrt'));
|
||||
}
|
||||
$id = isset($_POST['shipping_id']) ? (int) $_POST['shipping_id'] : 0;
|
||||
$new_status = isset($_POST['new_status']) ? sanitize_key((string) wp_unslash($_POST['new_status'])) : '';
|
||||
$note = isset($_POST['note']) ? sanitize_textarea_field((string) wp_unslash($_POST['note'])) : '';
|
||||
check_admin_referer('aksrt_pay_update_shipping_' . $id);
|
||||
|
||||
$ok = false;
|
||||
if ($id > 0 && $new_status !== '' && class_exists('AKSRT_Shipping')) {
|
||||
$ok = AKSRT_Shipping::get_instance()->update_status($id, $new_status, $note, get_current_user_id());
|
||||
}
|
||||
|
||||
$redirect_order = isset($_POST['redirect_order']) ? sanitize_text_field((string) wp_unslash($_POST['redirect_order'])) : '';
|
||||
if ($redirect_order !== '') {
|
||||
wp_safe_redirect($this->page_url('aksrt_orders', [
|
||||
'order' => $redirect_order,
|
||||
'aksrt_pay_msg' => $ok ? 'shipping_updated' : 'shipping_failed',
|
||||
]));
|
||||
exit;
|
||||
}
|
||||
|
||||
wp_safe_redirect($this->page_url('aksrt_shipping', [
|
||||
'view' => 'records',
|
||||
'aksrt_pay_msg' => $ok ? 'shipping_updated' : 'shipping_failed',
|
||||
]));
|
||||
exit;
|
||||
}
|
||||
|
||||
public function handle_query_express(): void {
|
||||
if (!current_user_can(self::CAPABILITY)) {
|
||||
wp_die(esc_html__('权限不足', 'aksrt'));
|
||||
}
|
||||
$id = isset($_POST['shipping_id']) ? (int) $_POST['shipping_id'] : 0;
|
||||
$force = !empty($_POST['force']);
|
||||
check_admin_referer('aksrt_pay_query_express_' . $id);
|
||||
|
||||
$ok = false;
|
||||
$order_number = '';
|
||||
if ($id > 0 && class_exists('AKSRT_Shipping')) {
|
||||
$svc = AKSRT_Shipping::get_instance();
|
||||
$record = $svc->get($id);
|
||||
$order_number = is_array($record) ? (string) ($record['order_number'] ?? '') : '';
|
||||
$result = $svc->query_express($id, $force);
|
||||
$ok = !empty($result['success']);
|
||||
}
|
||||
|
||||
wp_safe_redirect($this->page_url('aksrt_shipping', [
|
||||
'view' => 'records',
|
||||
'express_id' => $id,
|
||||
's' => $order_number,
|
||||
'aksrt_pay_msg' => $ok ? 'express_ok' : 'express_failed',
|
||||
]));
|
||||
exit;
|
||||
}
|
||||
|
||||
public function handle_create_shipping(): void {
|
||||
if (!current_user_can(self::CAPABILITY)) {
|
||||
wp_die(esc_html__('权限不足', 'aksrt'));
|
||||
}
|
||||
$order_number = isset($_POST['order_number']) ? sanitize_text_field((string) wp_unslash($_POST['order_number'])) : '';
|
||||
$redirect_page = isset($_POST['redirect_page']) ? sanitize_key((string) wp_unslash($_POST['redirect_page'])) : 'order';
|
||||
$nonce_action = $redirect_page === 'shipping' ? 'aksrt_pay_create_shipping' : ('aksrt_pay_create_shipping_' . $order_number);
|
||||
check_admin_referer($nonce_action);
|
||||
|
||||
$ok = false;
|
||||
if ($order_number !== '' && class_exists('AKSRT_Shipping')) {
|
||||
if (class_exists('AKSRT_Order_Repository')) {
|
||||
$order = AKSRT_Order_Repository::get_instance()->get($order_number);
|
||||
if (!$order) {
|
||||
$this->redirect_shipping_create_result(false, $order_number, $redirect_page);
|
||||
}
|
||||
}
|
||||
$id = AKSRT_Shipping::get_instance()->create([
|
||||
'order_number' => $order_number,
|
||||
'carrier' => sanitize_text_field((string) wp_unslash($_POST['carrier'] ?? '')),
|
||||
'tracking_no' => sanitize_text_field((string) wp_unslash($_POST['tracking_no'] ?? '')),
|
||||
'note' => sanitize_textarea_field((string) wp_unslash($_POST['note'] ?? '')),
|
||||
'operator_id' => get_current_user_id(),
|
||||
]);
|
||||
$ok = $id > 0;
|
||||
}
|
||||
|
||||
$this->redirect_shipping_create_result($ok, $order_number, $redirect_page);
|
||||
}
|
||||
|
||||
private function redirect_shipping_create_result(bool $ok, string $order_number, string $redirect_page): void {
|
||||
$msg = $ok ? 'shipping_created' : 'shipping_create_failed';
|
||||
if ($redirect_page === 'shipping') {
|
||||
wp_safe_redirect($this->page_url('aksrt_shipping', [
|
||||
'view' => 'records',
|
||||
'aksrt_pay_msg' => $msg,
|
||||
's' => $order_number,
|
||||
]));
|
||||
exit;
|
||||
}
|
||||
if ($redirect_page === 'pending') {
|
||||
wp_safe_redirect($this->page_url('aksrt_shipping', [
|
||||
'view' => 'pending',
|
||||
'aksrt_pay_msg' => $msg,
|
||||
]));
|
||||
exit;
|
||||
}
|
||||
wp_safe_redirect($this->page_url('aksrt_orders', [
|
||||
'order' => $order_number,
|
||||
'aksrt_pay_msg' => $msg,
|
||||
]));
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
public function shipping_status_options_public(bool $include_all = false): array {
|
||||
return $this->shipping_status_options($include_all);
|
||||
}
|
||||
|
||||
private function shipping_status_options(bool $include_all = false): array {
|
||||
$options = [];
|
||||
if ($include_all) {
|
||||
$options[''] = __('全部状态', 'aksrt');
|
||||
}
|
||||
if (class_exists('AKSRT_Shipping')) {
|
||||
foreach (AKSRT_Shipping::get_status_options() as $item) {
|
||||
$value = (string) ($item['value'] ?? '');
|
||||
if ($value === '') {
|
||||
continue;
|
||||
}
|
||||
$options[$value] = (string) ($item['label'] ?? $value);
|
||||
}
|
||||
}
|
||||
if (count($options) === (int) $include_all) {
|
||||
$options = array_merge($options, [
|
||||
'shipped' => __('已发货', 'aksrt'),
|
||||
'in_transit' => __('运输中', 'aksrt'),
|
||||
'delivered' => __('已签收', 'aksrt'),
|
||||
'returned' => __('已退回', 'aksrt'),
|
||||
]);
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
public function render_carrier_field_public(string $selected = ''): void {
|
||||
$this->render_carrier_field($selected);
|
||||
}
|
||||
|
||||
private function render_carrier_field(string $selected = ''): void {
|
||||
$options = [];
|
||||
if (class_exists('AKSRT_Shipping')) {
|
||||
foreach (AKSRT_Shipping::get_carrier_options() as $item) {
|
||||
$value = (string) ($item['value'] ?? '');
|
||||
$label = (string) ($item['label'] ?? $value);
|
||||
if ($value !== '') {
|
||||
$options[$value] = $label;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($options) {
|
||||
echo '<select name="carrier" required>';
|
||||
foreach ($options as $value => $label) {
|
||||
printf(
|
||||
'<option value="%s"%s>%s</option>',
|
||||
esc_attr($value),
|
||||
selected($selected, $value, false),
|
||||
esc_html($label)
|
||||
);
|
||||
}
|
||||
echo '</select>';
|
||||
return;
|
||||
}
|
||||
echo '<input type="text" name="carrier" value="' . esc_attr($selected) . '" required placeholder="SF/YTO/..." />';
|
||||
}
|
||||
private function render_express_timeline_panel(int $shipping_id): void {
|
||||
if ($shipping_id <= 0 || !class_exists('AKSRT_Shipping')) {
|
||||
echo '<p>' . esc_html__('无法加载物流轨迹。', 'aksrt') . '</p>';
|
||||
return;
|
||||
}
|
||||
$svc = AKSRT_Shipping::get_instance();
|
||||
// Prefer cached data; do not force remote query on pure view.
|
||||
$timeline = $svc->build_express_timeline($shipping_id);
|
||||
$record = $svc->get($shipping_id);
|
||||
echo '<div style="padding:10px 12px;background:#f6f7f7;border:1px solid #dcdcde;">';
|
||||
echo '<p style="margin:0 0 8px;"><strong>' . esc_html__('物流轨迹', 'aksrt') . '</strong> · ';
|
||||
echo esc_html((string) ($record['carrier'] ?? '')) . ' / ' . esc_html((string) ($record['tracking_no'] ?? ''));
|
||||
echo '</p>';
|
||||
if (!$timeline) {
|
||||
echo '<p style="margin:0;">' . esc_html__('暂无轨迹,可点击「查物流」拉取快递 API。', 'aksrt') . '</p>';
|
||||
echo '</div>';
|
||||
return;
|
||||
}
|
||||
echo '<ol style="margin:0;padding-left:18px;">';
|
||||
// newest first for operators
|
||||
$timeline = array_reverse($timeline);
|
||||
foreach ($timeline as $item) {
|
||||
$time = (string) ($item['time'] ?? '');
|
||||
$label = (string) ($item['label'] ?? '');
|
||||
echo '<li style="margin:0 0 6px;"><code>' . esc_html($time) . '</code> ' . esc_html($label) . '</li>';
|
||||
}
|
||||
echo '</ol></div>';
|
||||
}
|
||||
|
||||
|
||||
private function ensure_cap(): void {
|
||||
if (!current_user_can(self::CAPABILITY)) {
|
||||
wp_die(esc_html__('您没有权限访问此页面。', 'aksrt'));
|
||||
}
|
||||
}
|
||||
|
||||
private function render_header(string $title): void {
|
||||
echo '<div class="wrap">';
|
||||
echo '<h1>' . esc_html($title) . '</h1>';
|
||||
$this->render_flash();
|
||||
}
|
||||
|
||||
private function render_footer(): void {
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
private function render_flash(): void {
|
||||
if (empty($_GET['aksrt_pay_msg'])) {
|
||||
return;
|
||||
}
|
||||
$code = sanitize_key((string) wp_unslash($_GET['aksrt_pay_msg']));
|
||||
$map = [
|
||||
'shipping_updated' => __('物流状态已更新。', 'aksrt'),
|
||||
'shipping_failed' => __('物流状态更新失败。', 'aksrt'),
|
||||
'shipping_created' => __('发货记录已创建。', 'aksrt'),
|
||||
'shipping_create_failed' => __('发货记录创建失败。', 'aksrt'),
|
||||
'express_ok' => __('物流轨迹已更新。', 'aksrt'),
|
||||
'express_failed' => __('物流轨迹查询失败。', 'aksrt'),
|
||||
];
|
||||
if (!isset($map[$code])) {
|
||||
return;
|
||||
}
|
||||
$class = str_contains($code, 'failed') ? 'notice-error' : 'notice-success';
|
||||
echo '<div class="notice ' . esc_attr($class) . ' is-dismissible"><p>' . esc_html($map[$code]) . '</p></div>';
|
||||
}
|
||||
|
||||
private function page_url(string $slug, array $args = []): string {
|
||||
return add_query_arg(array_merge(['page' => $slug], $args), admin_url('admin.php'));
|
||||
}
|
||||
|
||||
private function render_pagination(int $pages, int $page_num): void {
|
||||
if ($pages <= 1) {
|
||||
return;
|
||||
}
|
||||
echo '<div class="tablenav"><div class="tablenav-pages">';
|
||||
echo paginate_links([
|
||||
'base' => add_query_arg('paged', '%#%'),
|
||||
'format' => '',
|
||||
'prev_text' => '«',
|
||||
'next_text' => '»',
|
||||
'total' => $pages,
|
||||
'current' => $page_num,
|
||||
]);
|
||||
echo '</div></div>';
|
||||
}
|
||||
}
|
||||
@@ -87,8 +87,11 @@ class AKSRT_Plate_Meta_Box {
|
||||
$add_roles = get_post_meta($plate_id, '_aksrt_add_limit_roles', true);
|
||||
$add_roles = is_array($add_roles) ? array_map('sanitize_key', $add_roles) : [];
|
||||
$wp_roles = $this->wp_role_options();
|
||||
$icon = (string) get_post_meta($plate_id, '_aksrt_icon', true);
|
||||
$sort_order = (int) get_post_meta($plate_id, '_aksrt_sort_order', true);
|
||||
|
||||
$this->render_access_fields($allow_view, $add_limit, $view_roles, $add_roles, $wp_roles);
|
||||
$this->render_display_fields($icon, $sort_order);
|
||||
$this->render_moderator_fields($moderator_ids, $roles_map, $author_id);
|
||||
$this->render_applications($applications);
|
||||
}
|
||||
@@ -148,6 +151,22 @@ class AKSRT_Plate_Meta_Box {
|
||||
<?php
|
||||
}
|
||||
|
||||
private function render_display_fields(string $icon, int $sort_order): void {
|
||||
?>
|
||||
<p>
|
||||
<label for="aksrt_plate_icon"><strong><?php esc_html_e('图标', 'aksrt'); ?></strong></label>
|
||||
<input type="text" id="aksrt_plate_icon" name="aksrt_plate_icon" class="widefat" value="<?php echo esc_attr($icon); ?>" placeholder="fa-comments / dashicons-admin-site" />
|
||||
<span class="description"><?php esc_html_e('图标 class 或标识,保存即重写。', 'aksrt'); ?></span>
|
||||
</p>
|
||||
<p>
|
||||
<label for="aksrt_plate_sort_order"><strong><?php esc_html_e('排序', 'aksrt'); ?></strong></label>
|
||||
<input type="number" id="aksrt_plate_sort_order" name="aksrt_plate_sort_order" class="widefat" value="<?php echo esc_attr((string) $sort_order); ?>" step="1" />
|
||||
<span class="description"><?php esc_html_e('数字越小越靠前。', 'aksrt'); ?></span>
|
||||
</p>
|
||||
<hr>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<int> $moderator_ids
|
||||
* @param array<int|string,string> $roles_map
|
||||
@@ -261,10 +280,23 @@ class AKSRT_Plate_Meta_Box {
|
||||
}
|
||||
|
||||
$this->save_access_meta($post_id);
|
||||
$this->save_display_meta($post_id);
|
||||
$this->save_moderators($post_id, (int) $post->post_author);
|
||||
$this->save_applications();
|
||||
}
|
||||
|
||||
private function save_display_meta(int $post_id): void {
|
||||
$icon = isset($_POST['aksrt_plate_icon'])
|
||||
? sanitize_text_field((string) wp_unslash($_POST['aksrt_plate_icon']))
|
||||
: '';
|
||||
update_post_meta($post_id, '_aksrt_icon', $icon);
|
||||
|
||||
$sort = isset($_POST['aksrt_plate_sort_order'])
|
||||
? (int) wp_unslash($_POST['aksrt_plate_sort_order'])
|
||||
: 0;
|
||||
update_post_meta($post_id, '_aksrt_sort_order', $sort);
|
||||
}
|
||||
|
||||
private function save_access_meta(int $post_id): void {
|
||||
$allow_view = isset($_POST['aksrt_plate_allow_view']) ? sanitize_key((string) wp_unslash($_POST['aksrt_plate_allow_view'])) : 'public';
|
||||
if (!in_array($allow_view, self::ALLOW_VIEW, true)) {
|
||||
|
||||
Reference in New Issue
Block a user