feat(pay): alone download page, free-login gate, list pay badges
This commit is contained in:
@@ -145,28 +145,54 @@ if (!function_exists('aksrt_resource_price_amount')) {
|
||||
|
||||
if (!function_exists('aksrt_resource_card_badge_text')) {
|
||||
/**
|
||||
* Resource badge text used in mixed post cards.
|
||||
* List-card pay badge (Zibll zib_get_posts_list_pay_tags equivalent).
|
||||
*
|
||||
* Only resource-type posts should render this badge.
|
||||
* Renders for any paid post type, not only download resources.
|
||||
* Returns plain text; card template wraps with link + class.
|
||||
*
|
||||
* @param int|WP_Post|null $post
|
||||
* @return string
|
||||
*/
|
||||
function aksrt_resource_card_badge_text($post = null): string {
|
||||
if (!function_exists('aksrt_is_resource_post') || !aksrt_is_resource_post($post)) {
|
||||
$p = get_post($post);
|
||||
if (!($p instanceof WP_Post)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$meta = aksrt_get_resource_meta($post);
|
||||
$price = (float) $meta['price'];
|
||||
|
||||
if ($price <= 0) {
|
||||
// 免费资源不在卡片上显示价格 chip。
|
||||
$meta = function_exists('aksrt_get_pay_meta') ? aksrt_get_pay_meta($p) : null;
|
||||
if (!is_array($meta)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$pay_type = (string) ($meta['pay_type'] ?? 'no');
|
||||
if ($pay_type === '' || $pay_type === 'no') {
|
||||
return '';
|
||||
}
|
||||
|
||||
$price = (float) ($meta['price'] ?? 0);
|
||||
$type_labels = function_exists('aksrt_get_pay_types') ? aksrt_get_pay_types() : [];
|
||||
$type_name = $type_labels[$pay_type] ?? __('付费内容', 'aksrt');
|
||||
|
||||
// VIP-only posts.
|
||||
if ($pay_type === 'vip') {
|
||||
return __('会员专属', 'aksrt');
|
||||
}
|
||||
|
||||
// Free paid-type (price 0): Zibll shows "免费资源" / free type name.
|
||||
if ($price <= 0) {
|
||||
if ($pay_type === 'download') {
|
||||
return __('免费资源', 'aksrt');
|
||||
}
|
||||
// e.g. 付费阅读 → 免费阅读
|
||||
return str_replace(__('付费', 'aksrt'), __('免费', 'aksrt'), (string) $type_name);
|
||||
}
|
||||
|
||||
$currency = class_exists('AKSRT_Settings') ? AKSRT_Settings::get_currency_name() : __('积分', 'aksrt');
|
||||
return sprintf(__('付费 %s %s', 'aksrt'), aksrt_resource_price_amount($price), $currency);
|
||||
$amount = function_exists('aksrt_resource_price_amount')
|
||||
? aksrt_resource_price_amount($price)
|
||||
: (string) $price;
|
||||
|
||||
return sprintf('%s %s%s', $type_name, $amount, $currency);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user