Files
wordpress-theme-aksrt/inc/modules/user-parts/urls.php
T
kate522 51274fd00a feat(user-center): promote invite into standalone 推广中心 tab
Register a dedicated `promotion` dashboard panel gated by the existing
invite switches (credits + invite reward + invite registration), and move
the invite card out of the revenue tab so 收益中心 is pure earnings/withdrawal.

- src/User/Center.php: register promotion panel; revenue no longer depends
  on invite being on
- inc/helpers/user-center-renderers/profile-promotion.php: new panel body
  hosting the existing [data-aksrt-invite] card
- profile-revenue.php: drop the invite section; aksrt-user-center.php: drop
  unused show_invite_section context, add promotion to built-in tabs + view map
- repoint invite/promotion deep-link aliases from revenue to promotion across
  tab-url builder, tab resolver, runtime tabAliases, urls.php, and the
  revenue-JS enqueue gate
- sidebar-nav.php: add 推广中心 service entry; shell.css: entry icon color;
  sidebar-creator.php: reword revenue card
- UserRuntime.php: allow promotion in configurable tabs
2026-08-05 16:45:47 +08:00

329 lines
9.9 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
/**
* User public URL/page API
*
* @package AKSRT
*/
defined('ABSPATH') || exit;
// ============================================================
// 五、公开 API 函数(兼容旧代码调用)
// ============================================================
if (!function_exists('aksrt_get_user_center_url')) :
/**
* 获取本人中心 URL(私有空间入口)
*
* @param string $tab 可选 tab 参数
* @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' => 'promotion',
'promotion' => 'promotion',
];
if (isset($aliases[$tab])) {
$tab = $aliases[$tab];
}
$url = add_query_arg('tab', $tab, $url);
}
return $url;
}
endif;
if (!function_exists('aksrt_get_new_post_url')) :
/**
* 前台写文章/投稿页 URL(模板 templates/pages/page-submit.php)。
*
* @param int $edit_id 编辑中的文章 ID;0 表示新建。
* @return string 未指派页面时返回空串。
*/
function aksrt_get_new_post_url(int $edit_id = 0): string {
if (class_exists('\AKSRT\Settings\Settings')) {
$submit = \AKSRT\Settings\Settings::get_submit_settings();
if (isset($submit['enabled']) && empty($submit['enabled'])) {
return '';
}
}
$url = function_exists('aksrt_get_template_url')
? aksrt_get_template_url('submit')
: home_url('/submit/');
if ($edit_id > 0) {
$url = add_query_arg('edit', $edit_id, $url);
}
return $url;
}
endif;
if (!function_exists('aksrt_get_orders_page_url')) :
/**
* 订单中心 URL — 嵌在用户中心 tab=orders(zibll 同构)。
* 旧 /orders/ 页面模板会 302 到此地址。
*/
function aksrt_get_orders_page_url(): string {
if (function_exists('aksrt_get_user_center_tab_url')) {
return aksrt_get_user_center_tab_url('orders');
}
if (function_exists('aksrt_get_user_center_url')) {
return aksrt_get_user_center_url('orders');
}
return home_url('/profile/?tab=orders');
}
endif;
if (!function_exists('aksrt_get_revenue_page_url')) :
/**
* 收益中心 URL — 嵌在用户中心 tab=revenue。
*/
function aksrt_get_revenue_page_url(): string {
if (function_exists('aksrt_get_user_center_tab_url')) {
return aksrt_get_user_center_tab_url('revenue');
}
if (function_exists('aksrt_get_user_center_url')) {
return aksrt_get_user_center_url('revenue');
}
return home_url('/profile/?tab=revenue');
}
endif;
if (!function_exists('aksrt_get_messages_page_url')) :
/**
* 消息中心页面 URL(模板 templates/pages/page-messages.php)。
*/
function aksrt_get_messages_page_url(): string {
if (class_exists('\AKSRT\Settings\Settings') && !\AKSRT\Settings\Settings::message_enabled()) {
return '';
}
return function_exists('aksrt_get_template_url')
? aksrt_get_template_url('messages')
: home_url('/messages/');
}
endif;
if (!function_exists('aksrt_get_user_home_url')) :
/**
* 获取公开用户主页 URL(/user/{nicename}/)
*
* @param WP_User|int|string|null $user 用户对象、ID、nicename 或 null(当前用户)
* @return string
*/
function aksrt_get_user_home_url($user = null): string {
$slug = '';
if ($user instanceof WP_User) {
$slug = $user->user_nicename;
} elseif (is_int($user) && $user > 0) {
$u = get_userdata($user);
$slug = $u ? $u->user_nicename : '';
} elseif (is_numeric($user) && (int) $user > 0) {
$u = get_userdata((int) $user);
$slug = $u ? $u->user_nicename : '';
} elseif (is_string($user) && $user) {
$slug = $user;
} else {
$current = wp_get_current_user();
$slug = $current->ID ? $current->user_nicename : '';
}
if (!$slug) {
return home_url('/');
}
// Plain permalinks: Apache 404s pretty /user/{slug}/ before WP boots.
if (!get_option('permalink_structure')) {
return add_query_arg('user_nicename', rawurlencode($slug), home_url('/'));
}
return home_url('/user/' . trailingslashit($slug));
}
endif;
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'));
}
endif;
if (!function_exists('aksrt_is_user_home_page')) :
/**
* 判断当前是否为公开用户主页
*/
function aksrt_is_user_home_page(): bool {
return (bool) get_query_var('user_nicename')
|| is_page_template('templates/pages/page-user-home.php');
}
endif;
if (!function_exists('aksrt_get_profile_url')) :
/**
* 兼容层:获取用户主页 URL
*
* @deprecated 使用 aksrt_get_user_center_url() 或 aksrt_get_user_home_url() 替代
* @param WP_User|int|string|null $user
* @return string
*/
function aksrt_get_profile_url($user = null): string {
// 无参调用 → 当前用户主页(公开页)
if ($user === null) {
return aksrt_get_user_home_url();
}
return aksrt_get_user_home_url($user);
}
endif;
if (!function_exists('aksrt_get_sign_page_url')) :
/**
* Get the unified auth page URL, with legacy route fallback while the page self-heals.
*
* @param string $tab
* @param array<string, scalar> $args
*/
function aksrt_get_sign_page_url(string $tab = 'login', array $args = []): string {
$tab = aksrt_normalize_auth_tab($tab);
$legacy_fallbacks = [
'login' => home_url('/login/'),
'register' => home_url('/register/'),
'bind' => home_url('/bind-account/'),
'reset-password' => home_url('/reset-password/'),
'verify-email' => home_url('/verify-email/'),
];
$page = aksrt_find_template_page('templates/pages/page-sign.php');
if (!$page) {
aksrt_ensure_template_page('sign');
$page = aksrt_find_template_page('templates/pages/page-sign.php');
}
if ($page instanceof WP_Post) {
$url = get_permalink($page->ID);
$args = ['tab' => $tab] + $args;
return add_query_arg($args, $url);
}
$url = $legacy_fallbacks[$tab] ?? home_url('/login/');
return !empty($args) ? add_query_arg($args, $url) : $url;
}
/**
* Determine whether the current request is served by the unified auth experience.
*/
function aksrt_is_auth_page_request(): bool {
return (bool) get_query_var('aksrt_sign')
|| is_page_template('templates/pages/page-sign.php')
|| is_page_template('templates/pages/page-login.php')
|| is_page_template('templates/pages/page-register.php')
|| is_page_template('templates/pages/page-bind-account.php')
|| is_page_template('templates/pages/page-reset-password.php')
|| is_page_template('templates/pages/page-verify-email.php');
}
endif;
if (!function_exists('aksrt_get_login_url')) :
/** 获取登录页 URL */
function aksrt_get_login_url($redirect = '') {
$url = aksrt_get_sign_page_url('login');
if ($redirect) {
$url = add_query_arg('redirect_to', urlencode($redirect), $url);
}
return $url;
}
endif;
if (!function_exists('aksrt_get_register_url')) :
/** 获取注册页 URL */
function aksrt_get_register_url() {
return aksrt_get_sign_page_url('register');
}
endif;
if (!function_exists('aksrt_get_bind_url')) :
/** 获取绑定账号页面 URL */
function aksrt_get_bind_url($transient_key = '') {
$url = aksrt_get_template_url('bind');
if ($transient_key) {
$url = add_query_arg('obk', $transient_key, $url);
}
return $url;
}
endif;
if (!function_exists('aksrt_get_logout_url')) :
/**
* 获取退出登录 URL。
*
* Prefer query-arg form so logout works even when /logout/ rewrite is missing
* (Apache would 404 the pretty path before WordPress runs). Pretty /logout/
* remains registered as a convenience alias.
*
* @param string $redirect Redirect after logout.
*/
function aksrt_get_logout_url($redirect = '') {
$target = is_string($redirect) && $redirect !== '' ? $redirect : home_url('/');
// home_url('/?aksrt_logout=1') always hits index.php without rewrite rules.
$url = add_query_arg(
[
'aksrt_logout' => '1',
'redirect_to' => $target,
],
home_url('/')
);
return wp_nonce_url($url, 'aksrt-logout');
}
endif;
if (!function_exists('aksrt_get_reset_password_url')) :
/**
* 获取重置密码页面 URL
*
* @param string $token 主题重置 token(可选,设置密码时需要)
* @param int $user_id 用户 ID(可选,设置密码时需要)
* @return string
*/
function aksrt_get_reset_password_url(string $token = '', int $user_id = 0): string {
$url = aksrt_get_template_url('reset-password');
if ($token !== '' && $user_id > 0) {
$url = add_query_arg([
'token' => $token,
'uid' => $user_id,
], $url);
}
return $url;
}
endif;
if (!function_exists('aksrt_get_verify_email_url')) :
/** 获取邮箱验证页面 URL */
function aksrt_get_verify_email_url(int $user_id = 0, array $args = []): string {
$url = aksrt_get_template_url('verify-email');
if ($user_id > 0) {
$args['uid'] = $user_id;
}
if (!empty($args)) {
$url = add_query_arg($args, $url);
}
return $url;
}
endif;
// Notifications live in the same user/ domain; bootstrap also loads it.
if (!class_exists('AKSRT_User_Notifications', false) /* procedural module */ && file_exists(dirname(__DIR__) . '/user-notifications.php')) {
require_once dirname(__DIR__) . '/user-notifications.php';
}