feat(users): normalize center routes and withdrawal limits
This commit is contained in:
@@ -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