feat(identity): author card, per-user tip, comment caps, task status
Author card uses configurable limit/orderby/style and self CTAs. Tip is per-user weixin/alipay QR modal (no site-global image). Comment action permissions honor user_caps matrix. Free points tasks expose done_today/passive status + better comment deep link. audit-admin-contracts errors=0.
This commit is contained in:
1 parent
b4d04ae346
commit
8d4e94a02c
10 files changed
+374
-148
No files matched your search
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
/**
|
||||
* Per-user tip (打赏) helpers — Zibll post_rewards_s + user QR parity.
|
||||
*
|
||||
* Meta: aksrt_rewards_weixin, aksrt_rewards_alipay (attachment id or URL).
|
||||
*
|
||||
* @package AKSRT
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
if (!function_exists('aksrt_rewards_enabled')) {
|
||||
function aksrt_rewards_enabled(): bool {
|
||||
if (!class_exists('AKSRT_Settings') || !method_exists('AKSRT_Settings', 'get_post_page_settings')) {
|
||||
return false;
|
||||
}
|
||||
$s = AKSRT_Settings::get_post_page_settings();
|
||||
return !empty($s['rewards_enabled']) || !empty($s['post_rewards_s']);
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('aksrt_get_user_rewards_img_urls')) {
|
||||
/**
|
||||
* @return array{weixin:string,alipay:string}
|
||||
*/
|
||||
function aksrt_get_user_rewards_img_urls(int $user_id): array {
|
||||
$out = ['weixin' => '', 'alipay' => ''];
|
||||
if ($user_id <= 0) {
|
||||
return $out;
|
||||
}
|
||||
foreach (['weixin' => 'aksrt_rewards_weixin', 'alipay' => 'aksrt_rewards_alipay'] as $key => $meta) {
|
||||
$raw = get_user_meta($user_id, $meta, true);
|
||||
if (is_numeric($raw) && (int) $raw > 0) {
|
||||
$url = wp_get_attachment_image_url((int) $raw, 'full');
|
||||
$out[$key] = is_string($url) ? $url : '';
|
||||
} else {
|
||||
$out[$key] = esc_url_raw((string) $raw);
|
||||
}
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('aksrt_user_has_rewards_qr')) {
|
||||
function aksrt_user_has_rewards_qr(int $user_id): bool {
|
||||
$urls = aksrt_get_user_rewards_img_urls($user_id);
|
||||
return $urls['weixin'] !== '' || $urls['alipay'] !== '';
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('aksrt_get_rewards_button')) {
|
||||
function aksrt_get_rewards_button(int $user_id, string $class = 'but jb-blue ml10 pw-1em'): string {
|
||||
if ($user_id <= 0 || !aksrt_rewards_enabled() || !aksrt_user_has_rewards_qr($user_id)) {
|
||||
return '';
|
||||
}
|
||||
$label = '赞赏';
|
||||
if (class_exists('AKSRT_Settings') && method_exists('AKSRT_Settings', 'get_post_page_settings')) {
|
||||
$s = AKSRT_Settings::get_post_page_settings();
|
||||
$label = (string) ($s['rewards_btn_text'] ?? $s['rewards_text'] ?? $label);
|
||||
if ($label === '') {
|
||||
$label = '赞赏';
|
||||
}
|
||||
}
|
||||
return '<button type="button" class="' . esc_attr($class) . ' aksrt-reward-open" data-aksrt-reward-open data-user-id="' . (int) $user_id . '"><i class="fa fa-gift em09" aria-hidden="true"></i> ' . esc_html($label) . '</button>';
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('aksrt_render_rewards_modal_for_user')) {
|
||||
function aksrt_render_rewards_modal_for_user(int $user_id): void {
|
||||
static $done = [];
|
||||
if ($user_id <= 0 || isset($done[$user_id])) {
|
||||
return;
|
||||
}
|
||||
if (!aksrt_rewards_enabled() || !aksrt_user_has_rewards_qr($user_id)) {
|
||||
return;
|
||||
}
|
||||
$done[$user_id] = true;
|
||||
$urls = aksrt_get_user_rewards_img_urls($user_id);
|
||||
$label = '赞赏';
|
||||
if (class_exists('AKSRT_Settings') && method_exists('AKSRT_Settings', 'get_post_page_settings')) {
|
||||
$s = AKSRT_Settings::get_post_page_settings();
|
||||
$label = (string) ($s['rewards_text'] ?? $label);
|
||||
if ($label === '') {
|
||||
$label = __('赞赏', 'aksrt');
|
||||
}
|
||||
}
|
||||
?>
|
||||
<div class="reward-modal" id="reward-modal-<?php echo (int) $user_id; ?>" data-user-id="<?php echo (int) $user_id; ?>" aria-hidden="true">
|
||||
<div class="reward-modal__overlay" data-aksrt-reward-close></div>
|
||||
<div class="reward-modal__dialog" role="dialog" aria-modal="true">
|
||||
<button type="button" class="reward-modal__close" data-aksrt-reward-close aria-label="<?php esc_attr_e('关闭', 'aksrt'); ?>"><i class="fas fa-times" aria-hidden="true"></i></button>
|
||||
<div class="reward-modal__content">
|
||||
<h3><?php echo esc_html($label); ?></h3>
|
||||
<div class="reward-modal__qrcodes flex jc ac hh">
|
||||
<?php if ($urls['weixin'] !== '') : ?>
|
||||
<div class="reward-modal__qrcode text-center mr10">
|
||||
<img src="<?php echo esc_url($urls['weixin']); ?>" alt="<?php esc_attr_e('微信收款码', 'aksrt'); ?>" loading="lazy" decoding="async" />
|
||||
<div class="em09 muted-2-color mt6"><?php esc_html_e('微信', 'aksrt'); ?></div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php if ($urls['alipay'] !== '') : ?>
|
||||
<div class="reward-modal__qrcode text-center">
|
||||
<img src="<?php echo esc_url($urls['alipay']); ?>" alt="<?php esc_attr_e('支付宝收款码', 'aksrt'); ?>" loading="lazy" decoding="async" />
|
||||
<div class="em09 muted-2-color mt6"><?php esc_html_e('支付宝', 'aksrt'); ?></div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user