Move 288 types from global AKSRT_* + inc/classes manual requires into
namespace AKSRT\{Domain} under src/AKSRT/, wire composer.json psr-4,
and slim bootstrap to helpers/modules/hooks only. Split multi-class
widget/gateway files, update admin contract audit paths, and document
the layout in ADR/README.
268 lines
8.0 KiB
PHP
268 lines
8.0 KiB
PHP
<?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 !== '') {
|
||
$url = add_query_arg('tab', $tab, $url);
|
||
}
|
||
return $url;
|
||
}
|
||
endif;
|
||
|
||
if (!function_exists('aksrt_get_orders_page_url')) :
|
||
/**
|
||
* 订单中心页面 URL(模板 templates/pages/page-orders.php)。
|
||
* 未指派页面时返回空串,调用方应隐藏入口。
|
||
*/
|
||
function aksrt_get_orders_page_url(): string {
|
||
return function_exists('aksrt_get_page_url_by_template')
|
||
? aksrt_get_page_url_by_template('templates/pages/page-orders.php')
|
||
: '';
|
||
}
|
||
endif;
|
||
|
||
if (!function_exists('aksrt_get_cart_page_url')) :
|
||
/**
|
||
* 购物车页面 URL(模板 templates/pages/page-cart.php)。
|
||
*/
|
||
function aksrt_get_cart_page_url(): string {
|
||
return function_exists('aksrt_get_page_url_by_template')
|
||
? aksrt_get_page_url_by_template('templates/pages/page-cart.php')
|
||
: '';
|
||
}
|
||
endif;
|
||
|
||
if (!function_exists('aksrt_get_revenue_page_url')) :
|
||
/**
|
||
* 收益中心页面 URL(模板 templates/pages/page-revenue.php)。
|
||
*/
|
||
function aksrt_get_revenue_page_url(): string {
|
||
return function_exists('aksrt_get_page_url_by_template')
|
||
? aksrt_get_page_url_by_template('templates/pages/page-revenue.php')
|
||
: '';
|
||
}
|
||
endif;
|
||
|
||
if (!function_exists('aksrt_get_messages_page_url')) :
|
||
/**
|
||
* 消息中心页面 URL(模板 templates/pages/page-messages.php)。
|
||
*/
|
||
function aksrt_get_messages_page_url(): string {
|
||
return function_exists('aksrt_get_page_url_by_template')
|
||
? aksrt_get_page_url_by_template('templates/pages/page-messages.php')
|
||
: '';
|
||
}
|
||
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_string($user) && $user) {
|
||
$slug = $user;
|
||
} else {
|
||
$current = wp_get_current_user();
|
||
$slug = $current->ID ? $current->user_nicename : '';
|
||
}
|
||
if (!$slug) return 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 */
|
||
function aksrt_get_logout_url($redirect = '') {
|
||
$target = $redirect ?: home_url('/');
|
||
$url = add_query_arg('redirect_to', rawurlencode($target), home_url('/logout/'));
|
||
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';
|
||
}
|
||
|