feat: upgrade widgets and affiliate commission flow
This commit is contained in:
@@ -133,8 +133,8 @@ if (!function_exists('aksrt_get_user_center_tab_url')) {
|
||||
*/
|
||||
function aksrt_get_user_center_tab_url(string $tab): string {
|
||||
$tab = sanitize_key($tab);
|
||||
if ('invite' === $tab || 'promotion' === $tab) {
|
||||
$tab = 'revenue';
|
||||
if ('invite' === $tab) {
|
||||
$tab = 'promotion';
|
||||
}
|
||||
return aksrt_get_user_center_url($tab);
|
||||
}
|
||||
@@ -180,6 +180,7 @@ if (!function_exists('aksrt_capture_user_center_view')) {
|
||||
'vip' => 'vip',
|
||||
'orders' => 'orders',
|
||||
'auth' => 'auth',
|
||||
'promotion' => 'promotion',
|
||||
'revenue' => 'revenue',
|
||||
'settings' => 'settings',
|
||||
'header' => 'header',
|
||||
@@ -205,7 +206,7 @@ if (!function_exists('aksrt_capture_user_center_panel')) {
|
||||
* Capture a built-in or registered user-center panel body.
|
||||
*/
|
||||
function aksrt_capture_user_center_panel(string $tab_key, array $tab, array $context): string {
|
||||
$built_in_tabs = ['profile', 'level', 'creator', 'posts', 'follow', 'comments', 'favorites', 'credits', 'vip', 'orders', 'auth', 'revenue', 'settings'];
|
||||
$built_in_tabs = ['profile', 'level', 'creator', 'posts', 'follow', 'comments', 'favorites', 'credits', 'vip', 'orders', 'auth', 'promotion', 'revenue', 'settings'];
|
||||
if (in_array($tab_key, $built_in_tabs, true)) {
|
||||
return aksrt_capture_user_center_view($tab_key, $context);
|
||||
}
|
||||
@@ -314,8 +315,8 @@ if (!function_exists('aksrt_user_center_resolve_tabs')) {
|
||||
}
|
||||
if ('signin' === $active || 'assets' === $active) {
|
||||
$active = 'credits';
|
||||
} elseif ('invite' === $active || 'promotion' === $active) {
|
||||
$active = 'revenue';
|
||||
} elseif ('invite' === $active) {
|
||||
$active = 'promotion';
|
||||
} elseif ('vip' === $active) {
|
||||
// Prefer dedicated vip tab when registered; else credits (VIP shop).
|
||||
$active = in_array('vip', $keys, true) ? 'vip' : 'credits';
|
||||
@@ -354,8 +355,7 @@ if (!function_exists('aksrt_user_center_runtime_config')) {
|
||||
'activeTab' => $active_tab,
|
||||
'tabAliases' => [
|
||||
'signin' => 'credits',
|
||||
'invite' => 'revenue',
|
||||
'promotion' => 'revenue',
|
||||
'invite' => 'promotion',
|
||||
'assets' => 'credits',
|
||||
// vip → vip when panel exists; SPA may still map missing keys via server resolve.
|
||||
'vip' => 'vip',
|
||||
|
||||
@@ -2,9 +2,7 @@
|
||||
/**
|
||||
* User center promotion panel (invite / 推广中心).
|
||||
*
|
||||
* Standalone dashboard tab that hosts the invite card. Reuses the existing
|
||||
* invite REST contract and credits.js `initInvite()` binding via the
|
||||
* `[data-aksrt-invite]` card in profile-invite.php.
|
||||
* Standalone dashboard tab for the forward-only promotion contract.
|
||||
*
|
||||
* @package AKSRT
|
||||
*/
|
||||
@@ -18,8 +16,12 @@ if ($user_id <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
$currency_name = (string) ($context['currency_name'] ?? __('积分', 'aksrt'));
|
||||
$settings = class_exists('\\AKSRT\\Settings\\Settings') ? \AKSRT\Settings\Settings::get_affiliate_settings() : [];
|
||||
?>
|
||||
<div class="uc-promotion-page" data-aksrt-promotion-page>
|
||||
<?php require __DIR__ . '/profile-invite.php'; ?>
|
||||
</div>
|
||||
<section class="uc-promotion-page aksrt-affiliate-panel" data-aksrt-promotion-page>
|
||||
<header class="uc-panel-heading"><h2><?php esc_html_e('推广中心', 'aksrt'); ?></h2><p><?php echo esc_html($settings['promotion_text'] ?? __('分享推广链接,好友完成会员或付费内容订单后获得佣金。', 'aksrt')); ?></p></header>
|
||||
<div class="uc-affiliate-link-card" data-affiliate-card><div><span class="muted-2-color"><?php esc_html_e('推广链接', 'aksrt'); ?></span><input type="text" readonly data-affiliate-link aria-label="<?php esc_attr_e('推广链接', 'aksrt'); ?>"></div><button type="button" class="btn-primary btn-sm" data-affiliate-copy><i class="fas fa-copy" aria-hidden="true"></i><?php esc_html_e('复制链接', 'aksrt'); ?></button><p data-affiliate-feedback role="status" aria-live="polite"></p></div>
|
||||
<div class="uc-affiliate-stats" data-affiliate-stats><article><span><?php esc_html_e('当前比例', 'aksrt'); ?></span><strong data-affiliate-ratio>—</strong></article><article><span><?php esc_html_e('推广人数', 'aksrt'); ?></span><strong data-affiliate-promoters>—</strong></article><article><span><?php esc_html_e('有效付费人数', 'aksrt'); ?></span><strong data-affiliate-payers>—</strong></article></div>
|
||||
<form class="uc-affiliate-accounts" data-affiliate-accounts><label><?php esc_html_e('支付宝收款码/账户', 'aksrt'); ?><input type="text" name="alipay" autocomplete="off"></label><label><?php esc_html_e('微信收款码/账户', 'aksrt'); ?><input type="text" name="wechat" autocomplete="off"></label><button type="submit" class="btn-secondary btn-sm"><?php esc_html_e('保存收款方式', 'aksrt'); ?></button><p data-affiliate-account-feedback role="status" aria-live="polite"></p></form>
|
||||
<p class="uc-affiliate-note"><?php esc_html_e('仅会员和付费内容订单参与返佣;首次触达后 30 天内绑定,禁止自邀和换绑。', 'aksrt'); ?></p>
|
||||
</section>
|
||||
|
||||
@@ -20,42 +20,33 @@ $affiliate = class_exists('\AKSRT\Settings\Settings')
|
||||
$withdrawal = class_exists('\AKSRT\Settings\Settings')
|
||||
? \AKSRT\Settings\Settings::get_withdrawal_settings()
|
||||
: [];
|
||||
$all_settings = class_exists('\AKSRT\Settings\Settings')
|
||||
? \AKSRT\Settings\Settings::get_all()
|
||||
: [];
|
||||
$withdraw_on = !empty($all_settings['pay_balance_withdraw_s'])
|
||||
$withdraw_on = !empty($affiliate['enabled'])
|
||||
&& class_exists('\AKSRT\Credits\Balance')
|
||||
&& \AKSRT\Credits\Balance::enabled();
|
||||
if ($withdraw_on && class_exists('\AKSRT\Settings\Capabilities') && !\AKSRT\Settings\Capabilities::user_can('balance_withdraw', $user_id)) {
|
||||
$withdraw_on = false;
|
||||
}
|
||||
$withdraw_min = max(1, (float) ($all_settings['pay_balance_withdraw_lowest_money'] ?? $all_settings['pay_rebate_withdraw_lowest_money'] ?? $withdrawal['min_amount'] ?? 50));
|
||||
$withdraw_min = max(1, (float) ($affiliate['min_withdrawal'] ?? $withdrawal['min_amount'] ?? 50));
|
||||
$wallet_fmt = class_exists('\AKSRT\Credits\Balance')
|
||||
? \AKSRT\Credits\Balance::format((float) \AKSRT\Credits\Balance::balance($user_id))
|
||||
: '0.00';
|
||||
|
||||
$commission_stats = class_exists('\AKSRT\Payment\Rebate')
|
||||
? \AKSRT\Payment\Rebate::get_instance()->get_stats($user_id)
|
||||
: ['total' => 0, 'pending' => 0, 'pending_amount' => 0, 'settled' => 0, 'total_amount' => 0, 'settled_amount' => 0];
|
||||
$commission_stats = class_exists('\AKSRT\Payment\CommissionLedger')
|
||||
? \AKSRT\Payment\CommissionLedger::get_instance()->overview($user_id)
|
||||
: ['total' => 0, 'pending' => 0, 'settled' => 0, 'wallet' => 0];
|
||||
$available_commission = class_exists('\AKSRT\Credits\Balance')
|
||||
? (float) \AKSRT\Credits\Balance::balance($user_id)
|
||||
: (float) ($commission_stats['settled_amount'] ?? 0);
|
||||
$vip_ratios = is_array($affiliate['user_ratio'] ?? null) ? $affiliate['user_ratio'] : [];
|
||||
$commission_ratio = (int) ($vip_ratios['user'] ?? $affiliate['ratio'] ?? 0);
|
||||
$current_vip = function_exists('aksrt_get_user_vip_level') ? (int) aksrt_get_user_vip_level($user_id) : 0;
|
||||
if ($current_vip >= 2 && !empty($vip_ratios['vip2'])) {
|
||||
$commission_ratio = (int) $vip_ratios['vip2'];
|
||||
} elseif ($current_vip >= 1 && !empty($vip_ratios['vip1'])) {
|
||||
$commission_ratio = (int) $vip_ratios['vip1'];
|
||||
}
|
||||
$details_text = trim((string) ($affiliate['text']['details'] ?? ''));
|
||||
: (float) ($commission_stats['settled'] ?? 0);
|
||||
$vip_ratios = [];
|
||||
$commission_ratio = (float) ($affiliate['ratio'] ?? 0);
|
||||
$details_text = trim((string) ($affiliate['earnings_text'] ?? ''));
|
||||
if ($details_text === '') {
|
||||
$details_text = trim((string) ($affiliate['note'] ?? '')) ?: __('好友通过推广链接完成符合条件的订单后,系统会按当前佣金比例记录返佣,结算后进入可提现余额。', 'aksrt');
|
||||
$details_text = __('好友通过推广链接完成符合条件的订单后,系统会按当前佣金比例记录返佣,结算后进入可提现余额。', 'aksrt');
|
||||
}
|
||||
|
||||
$revenue_request = is_array($context['revenue_request'] ?? null) ? $context['revenue_request'] : [];
|
||||
$active_reward_tab = sanitize_key((string) ($revenue_request['reward_tab'] ?? ($_GET['reward_tab'] ?? 'detail')));
|
||||
if (!in_array($active_reward_tab, ['detail', 'orders', 'users'], true)) {
|
||||
if (!in_array($active_reward_tab, ['detail', 'orders'], true)) {
|
||||
$active_reward_tab = 'detail';
|
||||
}
|
||||
$base_url = function_exists('aksrt_get_user_center_tab_url')
|
||||
@@ -69,22 +60,20 @@ $format_amount = static function ($amount): string {
|
||||
};
|
||||
|
||||
$commission_page = max(1, (int) ($revenue_request['commission_page'] ?? ($_GET['commission_page'] ?? 1)));
|
||||
$commission_view = class_exists('\AKSRT\Payment\Rebate')
|
||||
? \AKSRT\Payment\Rebate::get_instance()->get_list([
|
||||
'user_id' => $user_id,
|
||||
'limit' => 10,
|
||||
'offset' => ($commission_page - 1) * 10,
|
||||
$commission_view = class_exists('\AKSRT\Payment\CommissionLedger')
|
||||
? \AKSRT\Payment\CommissionLedger::get_instance()->list_entries($user_id, [
|
||||
'per_page' => 10,
|
||||
'page' => $commission_page,
|
||||
])
|
||||
: ['items' => [], 'total' => 0, 'max_pages' => 1, 'page' => 1];
|
||||
$commission_items = (array) ($commission_view['items'] ?? []);
|
||||
$commission_total_pages = max(1, (int) ($commission_view['max_pages'] ?? ceil(max(1, (int) ($commission_view['total'] ?? 0)) / 10)));
|
||||
if ($commission_page > $commission_total_pages) {
|
||||
$commission_page = $commission_total_pages;
|
||||
if (class_exists('\AKSRT\Payment\Rebate')) {
|
||||
$commission_view = \AKSRT\Payment\Rebate::get_instance()->get_list([
|
||||
'user_id' => $user_id,
|
||||
'limit' => 10,
|
||||
'offset' => ($commission_page - 1) * 10,
|
||||
if (class_exists('\AKSRT\Payment\CommissionLedger')) {
|
||||
$commission_view = \AKSRT\Payment\CommissionLedger::get_instance()->list_entries($user_id, [
|
||||
'per_page' => 10,
|
||||
'page' => $commission_page,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -110,7 +99,7 @@ $status_labels = [
|
||||
<div class="uc-commission-card__body">
|
||||
<span><?php esc_html_e('我的佣金', 'aksrt'); ?></span>
|
||||
<strong><?php echo esc_html($format_amount($available_commission)); ?></strong>
|
||||
<span><?php printf(esc_html__('累计佣金 %s,待结算 %s', 'aksrt'), esc_html($format_amount($commission_stats['total_amount'] ?? 0)), esc_html($format_amount($commission_stats['pending_amount'] ?? 0))); ?></span>
|
||||
<span><?php printf(esc_html__('累计佣金 %s,待结算 %s', 'aksrt'), esc_html($format_amount($commission_stats['total'] ?? 0)), esc_html($format_amount($commission_stats['pending'] ?? 0))); ?></span>
|
||||
</div>
|
||||
<?php if ($withdraw_on) : ?>
|
||||
<button type="button" class="uc-commission-card__action" data-aksrt-withdraw-open><i class="fas fa-arrow-right" aria-hidden="true"></i><?php esc_html_e('立即提现', 'aksrt'); ?></button>
|
||||
@@ -120,35 +109,15 @@ $status_labels = [
|
||||
|
||||
<section class="uc-reward-area" aria-labelledby="uc-reward-area-title">
|
||||
<div class="uc-reward-area__heading">
|
||||
<h3 id="uc-reward-area-title"><?php esc_html_e('推广奖励', 'aksrt'); ?></h3>
|
||||
<span><?php esc_html_e('邀请与返佣数据', 'aksrt'); ?></span>
|
||||
<h3 id="uc-reward-area-title"><?php esc_html_e('收益明细', 'aksrt'); ?></h3>
|
||||
<span><?php esc_html_e('佣金账本与提现状态', 'aksrt'); ?></span>
|
||||
</div>
|
||||
<nav class="uc-reward-tabs" aria-label="<?php esc_attr_e('推广奖励', 'aksrt'); ?>">
|
||||
<a <?php echo $active_reward_tab === 'detail' ? 'aria-current="page"' : ''; ?> class="<?php echo $active_reward_tab === 'detail' ? 'is-active' : ''; ?>" href="<?php echo esc_url($reward_url('detail')); ?>"><?php esc_html_e('佣金详细', 'aksrt'); ?></a>
|
||||
<nav class="uc-reward-tabs" aria-label="<?php esc_attr_e('收益明细', 'aksrt'); ?>">
|
||||
<a <?php echo $active_reward_tab === 'orders' ? 'aria-current="page"' : ''; ?> class="<?php echo $active_reward_tab === 'orders' ? 'is-active' : ''; ?>" href="<?php echo esc_url($reward_url('orders')); ?>"><?php esc_html_e('佣金明细', 'aksrt'); ?></a>
|
||||
<a <?php echo $active_reward_tab === 'users' ? 'aria-current="page"' : ''; ?> class="<?php echo $active_reward_tab === 'users' ? 'is-active' : ''; ?>" href="<?php echo esc_url($reward_url('users')); ?>"><?php esc_html_e('推荐用户', 'aksrt'); ?></a>
|
||||
</nav>
|
||||
|
||||
<?php if ($active_reward_tab === 'detail') : ?>
|
||||
<div class="uc-reward-pane uc-reward-pane--detail">
|
||||
<section class="uc-reward-block" aria-labelledby="uc-referral-link-title">
|
||||
<div class="uc-reward-block__heading"><h4 id="uc-referral-link-title"><?php esc_html_e('推广链接', 'aksrt'); ?></h4><p><?php esc_html_e('分享链接,好友注册后会自动建立邀请关系。', 'aksrt'); ?></p></div>
|
||||
<div class="uc-invite-share">
|
||||
<div class="uc-invite-code"><span><?php esc_html_e('我的邀请码', 'aksrt'); ?></span><strong data-invite-code>--</strong></div>
|
||||
<label class="screen-reader-text" for="aksrt-invite-link"><?php esc_html_e('推广链接', 'aksrt'); ?></label>
|
||||
<div class="uc-invite-link-row"><input id="aksrt-invite-link" type="text" data-invite-link readonly value=""><button type="button" class="btn-primary btn-sm" data-invite-copy disabled><i class="fas fa-copy" aria-hidden="true"></i><span><?php esc_html_e('复制链接', 'aksrt'); ?></span></button></div>
|
||||
<p class="uc-reward-status" data-invite-status role="status" aria-live="polite"><?php esc_html_e('正在加载推广数据...', 'aksrt'); ?></p>
|
||||
<p class="uc-reward-copy-feedback" data-invite-copy-feedback role="status" aria-live="polite"></p>
|
||||
</div>
|
||||
</section>
|
||||
<section class="uc-reward-block" aria-labelledby="uc-ratio-title">
|
||||
<div class="uc-reward-block__heading"><h4 id="uc-ratio-title"><?php esc_html_e('佣金比例', 'aksrt'); ?></h4><p><?php esc_html_e('当前推广身份对应的返佣规则。', 'aksrt'); ?></p></div>
|
||||
<dl class="uc-ratio-list">
|
||||
<div><dt><?php esc_html_e('普通用户', 'aksrt'); ?></dt><dd><?php echo esc_html((string) ($vip_ratios['user'] ?? $commission_ratio)); ?>%</dd></div>
|
||||
<div><dt>VIP 1</dt><dd><?php echo esc_html((string) ($vip_ratios['vip1'] ?? 0)); ?>%</dd></div>
|
||||
<div><dt>VIP 2</dt><dd><?php echo esc_html((string) ($vip_ratios['vip2'] ?? 0)); ?>%</dd></div>
|
||||
</dl>
|
||||
</section>
|
||||
<section class="uc-reward-block uc-reward-block--details" aria-labelledby="uc-details-title">
|
||||
<div class="uc-reward-block__heading"><h4 id="uc-details-title"><?php esc_html_e('返佣详解', 'aksrt'); ?></h4></div>
|
||||
<div class="uc-reward-richtext"><?php echo wp_kses_post(wpautop($details_text)); ?></div>
|
||||
@@ -164,17 +133,14 @@ $status_labels = [
|
||||
$source_user = !empty($item['source_user_id']) ? get_userdata((int) $item['source_user_id']) : null;
|
||||
$source_name = $source_user instanceof WP_User ? $source_user->display_name : __('推广用户', 'aksrt');
|
||||
?>
|
||||
<article class="uc-commission-row"><span class="uc-commission-row__icon"><i class="fas fa-receipt" aria-hidden="true"></i></span><div class="uc-commission-row__main"><strong><?php echo esc_html($source_name); ?></strong><span><?php printf(esc_html__('订单 %s', 'aksrt'), esc_html((string) ($item['order_number'] ?? '-'))); ?></span><time><?php echo esc_html((string) ($item['created_at'] ?? '')); ?></time></div><div class="uc-commission-row__value"><strong>+<?php echo esc_html($format_amount($item['amount'] ?? 0)); ?></strong><span class="is-<?php echo esc_attr($status); ?>"><?php echo esc_html($status_labels[$status] ?? $status); ?></span></div></article>
|
||||
<article class="uc-commission-row"><span class="uc-commission-row__icon"><i class="fas fa-receipt" aria-hidden="true"></i></span><div class="uc-commission-row__main"><strong><?php echo esc_html($source_name); ?></strong><span><?php printf(esc_html__('订单 %s', 'aksrt'), esc_html((string) ($item['order_number'] ?? '-'))); ?></span><time><?php echo esc_html((string) ($item['created_at'] ?? '')); ?></time></div><div class="uc-commission-row__value"><strong><?php echo esc_html($format_amount((float) ($item['original_amount'] ?? 0) + (float) ($item['adjustment_total'] ?? 0))); ?></strong><span class="is-<?php echo esc_attr($status); ?>"><?php echo esc_html($status_labels[$status] ?? $status); ?></span></div></article>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php if ($commission_total_pages > 1) : ?><nav class="uc-reward-pagination" aria-label="<?php esc_attr_e('佣金明细分页', 'aksrt'); ?>"><?php for ($i = 1; $i <= $commission_total_pages; $i++) : ?><a class="<?php echo $i === $commission_page ? 'is-active' : ''; ?>" href="<?php echo esc_url($reward_url('orders', ['commission_page' => $i])); ?>"><?php echo esc_html((string) $i); ?></a><?php endfor; ?></nav><?php endif; ?>
|
||||
<?php else : ?><p class="uc-reward-empty"><?php esc_html_e('暂无佣金订单', 'aksrt'); ?></p><?php endif; ?>
|
||||
</div>
|
||||
<?php else : ?>
|
||||
<div class="uc-reward-pane">
|
||||
<div class="uc-reward-list-heading"><div><h4><?php esc_html_e('邀请记录', 'aksrt'); ?></h4><p><?php esc_html_e('通过推广链接注册的用户会显示在这里。', 'aksrt'); ?></p></div><strong data-invite-total><?php esc_html_e('加载中...', 'aksrt'); ?></strong></div>
|
||||
<div class="uc-invite-list is-loading" data-invite-list aria-live="polite"><p class="uc-reward-empty"><?php esc_html_e('正在加载邀请记录...', 'aksrt'); ?></p></div>
|
||||
</div>
|
||||
<div class="uc-reward-pane"><p class="uc-reward-empty"><?php esc_html_e('暂无收益明细。', 'aksrt'); ?></p></div>
|
||||
<?php endif; ?>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
@@ -23,7 +23,6 @@ $withdraw_fee_rate = (int) ($withdraw_settings['service_charge_rate'] ?? 5);
|
||||
<select class="uc-card-pass__input" name="method" data-aksrt-withdraw-method>
|
||||
<option value="alipay"><?php esc_html_e('支付宝', 'aksrt'); ?></option>
|
||||
<option value="wechat"><?php esc_html_e('微信', 'aksrt'); ?></option>
|
||||
<option value="bank"><?php esc_html_e('银行卡', 'aksrt'); ?></option>
|
||||
</select>
|
||||
<label class="muted-color em09 mt10"><?php esc_html_e('收款账户信息', 'aksrt'); ?></label>
|
||||
<textarea class="uc-card-pass__input" name="account" rows="3" data-aksrt-withdraw-account placeholder="<?php esc_attr_e('姓名 + 账户 / 卡号', 'aksrt'); ?>"></textarea>
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
/** Shared forward widget contract. */
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
function aksrt_widget_common_defaults(): array {
|
||||
return class_exists('\\AKSRT\\Widgets\\CommonWidgetFields') ? \AKSRT\Widgets\CommonWidgetFields::defaults() : ['subtitle'=>'','title_link'=>'','display_pc'=>1,'display_mobile'=>1,'sticky'=>0,'animation'=>'none','background'=>'surface','dark_background'=>'surface'];
|
||||
}
|
||||
function aksrt_widget_common_normalize(array $instance): array {
|
||||
if (class_exists('\\AKSRT\\Widgets\\CommonWidgetFields')) return \AKSRT\Widgets\CommonWidgetFields::normalize($instance);
|
||||
$d = aksrt_widget_common_defaults();
|
||||
$out = $instance;
|
||||
$out['subtitle'] = sanitize_text_field((string)($instance['subtitle'] ?? $d['subtitle']));
|
||||
$out['title_link'] = esc_url_raw((string)($instance['title_link'] ?? ''));
|
||||
foreach (['display_pc','display_mobile','sticky'] as $key) $out[$key] = !empty($instance[$key]) ? 1 : 0;
|
||||
$out['animation'] = in_array(($a = sanitize_key((string)($instance['animation'] ?? 'none'))), ['none','fade','slide'], true) ? $a : 'none';
|
||||
$out['background'] = in_array(($b = sanitize_key((string)($instance['background'] ?? 'surface'))), ['surface','transparent','primary'], true) ? $b : 'surface';
|
||||
$out['dark_background'] = in_array(($db = sanitize_key((string)($instance['dark_background'] ?? 'surface'))), ['surface','transparent','primary'], true) ? $db : 'surface';
|
||||
return $out;
|
||||
}
|
||||
function aksrt_widget_common_form(WP_Widget $widget, array $instance): void {
|
||||
$v = aksrt_widget_common_normalize($instance);
|
||||
$field = static function(string $key) use ($widget): string { return esc_attr($widget->get_field_name($key)); };
|
||||
echo '<p><label for="' . esc_attr($widget->get_field_id('subtitle')) . '">' . esc_html__('副标题', 'aksrt') . '</label><input class="widefat" id="' . esc_attr($widget->get_field_id('subtitle')) . '" name="' . $field('subtitle') . '" type="text" value="' . esc_attr($v['subtitle']) . '"></p>';
|
||||
echo '<p><label for="' . esc_attr($widget->get_field_id('title_link')) . '">' . esc_html__('标题链接', 'aksrt') . '</label><input class="widefat" id="' . esc_attr($widget->get_field_id('title_link')) . '" name="' . $field('title_link') . '" type="url" value="' . esc_attr($v['title_link']) . '"></p>';
|
||||
echo '<p><label><input type="checkbox" name="' . $field('display_pc') . '" value="1" ' . checked($v['display_pc'], 1, false) . '> ' . esc_html__('桌面端显示', 'aksrt') . '</label> <label><input type="checkbox" name="' . $field('display_mobile') . '" value="1" ' . checked($v['display_mobile'], 1, false) . '> ' . esc_html__('移动端显示', 'aksrt') . '</label> <label><input type="checkbox" name="' . $field('sticky') . '" value="1" ' . checked($v['sticky'], 1, false) . '> ' . esc_html__('侧栏吸顶', 'aksrt') . '</label></p>';
|
||||
echo '<p><label>' . esc_html__('入场动画', 'aksrt') . '<select class="widefat" name="' . $field('animation') . '"><option value="none" ' . selected($v['animation'], 'none', false) . '>None</option><option value="fade" ' . selected($v['animation'], 'fade', false) . '>Fade</option><option value="slide" ' . selected($v['animation'], 'slide', false) . '>Slide</option></select></label></p>';
|
||||
}
|
||||
add_filter('widget_update_callback', static function($instance, $new_instance, $old_instance, $widget) { return is_array($instance) ? aksrt_widget_common_normalize($instance) : $instance; }, 10, 4);
|
||||
add_action('in_widget_form', static function(WP_Widget $widget, &$return, array $instance): void { aksrt_widget_common_form($widget, $instance); }, 20, 3);
|
||||
@@ -8,6 +8,7 @@
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
require_once AKSRT_DIR . '/inc/modules/widget-areas.php';
|
||||
require_once AKSRT_DIR . '/inc/modules/widget-common.php';
|
||||
|
||||
/**
|
||||
* Register custom widgets.
|
||||
@@ -68,6 +69,12 @@ function aksrt_register_widgets() {
|
||||
register_widget('\AKSRT\Widgets\WidgetMainPosts');
|
||||
register_widget('\AKSRT\Widgets\WidgetTermAggregation');
|
||||
register_widget('\AKSRT\Widgets\WidgetIconCoverCards');
|
||||
register_widget('\AKSRT\Widgets\PricingPlansWidget');
|
||||
register_widget('\AKSRT\Widgets\TestimonialsWidget');
|
||||
register_widget('\AKSRT\Widgets\FaqWidget');
|
||||
register_widget('\AKSRT\Widgets\StatsWidget');
|
||||
register_widget('\AKSRT\Widgets\HighlightsWidget');
|
||||
register_widget('\AKSRT\Widgets\PartnersWidget');
|
||||
}
|
||||
add_action('widgets_init', 'aksrt_register_widgets');
|
||||
|
||||
@@ -102,6 +109,9 @@ add_filter('block_type_metadata', function ($metadata) {
|
||||
$aksrt_widgets = [
|
||||
'aksrt_categories',
|
||||
'aksrt_tag_cloud',
|
||||
'aksrt_hot_posts','aksrt_tab_posts','aksrt_category_block','aksrt_category_tabs','aksrt_category_recommend',
|
||||
'aksrt_search','aksrt_notice','aksrt_recent_comments','aksrt_icon_cards','aksrt_buttons','aksrt_announcement','aksrt_user_card','aksrt_cover_cards','aksrt_video_player','aksrt_yiyan','aksrt_slider','aksrt_iframe','aksrt_combo_info','aksrt_text_title','aksrt_term_cards','aksrt_post_pay_box','aksrt_author_card','aksrt_oneline_posts','aksrt_main_posts','aksrt_term_aggregation','aksrt_icon_cover_cards',
|
||||
'aksrt_pricing_plans','aksrt_testimonials','aksrt_faq','aksrt_stats','aksrt_highlights','aksrt_partners',
|
||||
];
|
||||
|
||||
if (!empty($metadata['name']) && in_array($metadata['name'], $aksrt_widgets, true)) {
|
||||
@@ -123,6 +133,8 @@ add_action('in_widget_form', function (WP_Widget $widget): void {
|
||||
'aksrt_category_block' => 'hybrid',
|
||||
'aksrt_category_tabs' => 'hybrid',
|
||||
'aksrt_category_recommend' => 'homepage',
|
||||
'aksrt_search'=>'sidebar','aksrt_notice'=>'sidebar','aksrt_recent_comments'=>'sidebar','aksrt_icon_cards'=>'hybrid','aksrt_buttons'=>'hybrid','aksrt_announcement'=>'homepage','aksrt_user_card'=>'sidebar','aksrt_cover_cards'=>'homepage','aksrt_video_player'=>'content','aksrt_yiyan'=>'sidebar','aksrt_slider'=>'homepage','aksrt_iframe'=>'content','aksrt_combo_info'=>'homepage','aksrt_text_title'=>'hybrid','aksrt_term_cards'=>'homepage','aksrt_post_pay_box'=>'content','aksrt_author_card'=>'content','aksrt_oneline_posts'=>'sidebar','aksrt_main_posts'=>'homepage','aksrt_term_aggregation'=>'homepage','aksrt_icon_cover_cards'=>'homepage',
|
||||
'aksrt_pricing_plans'=>'homepage','aksrt_testimonials'=>'homepage','aksrt_faq'=>'content','aksrt_stats'=>'homepage','aksrt_highlights'=>'homepage','aksrt_partners'=>'homepage',
|
||||
];
|
||||
|
||||
$scope = $map[$widget->id_base] ?? '';
|
||||
|
||||
Reference in New Issue
Block a user