feat(users): normalize center routes and withdrawal limits
This commit is contained in:
@@ -106,13 +106,7 @@ if (!function_exists('aksrt_get_user_center_tab_url')) {
|
||||
if ('invite' === $tab || 'promotion' === $tab) {
|
||||
$tab = 'revenue';
|
||||
}
|
||||
$url = remove_query_arg([
|
||||
'tab', 'posts_page', 'comments_page', 'favorites_page', 'credits_page',
|
||||
'post_status', 'creator_page', 'creator_status', 'saved', 'profile_error',
|
||||
'order_tab', 'otab', 'order_status', 'order_page', 'order_type', 'income_currency', 'income_status', 'income_page', 'section',
|
||||
], aksrt_get_user_center_url());
|
||||
|
||||
return add_query_arg('tab', $tab, $url);
|
||||
return aksrt_get_user_center_url($tab);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -282,7 +276,10 @@ if (!function_exists('aksrt_user_center_resolve_tabs')) {
|
||||
$default = in_array('vip', $keys, true)
|
||||
? 'vip'
|
||||
: (in_array('profile', $keys, true) ? 'profile' : ($keys[0] ?? 'profile'));
|
||||
$active = isset($_GET['tab']) ? sanitize_key(wp_unslash($_GET['tab'])) : $default;
|
||||
$active = (string) get_query_var('aksrt_user_center_tab') ?: $default;
|
||||
if ($active === 'balance') {
|
||||
$active = 'credits';
|
||||
}
|
||||
if ('signin' === $active || 'assets' === $active) {
|
||||
$active = 'credits';
|
||||
} elseif ('invite' === $active || 'promotion' === $active) {
|
||||
|
||||
@@ -32,13 +32,16 @@ $withdraw_on = !empty($all_settings['pay_balance_withdraw_s']);
|
||||
if ($withdraw_on && class_exists('\AKSRT\Settings\Capabilities') && !\AKSRT\Settings\Capabilities::user_can('balance_withdraw', $uid)) {
|
||||
$withdraw_on = false;
|
||||
}
|
||||
$withdraw_min = max(1, (float) ($all_settings['pay_balance_withdraw_lowest_money'] ?? $all_settings['pay_rebate_withdraw_lowest_money'] ?? 50));
|
||||
$withdraw_settings = class_exists('\\AKSRT\\Settings\\Settings') ? \AKSRT\Settings\Settings::get_withdrawal_settings() : [];
|
||||
$withdraw_min = max(0, (float) ($withdraw_settings['min_amount'] ?? 50));
|
||||
$withdraw_usage = ['remaining_count' => 0, 'remaining_amount' => 0];
|
||||
$withdraw_pending_hold = 0.0;
|
||||
$withdraw_history = [];
|
||||
if ($withdraw_on && class_exists('\AKSRT\Payment\Withdrawal')) {
|
||||
$wd_svc = \AKSRT\Payment\Withdrawal::get_instance();
|
||||
$withdraw_pending_hold = $wd_svc->sum_pending_hold((int) ($user_id ?? 0));
|
||||
$withdraw_history = $wd_svc->get_user_withdrawals((int) ($user_id ?? 0), ['limit' => 30]);
|
||||
$withdraw_usage = $wd_svc->daily_usage((int) ($user_id ?? 0), $withdraw_settings);
|
||||
}
|
||||
$withdraw_processing = $withdraw_pending_hold > 0;
|
||||
$card_pass_balance = ['enabled' => false, 'desc' => '', 'only_password' => true];
|
||||
@@ -66,7 +69,7 @@ $mark = (string) ($charge_view['currency_mark'] ?? '元');
|
||||
</div>
|
||||
<?php if ($withdraw_on) : ?>
|
||||
<button type="button" class="uc-asset-card__head-action muted-color px12" data-aksrt-withdraw-history-open>
|
||||
<?php echo $withdraw_processing ? esc_html__('提现处理中', 'aksrt') : esc_html__('提现记录', 'aksrt'); ?>
|
||||
<?php esc_html_e('提现记录', 'aksrt'); ?>
|
||||
<i class="fa fa-angle-right em12 ml3" aria-hidden="true"></i>
|
||||
</button>
|
||||
<?php endif; ?>
|
||||
@@ -81,11 +84,7 @@ $mark = (string) ($charge_view['currency_mark'] ?? '元');
|
||||
<button type="button" class="but c-blue-2 mr6 hollow" data-aksrt-transfer-open="balance"><?php esc_html_e('转账', 'aksrt'); ?></button>
|
||||
<?php endif; ?>
|
||||
<?php if ($withdraw_on) : ?>
|
||||
<?php if ($withdraw_processing) : ?>
|
||||
<button type="button" class="but c-blue-2 mr6 hollow" data-aksrt-withdraw-history-open><?php esc_html_e('提现处理中', 'aksrt'); ?></button>
|
||||
<?php else : ?>
|
||||
<button type="button" class="but c-blue-2 mr6 hollow" data-aksrt-withdraw-open><?php esc_html_e('提现', 'aksrt'); ?></button>
|
||||
<?php endif; ?>
|
||||
<button type="button" class="but c-blue-2 mr6 hollow" data-aksrt-withdraw-open><?php esc_html_e('提现', 'aksrt'); ?></button>
|
||||
<?php endif; ?>
|
||||
<button type="button" class="but b-blue-2" data-aksrt-charge-open><?php esc_html_e('充值', 'aksrt'); ?></button>
|
||||
</div>
|
||||
@@ -100,9 +99,8 @@ $mark = (string) ($charge_view['currency_mark'] ?? '元');
|
||||
</button>
|
||||
<?php endif; ?>
|
||||
<?php if ($withdraw_on) : ?>
|
||||
<div class="uc-asset-card__foot muted-2-color em09 flex jsb ac mt6">
|
||||
<div class="uc-asset-card__foot muted-2-color em09 mt6">
|
||||
<span><?php printf(esc_html__('处理中冻结 %s', 'aksrt'), esc_html(class_exists('\AKSRT\Credits\Balance') ? \AKSRT\Credits\Balance::format((float) $withdraw_pending_hold) : number_format_i18n((float) $withdraw_pending_hold, 2))); ?></span>
|
||||
<button type="button" class="muted-color" data-aksrt-withdraw-history-open><?php esc_html_e('提现记录', 'aksrt'); ?></button>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
@@ -1,19 +1,14 @@
|
||||
<?php
|
||||
/**
|
||||
* Shared balance withdrawal modal.
|
||||
*
|
||||
* @package AKSRT
|
||||
*/
|
||||
|
||||
/** Shared balance withdrawal modal. @package AKSRT */
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
if (!empty($GLOBALS['aksrt_withdraw_modal_rendered'])) {
|
||||
return;
|
||||
}
|
||||
$GLOBALS['aksrt_withdraw_modal_rendered'] = true;
|
||||
|
||||
$withdraw_min = max(1, (float) ($withdraw_min ?? 50));
|
||||
$wallet_fmt = (string) ($wallet_fmt ?? '0.00');
|
||||
$withdraw_min = max(0, (float) ($withdraw_min ?? 50));
|
||||
$withdraw_usage = is_array($withdraw_usage ?? null) ? $withdraw_usage : ['remaining_count' => 0, 'remaining_amount' => 0];
|
||||
$withdraw_fee_rate = (int) ($withdraw_settings['service_charge_rate'] ?? 5);
|
||||
?>
|
||||
<div class="uc-modal" id="aksrt-withdraw-modal" hidden data-aksrt-withdraw-modal>
|
||||
<div class="uc-modal__overlay" data-aksrt-withdraw-close></div>
|
||||
@@ -22,16 +17,16 @@ $wallet_fmt = (string) ($wallet_fmt ?? '0.00');
|
||||
<h3 class="uc-modal__title"><?php esc_html_e('余额提现', 'aksrt'); ?></h3>
|
||||
<form data-aksrt-withdraw-form>
|
||||
<label class="muted-color em09"><?php esc_html_e('提现金额', 'aksrt'); ?></label>
|
||||
<input type="number" class="uc-card-pass__input" name="amount" min="<?php echo esc_attr((string) $withdraw_min); ?>" step="0.01" data-aksrt-withdraw-amount>
|
||||
<p class="muted-2-color em09 mt6"><?php printf(esc_html__('最低提现 %s 元,当前余额 %s', 'aksrt'), esc_html((string) $withdraw_min), esc_html($wallet_fmt)); ?></p>
|
||||
<input type="number" class="uc-card-pass__input" name="amount" min="<?php echo esc_attr((string) $withdraw_min); ?>" max="<?php echo esc_attr((string) ($withdraw_usage['remaining_amount'] ?? 0)); ?>" step="1" inputmode="numeric" data-aksrt-withdraw-amount data-withdraw-min="<?php echo esc_attr((string) $withdraw_min); ?>" data-withdraw-remaining-amount="<?php echo esc_attr((string) ($withdraw_usage['remaining_amount'] ?? 0)); ?>" data-withdraw-remaining-count="<?php echo esc_attr((string) ($withdraw_usage['remaining_count'] ?? 0)); ?>">
|
||||
<p class="muted-2-color em09 mt6"><?php printf(esc_html__('最低提现%s 元,今日可提现%d次,提现手续费率%d%%', 'aksrt'), esc_html((string) $withdraw_min), (int) ($withdraw_usage['remaining_count'] ?? 0), $withdraw_fee_rate); ?></p>
|
||||
<label class="muted-color em09 mt10"><?php esc_html_e('收款方式', 'aksrt'); ?></label>
|
||||
<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>
|
||||
<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>
|
||||
<p class="uc-modal__tip" data-aksrt-withdraw-tip></p>
|
||||
<button type="submit" class="but jb-blue btn-block" data-aksrt-withdraw-submit><?php esc_html_e('提交申请', 'aksrt'); ?></button>
|
||||
</form>
|
||||
|
||||
@@ -14,7 +14,8 @@ defined('ABSPATH') || exit;
|
||||
// --- 3a. /user/{昵称} 自定义重写 ---
|
||||
add_filter('query_vars', function ($vars) {
|
||||
$vars[] = 'aksrt_user_center';
|
||||
$vars[] = 'user_nicename';
|
||||
$vars[] = 'aksrt_user_center_tab';
|
||||
$vars[] = 'aksrt_author_identifier';
|
||||
$vars[] = 'aksrt_orders';
|
||||
$vars[] = 'aksrt_revenue';
|
||||
return $vars;
|
||||
@@ -24,6 +25,14 @@ add_action('template_redirect', function () {
|
||||
if (is_admin() || wp_doing_ajax() || is_feed() || is_embed() || is_preview()) {
|
||||
return;
|
||||
}
|
||||
$request_path = trim((string) parse_url($_SERVER['REQUEST_URI'] ?? '', PHP_URL_PATH), '/');
|
||||
if ($request_path === 'profile' || str_starts_with($request_path, 'profile/')) {
|
||||
global $wp_query;
|
||||
if ($wp_query instanceof WP_Query) { $wp_query->set_404(); }
|
||||
status_header(404);
|
||||
nocache_headers();
|
||||
return;
|
||||
}
|
||||
|
||||
$resolved_path = aksrt_get_current_special_template_path();
|
||||
if ($resolved_path === '') {
|
||||
@@ -35,13 +44,36 @@ add_action('template_redirect', function () {
|
||||
exit;
|
||||
}, 100);
|
||||
|
||||
// /user/{tab} only accepts registered user-center tabs; former public /user/{slug}
|
||||
// addresses must not silently resolve to the user-center home.
|
||||
add_action('template_redirect', function () {
|
||||
if (is_admin() || wp_doing_ajax()) {
|
||||
return;
|
||||
}
|
||||
$tab = (string) get_query_var('aksrt_user_center_tab');
|
||||
if ($tab === '') {
|
||||
return;
|
||||
}
|
||||
$tab = $tab === 'balance' ? 'credits' : sanitize_key($tab);
|
||||
$allowed = class_exists('\\AKSRT\\User\\Center')
|
||||
? array_keys(\AKSRT\User\Center::get_instance()->get_dashboard_tabs())
|
||||
: ['profile', 'level', 'creator', 'comments', 'favorites', 'credits', 'vip', 'orders', 'auth', 'revenue', 'settings'];
|
||||
if (!in_array($tab, $allowed, true)) {
|
||||
global $wp_query;
|
||||
if ($wp_query instanceof WP_Query) { $wp_query->set_404(); }
|
||||
status_header(404);
|
||||
nocache_headers();
|
||||
}
|
||||
}, 1);
|
||||
|
||||
add_action('init', function () {
|
||||
add_rewrite_tag('%aksrt_user_center%', '([^&]+)');
|
||||
add_rewrite_tag('%user_nicename%', '([^/]+)');
|
||||
add_rewrite_tag('%aksrt_user_center_tab%', '([^/]+)');
|
||||
add_rewrite_tag('%aksrt_author_identifier%', '([^/]+)');
|
||||
add_rewrite_tag('%aksrt_orders%', '([0-1])');
|
||||
add_rewrite_tag('%aksrt_revenue%', '([0-1])');
|
||||
add_rewrite_rule('^profile/?$', 'index.php?aksrt_user_center=1', 'top');
|
||||
add_rewrite_rule('^user/([^/]+)/?$', 'index.php?user_nicename=$matches[1]', 'top');
|
||||
add_rewrite_rule('^user/([a-z0-9_-]+)/?$', 'index.php?aksrt_user_center=1&aksrt_user_center_tab=$matches[1]', 'top');
|
||||
add_rewrite_rule('^author/([^/]+)/?$', 'index.php?aksrt_author_identifier=$matches[1]', 'top');
|
||||
// Commerce center aliases (work even before WP page is assigned).
|
||||
add_rewrite_rule('^orders/?$', 'index.php?aksrt_orders=1', 'top');
|
||||
add_rewrite_rule('^revenue/?$', 'index.php?aksrt_revenue=1', 'top');
|
||||
@@ -56,9 +88,9 @@ add_filter('template_include', function ($template) {
|
||||
}
|
||||
|
||||
// A) /user/{昵称} even if special-path helper returned empty (user missing → 404).
|
||||
$nicename = (string) get_query_var('user_nicename');
|
||||
if ($nicename !== '') {
|
||||
$user = get_user_by('slug', $nicename);
|
||||
$identifier = (string) get_query_var('aksrt_author_identifier');
|
||||
if ($identifier !== '') {
|
||||
$user = function_exists('aksrt_resolve_public_user') ? aksrt_resolve_public_user($identifier) : null;
|
||||
if ($user instanceof WP_User) {
|
||||
$tpl = aksrt_locate_template_file('templates/pages/page-user-home.php');
|
||||
if ($tpl) {
|
||||
@@ -78,18 +110,12 @@ add_filter('template_include', function ($template) {
|
||||
return $four ?: $template;
|
||||
}
|
||||
|
||||
// B) profile slug page without rewrite var (permalink edge).
|
||||
// B) ordinary assigned page templates.
|
||||
if (is_page()) {
|
||||
$page_id = get_queried_object_id();
|
||||
if ($page_id) {
|
||||
$slug = (string) get_post_field('post_name', $page_id);
|
||||
$page_template = get_post_meta($page_id, '_wp_page_template', true);
|
||||
if ($slug === 'profile' || $page_template === 'templates/pages/page-profile.php') {
|
||||
$tpl = aksrt_locate_template_file('templates/pages/page-profile.php');
|
||||
if ($tpl) {
|
||||
return $tpl;
|
||||
}
|
||||
}
|
||||
if (is_string($page_template) && strpos($page_template, 'templates/pages/') === 0) {
|
||||
$tpl = aksrt_locate_template_file($page_template);
|
||||
if ($tpl) {
|
||||
@@ -157,13 +183,8 @@ add_action('init', function () {
|
||||
aksrt_ensure_template_page($requested_template_key);
|
||||
}
|
||||
|
||||
// Always re-assert profile page template (blank WP page with slug profile is common).
|
||||
if (function_exists('aksrt_ensure_template_page')) {
|
||||
aksrt_ensure_template_page('profile');
|
||||
}
|
||||
|
||||
// 统一 flush 检查 — bump when user-home rewrite / author override changes
|
||||
$rewrite_version = AKSRT_VERSION . ':user-home-profile-routing-v5';
|
||||
$rewrite_version = AKSRT_VERSION . ':user-center-author-routing-v6';
|
||||
$flushed = get_option('aksrt_user_rules_flushed');
|
||||
$rules = get_option('rewrite_rules');
|
||||
$need_flush = ($flushed !== $rewrite_version)
|
||||
@@ -199,15 +220,15 @@ add_filter('author_link', function ($link, $author_id) {
|
||||
$user = get_userdata($author_id);
|
||||
$slug = $user ? $user->user_nicename : ('user-' . max(0, $author_id));
|
||||
if (!get_option('permalink_structure')) {
|
||||
return add_query_arg('user_nicename', rawurlencode($slug), home_url('/'));
|
||||
return add_query_arg('aksrt_author', rawurlencode($slug), home_url('/'));
|
||||
}
|
||||
return home_url('/user/' . trailingslashit($slug));
|
||||
return home_url('/author/' . trailingslashit($slug));
|
||||
}, 99, 2);
|
||||
|
||||
// Accept ?user_nicename= when pretty rewrites are unavailable.
|
||||
add_filter('request', function ($query_vars) {
|
||||
if (empty($query_vars['user_nicename']) && !empty($_GET['user_nicename'])) {
|
||||
$query_vars['user_nicename'] = sanitize_title(wp_unslash((string) $_GET['user_nicename']));
|
||||
if (empty($query_vars['aksrt_author_identifier']) && !empty($_GET['aksrt_author'])) {
|
||||
$query_vars['aksrt_author_identifier'] = sanitize_text_field(wp_unslash((string) $_GET['aksrt_author']));
|
||||
}
|
||||
if (empty($query_vars['aksrt_user_center']) && isset($_GET['aksrt_user_center'])) {
|
||||
$query_vars['aksrt_user_center'] = '1';
|
||||
@@ -248,7 +269,7 @@ add_action('template_redirect', function () {
|
||||
if (empty($_GET['author'])) {
|
||||
return;
|
||||
}
|
||||
if (get_query_var('user_nicename') || get_query_var('aksrt_user_center')) {
|
||||
if (get_query_var('aksrt_author_identifier') || get_query_var('aksrt_user_center')) {
|
||||
return;
|
||||
}
|
||||
if (is_author()) {
|
||||
|
||||
@@ -369,12 +369,12 @@ function aksrt_clear_template_page_cache(): void {
|
||||
function aksrt_get_user_home_template_path(): string {
|
||||
global $_aksrt_special_templates, $aksrt_profile_user;
|
||||
|
||||
$nicename = (string) get_query_var('user_nicename');
|
||||
if ($nicename === '') {
|
||||
$identifier = (string) get_query_var('aksrt_author_identifier');
|
||||
if ($identifier === '') {
|
||||
return '';
|
||||
}
|
||||
|
||||
$user = get_user_by('slug', $nicename);
|
||||
$user = function_exists('aksrt_resolve_public_user') ? aksrt_resolve_public_user($identifier) : null;
|
||||
if (!$user instanceof WP_User) {
|
||||
return '';
|
||||
}
|
||||
@@ -393,7 +393,7 @@ function aksrt_get_user_home_template_path(): string {
|
||||
* Resolve the active special-page template path for the current request.
|
||||
*/
|
||||
function aksrt_get_current_special_template_path(): string {
|
||||
if (get_query_var('user_nicename')) {
|
||||
if (get_query_var('aksrt_author_identifier')) {
|
||||
return aksrt_get_user_home_template_path();
|
||||
}
|
||||
|
||||
|
||||
@@ -19,28 +19,13 @@ if (!function_exists('aksrt_get_user_center_url')) :
|
||||
* @return string
|
||||
*/
|
||||
function aksrt_get_user_center_url(string $tab = ''): string {
|
||||
if (get_option('permalink_structure')) {
|
||||
$url = home_url('/profile/');
|
||||
} else {
|
||||
$url = add_query_arg('aksrt_user_center', '1', home_url('/'));
|
||||
}
|
||||
|
||||
if ($tab !== '') {
|
||||
$tab = sanitize_key($tab);
|
||||
// Deep-link aliases used by header wallet / VIP CTA.
|
||||
$aliases = [
|
||||
'assets' => 'credits',
|
||||
'vip' => 'vip', // dedicated vip tab when registered; resolver falls back if missing
|
||||
'signin' => 'credits',
|
||||
'invite' => 'revenue',
|
||||
'promotion' => 'revenue',
|
||||
];
|
||||
if (isset($aliases[$tab])) {
|
||||
$tab = $aliases[$tab];
|
||||
}
|
||||
$url = add_query_arg('tab', $tab, $url);
|
||||
}
|
||||
return $url;
|
||||
$tab = sanitize_key($tab ?: 'profile');
|
||||
$aliases = ['assets' => 'credits', 'signin' => 'credits', 'invite' => 'revenue', 'promotion' => 'revenue'];
|
||||
$tab = $aliases[$tab] ?? $tab;
|
||||
$path_tab = $tab === 'credits' ? 'balance' : $tab;
|
||||
return get_option('permalink_structure')
|
||||
? home_url('/user/' . trailingslashit($path_tab))
|
||||
: add_query_arg(['aksrt_user_center' => '1', 'aksrt_user_center_tab' => $tab], home_url('/'));
|
||||
}
|
||||
endif;
|
||||
|
||||
@@ -81,7 +66,7 @@ function aksrt_get_orders_page_url(): string {
|
||||
if (function_exists('aksrt_get_user_center_url')) {
|
||||
return aksrt_get_user_center_url('orders');
|
||||
}
|
||||
return home_url('/profile/?tab=orders');
|
||||
return home_url('/user/orders/');
|
||||
}
|
||||
endif;
|
||||
|
||||
@@ -96,7 +81,7 @@ function aksrt_get_revenue_page_url(): string {
|
||||
if (function_exists('aksrt_get_user_center_url')) {
|
||||
return aksrt_get_user_center_url('revenue');
|
||||
}
|
||||
return home_url('/profile/?tab=revenue');
|
||||
return home_url('/user/revenue/');
|
||||
}
|
||||
endif;
|
||||
|
||||
@@ -122,29 +107,37 @@ if (!function_exists('aksrt_get_user_home_url')) :
|
||||
* @return string
|
||||
*/
|
||||
function aksrt_get_user_home_url($user = null): string {
|
||||
$slug = '';
|
||||
$target = null;
|
||||
$mode = class_exists('\\AKSRT\\Settings\\Settings') ? (string) (\AKSRT\Settings\Settings::get_user_home_settings()['route_identifier'] ?? 'nicename') : 'nicename';
|
||||
if ($user instanceof WP_User) {
|
||||
$slug = $user->user_nicename;
|
||||
$target = $user;
|
||||
} elseif (is_int($user) && $user > 0) {
|
||||
$u = get_userdata($user);
|
||||
$slug = $u ? $u->user_nicename : '';
|
||||
$target = get_userdata($user);
|
||||
} elseif (is_numeric($user) && (int) $user > 0) {
|
||||
$u = get_userdata((int) $user);
|
||||
$slug = $u ? $u->user_nicename : '';
|
||||
$target = get_userdata((int) $user);
|
||||
} elseif (is_string($user) && $user) {
|
||||
$slug = $user;
|
||||
$target = get_user_by('slug', $user);
|
||||
} else {
|
||||
$current = wp_get_current_user();
|
||||
$slug = $current->ID ? $current->user_nicename : '';
|
||||
$target = wp_get_current_user();
|
||||
}
|
||||
if (!$slug) {
|
||||
if (!$target instanceof WP_User || !$target->ID) {
|
||||
return home_url('/');
|
||||
}
|
||||
// Plain permalinks: Apache 404s pretty /user/{slug}/ before WP boots.
|
||||
$identifier = $mode === 'uid' ? (string) $target->ID : $target->user_nicename;
|
||||
if (!get_option('permalink_structure')) {
|
||||
return add_query_arg('user_nicename', rawurlencode($slug), home_url('/'));
|
||||
return add_query_arg('aksrt_author', rawurlencode($identifier), home_url('/'));
|
||||
}
|
||||
return home_url('/user/' . trailingslashit($slug));
|
||||
return home_url('/author/' . trailingslashit($identifier));
|
||||
}
|
||||
endif;
|
||||
|
||||
if (!function_exists('aksrt_resolve_public_user')) :
|
||||
function aksrt_resolve_public_user(string $identifier): ?WP_User {
|
||||
$mode = class_exists('\\AKSRT\\Settings\\Settings') ? (string) (\AKSRT\Settings\Settings::get_user_home_settings()['route_identifier'] ?? 'nicename') : 'nicename';
|
||||
if ($mode === 'uid') {
|
||||
return ctype_digit($identifier) && (int) $identifier > 0 ? get_userdata((int) $identifier) ?: null : null;
|
||||
}
|
||||
return get_user_by('slug', sanitize_title($identifier)) ?: null;
|
||||
}
|
||||
endif;
|
||||
|
||||
@@ -154,7 +147,7 @@ if (!function_exists('aksrt_is_user_center_page')) :
|
||||
*/
|
||||
function aksrt_is_user_center_page(): bool {
|
||||
return (bool) get_query_var('aksrt_user_center')
|
||||
|| (is_page_template('templates/pages/page-profile.php') && !(bool) get_query_var('user_nicename'));
|
||||
|| (is_page_template('templates/pages/page-profile.php') && !(bool) get_query_var('aksrt_author_identifier'));
|
||||
}
|
||||
endif;
|
||||
|
||||
@@ -163,7 +156,7 @@ if (!function_exists('aksrt_is_user_home_page')) :
|
||||
* 判断当前是否为公开用户主页
|
||||
*/
|
||||
function aksrt_is_user_home_page(): bool {
|
||||
return (bool) get_query_var('user_nicename')
|
||||
return (bool) get_query_var('aksrt_author_identifier')
|
||||
|| is_page_template('templates/pages/page-user-home.php');
|
||||
}
|
||||
endif;
|
||||
|
||||
Reference in New Issue
Block a user