feat(forum): guest cash purchase for topic and plate follow

- Reuse pay_no_logged_in / pay_cookie_day; generalized guest cookie helpers
- Topic + plate cash: guest preview/purchase (no balance), order.user_id=0, cookie unlock
- View gates: can_view_topic pay + plate follow accept signed guest cookies
- Templates: guest buy/follow CTAs; poll endpoint allows plate_follow guest orders
This commit is contained in:
kate522 committed 2026-07-15 13:58:54 +08:00
1 parent a9150862ef
commit 6b6314b033
9 files changed
+274 -70

No files matched your search

+29
View File
@@ -106,6 +106,20 @@ $max_pages = (int) ($view['pagination']['max_pages'] ?? 1);
</div>
<div class="aksrt-forum-board__actions">
<?php
$follow_pay_on = $forum && method_exists($forum, 'is_plate_follow_pay_enabled')
? $forum->is_plate_follow_pay_enabled($plate_id)
: ((int) get_post_meta($plate_id, '_aksrt_follow_pay', true) === 1);
$follow_pay_modo = sanitize_key((string) (get_post_meta($plate_id, '_aksrt_follow_pay_modo', true) ?: 'money'));
$allow_guest_plate = $current_user_id <= 0
&& $follow_pay_on
&& $follow_pay_modo === 'money'
&& function_exists('aksrt_allow_guest_forum_pay')
&& aksrt_allow_guest_forum_pay(get_post($plate_id));
$guest_followed = $current_user_id <= 0
&& function_exists('aksrt_guest_has_plate_follow_access')
&& aksrt_guest_has_plate_follow_access($plate_id);
?>
<?php if ($current_user_id > 0) : ?>
<button type="button"
class="aksrt-forum-board__follow-btn js-aksrt-follow-plate"
@@ -114,6 +128,21 @@ $max_pages = (int) ($view['pagination']['max_pages'] ?? 1);
<i class="fas fa-heart"></i>
<?php echo $is_followed ? esc_html__('已关注', 'aksrt') : esc_html__('关注', 'aksrt'); ?>
</button>
<?php elseif ($guest_followed) : ?>
<button type="button" class="aksrt-forum-board__follow-btn is-followed" disabled>
<i class="fas fa-heart"></i>
<?php esc_html_e('已关注', 'aksrt'); ?>
</button>
<?php elseif ($allow_guest_plate) : ?>
<button type="button"
class="aksrt-forum-board__follow-btn"
data-aksrt-pay-plate-follow="<?php echo esc_attr((string) $plate_id); ?>">
<i class="fas fa-heart"></i>
<?php esc_html_e('付费关注', 'aksrt'); ?>
</button>
<p class="description" style="margin-top:6px;font-size:12px;">
<?php esc_html_e('未登录关注通过 Cookie 生效;建议登录后关注以便保存订单。', 'aksrt'); ?>
</p>
<?php endif; ?>
<?php if (!empty($permissions['can_compose'])) : ?>
+14 -3
View File
@@ -192,7 +192,12 @@ if (empty($topic['can_view'])) :
<?php elseif ($charge_amount > 0 || $base_amount > 0) : ?>
<span class="aksrt-forum-topic__pay-price"><?php printf(esc_html__('价格:¥%s', 'aksrt'), esc_html(number_format(max($charge_amount, $base_amount), 2, '.', ''))); ?></span>
<?php endif; ?>
<?php if (!is_user_logged_in()) : ?>
<?php
$allow_guest_topic = !is_user_logged_in()
&& function_exists('aksrt_allow_guest_forum_pay')
&& aksrt_allow_guest_forum_pay(get_post($topic_id));
?>
<?php if (!is_user_logged_in() && !$allow_guest_topic) : ?>
<a href="<?php echo esc_url(wp_login_url(get_permalink($topic_id))); ?>" class="aksrt-forum-topic__primary-btn"><?php esc_html_e('登录后购买', 'aksrt'); ?></a>
<?php else : ?>
<button type="button" class="aksrt-forum-topic__primary-btn"
@@ -201,13 +206,19 @@ if (empty($topic['can_view'])) :
data-free="<?php echo $is_free_vip ? '1' : '0'; ?>">
<i class="fas fa-shopping-cart"></i>
<?php
if ($is_free_vip) {
if ($is_free_vip && is_user_logged_in()) {
esc_html_e('VIP 免费解锁', 'aksrt');
} else {
printf(esc_html__('购买解锁 ¥%s', 'aksrt'), esc_html(number_format($charge_amount, 2, '.', '')));
printf(esc_html__('购买解锁 ¥%s', 'aksrt'), esc_html(number_format(max($charge_amount, $base_amount), 2, '.', '')));
}
?>
</button>
<?php if ($allow_guest_topic) : ?>
<p class="description" style="margin-top:8px;">
<?php esc_html_e('未登录购买将通过浏览器 Cookie 解锁;建议登录后购买以便保存订单。', 'aksrt'); ?>
<a href="<?php echo esc_url(wp_login_url(get_permalink($topic_id))); ?>"><?php esc_html_e('去登录', 'aksrt'); ?></a>
</p>
<?php endif; ?>
<span class="aksrt-forum-topic__unlock-feedback js-aksrt-action-feedback" aria-live="polite"></span>
<?php endif; ?>
<?php else : ?>