fix(ns): class_exists() must use FQCN after PSR-4

Bare class_exists('Balance') looks up global Balance, always false
under AKSRT\* namespaces → REST 403 on balance exchange and friends.
Rewrite string checks to AKSRT\{Domain}\{Class}.
This commit is contained in:
kate522 committed 2026-07-17 15:40:20 +08:00
1 parent d55d1c6b62
commit 68d2e78d77
40 files changed
+105 -105

No files matched your search

+3 -3
View File
@@ -32,7 +32,7 @@ trait BalanceServiceCharge {
// Points purchase fulfill (zibll order_type=9).
if ($type === \AKSRT\Core\DomainModel::ORDER_PRODUCT_POINTS_BUY) {
if (!class_exists('Credits')) {
if (!class_exists('AKSRT\\Credits\\Credits')) {
return;
}
$note = json_decode((string) ($order['note'] ?? ''), true);
@@ -78,7 +78,7 @@ trait BalanceServiceCharge {
if ($type !== \AKSRT\Core\DomainModel::ORDER_PRODUCT_RECHARGE) {
return;
}
if (!class_exists('Balance')) {
if (!class_exists('AKSRT\\Credits\\Balance')) {
return;
}
$note = json_decode((string) ($order['note'] ?? ''), true);
@@ -140,7 +140,7 @@ trait BalanceServiceCharge {
return [
'enabled' => !empty($cfg['enabled']),
'desc' => (string) ($cfg['desc'] ?? ''),
'wallet' => class_exists('Balance') ? Balance::balance($user_id) : 0.0,
'wallet' => class_exists('AKSRT\\Credits\\Balance') ? Balance::balance($user_id) : 0.0,
'packages' => $packages,
'custom_s' => $custom_s,
'custom_limit' => $custom_limit,
+3 -3
View File
@@ -38,13 +38,13 @@ trait BalanceServicePoints {
if ($id === '') {
continue;
}
if ($id === 'balance' && !(class_exists('Balance') && Balance::enabled())) {
if ($id === 'balance' && !(class_exists('AKSRT\\Credits\\Balance') && Balance::enabled())) {
continue;
}
$methods[] = is_array($m) ? $m : ['id' => $id, 'name' => $id];
}
}
if (class_exists('Balance') && Balance::enabled()) {
if (class_exists('AKSRT\\Credits\\Balance') && Balance::enabled()) {
$has_bal = false;
foreach ($methods as $m) {
if (($m['id'] ?? '') === 'balance') {
@@ -60,7 +60,7 @@ trait BalanceServicePoints {
'enabled' => $this->points_buy_enabled(),
'desc' => (string) ($all['pay_points_desc'] ?? ''),
'rate' => $rate,
'points' => class_exists('Credits') ? Credits::balance($user_id) : 0,
'points' => class_exists('AKSRT\\Credits\\Credits') ? Credits::balance($user_id) : 0,
'packages' => $packages,
'custom_s' => $custom_s,
'custom_limit' => $custom_limit,
+7 -7
View File
@@ -93,7 +93,7 @@ trait BalanceServiceRest {
* GET charge options (packages + methods + limits).
*/
public function rest_charge_options(\WP_REST_Request $request) {
if (!class_exists('Balance') || !Balance::enabled()) {
if (!class_exists('AKSRT\\Credits\\Balance') || !Balance::enabled()) {
return new \WP_Error('aksrt_balance_disabled', __('余额功能未启用', 'aksrt'), ['status' => 403]);
}
$user_id = get_current_user_id();
@@ -109,7 +109,7 @@ trait BalanceServiceRest {
* POST create recharge order and initiate payment.
*/
public function rest_charge_create(\WP_REST_Request $request) {
if (!class_exists('Balance') || !Balance::enabled()) {
if (!class_exists('AKSRT\\Credits\\Balance') || !Balance::enabled()) {
return new \WP_Error('aksrt_balance_disabled', __('余额功能未启用', 'aksrt'), ['status' => 403]);
}
$user_id = get_current_user_id();
@@ -168,7 +168,7 @@ trait BalanceServiceRest {
if ($amount <= 0) {
return new \WP_Error('aksrt_transfer_amount', __('请输入有效金额', 'aksrt'), ['status' => 400]);
}
if (!class_exists('Balance')) {
if (!class_exists('AKSRT\\Credits\\Balance')) {
return new \WP_Error('aksrt_balance_unavailable', __('余额系统不可用', 'aksrt'), ['status' => 500]);
}
$from_bal = Balance::balance($from_id);
@@ -219,7 +219,7 @@ trait BalanceServiceRest {
if ($amount <= 0) {
return new \WP_Error('aksrt_transfer_amount', __('请输入有效积分', 'aksrt'), ['status' => 400]);
}
if (!class_exists('Credits')) {
if (!class_exists('AKSRT\\Credits\\Credits')) {
return new \WP_Error('aksrt_credits_unavailable', __('积分系统不可用', 'aksrt'), ['status' => 500]);
}
$fee_rate = max(0, min(50, (int) (\AKSRT\Settings\Settings::get_all()['points_service_charge'] ?? 0)));
@@ -286,14 +286,14 @@ trait BalanceServiceRest {
* Exchange points → cash wallet (pay_balance_exchange_*).
*/
public function rest_exchange_from_credits(\WP_REST_Request $request) {
if (!class_exists('Balance') || !Balance::enabled()) {
if (!class_exists('AKSRT\\Credits\\Balance') || !Balance::enabled()) {
return new \WP_Error('aksrt_balance_disabled', __('余额功能未启用', 'aksrt'), ['status' => 403]);
}
$cfg = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_payment_recharge_settings() : [];
if (empty($cfg['exchange']['enabled'])) {
return new \WP_Error('aksrt_exchange_closed', __('积分兑换余额未开启', 'aksrt'), ['status' => 403]);
}
if (!class_exists('Credits') || !\AKSRT\Settings\Settings::credits_enabled()) {
if (!class_exists('AKSRT\\Credits\\Credits') || !\AKSRT\Settings\Settings::credits_enabled()) {
return new \WP_Error('aksrt_credits_disabled', __('积分功能未启用', 'aksrt'), ['status' => 403]);
}
$params = $request->get_json_params();
@@ -380,7 +380,7 @@ trait BalanceServiceRest {
public function rest_balance_withdraw(\WP_REST_Request $request) {
if (!class_exists('Balance') || !Balance::enabled()) {
if (!class_exists('AKSRT\\Credits\\Balance') || !Balance::enabled()) {
return new \WP_Error('aksrt_balance_disabled', __('余额功能未启用', 'aksrt'), ['status' => 403]);
}
$settings = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_all() : [];
+10 -10
View File
@@ -39,7 +39,7 @@ class Earn {
}
public function on_user_register(int $user_id): void {
if (!class_exists('PointsFree')) {
if (!class_exists('AKSRT\\Credits\\PointsFree')) {
return;
}
PointsFree::grant($user_id, 'sign_up', 0, ['type' => 'user', 'id' => $user_id]);
@@ -54,7 +54,7 @@ class Earn {
public function on_wp_login($user_login, $user = null): void {
unset($user_login);
$user_id = $user instanceof \WP_User ? (int) $user->ID : 0;
if ($user_id <= 0 || !class_exists('PointsFree')) {
if ($user_id <= 0 || !class_exists('AKSRT\\Credits\\PointsFree')) {
return;
}
$today = (new \DateTimeImmutable('today', wp_timezone()))->format('Y-m-d');
@@ -81,7 +81,7 @@ class Earn {
return;
}
$user_id = (int) $post->post_author;
if ($user_id <= 0 || !class_exists('PointsFree')) {
if ($user_id <= 0 || !class_exists('AKSRT\\Credits\\PointsFree')) {
return;
}
if (get_post_meta($post->ID, 'aksrt_credit_post_rewarded', true)) {
@@ -118,7 +118,7 @@ class Earn {
private function reward_comment(\WP_Comment $comment): void {
$user_id = (int) $comment->user_id;
if ($user_id <= 0 || !class_exists('PointsFree')) {
if ($user_id <= 0 || !class_exists('AKSRT\\Credits\\PointsFree')) {
return;
}
if (get_comment_meta($comment->comment_ID, 'aksrt_credit_rewarded', true)) {
@@ -150,7 +150,7 @@ class Earn {
* @param bool $active
*/
public function on_post_liked(int $post_id, int $actor_id, bool $active): void {
if (!$active || $post_id <= 0 || !class_exists('PointsFree')) {
if (!$active || $post_id <= 0 || !class_exists('AKSRT\\Credits\\PointsFree')) {
return;
}
$post = get_post($post_id);
@@ -165,7 +165,7 @@ class Earn {
}
public function on_post_favorited(int $post_id, int $actor_id, bool $active): void {
if (!$active || $post_id <= 0 || !class_exists('PointsFree')) {
if (!$active || $post_id <= 0 || !class_exists('AKSRT\\Credits\\PointsFree')) {
return;
}
$post = get_post($post_id);
@@ -180,7 +180,7 @@ class Earn {
}
public function on_comment_liked(int $comment_id, int $actor_id, bool $active): void {
if (!$active || $comment_id <= 0 || !class_exists('PointsFree')) {
if (!$active || $comment_id <= 0 || !class_exists('AKSRT\\Credits\\PointsFree')) {
return;
}
$comment = get_comment($comment_id);
@@ -195,14 +195,14 @@ class Earn {
}
public function on_user_followed(int $follower_id, int $following_id): void {
if ($following_id <= 0 || $follower_id === $following_id || !class_exists('PointsFree')) {
if ($following_id <= 0 || $follower_id === $following_id || !class_exists('AKSRT\\Credits\\PointsFree')) {
return;
}
PointsFree::grant($following_id, 'followed', 0, ['type' => 'user', 'id' => $follower_id]);
}
public function on_forum_topic_created(int $user_id, int $post_id): void {
if ($user_id <= 0 || !class_exists('PointsFree')) {
if ($user_id <= 0 || !class_exists('AKSRT\\Credits\\PointsFree')) {
return;
}
PointsFree::grant($user_id, 'bbs_posts_new', 0, ['type' => 'post', 'id' => $post_id]);
@@ -222,7 +222,7 @@ class Earn {
return;
}
$user_id = (int) $comment->user_id;
if ($user_id <= 0 || !class_exists('PointsFree')) {
if ($user_id <= 0 || !class_exists('AKSRT\\Credits\\PointsFree')) {
return;
}
if (get_comment_meta($comment_id, 'aksrt_credit_forum_reply', true)) {
+1 -1
View File
@@ -188,7 +188,7 @@ class Invite {
/** 双向发放奖励 */
private function reward_pair(int $inviter_id, int $invitee_id): void {
if (!class_exists('Credits') || !class_exists('\AKSRT\Settings\Settings')) return;
if (!class_exists('AKSRT\\Credits\\Credits') || !class_exists('\AKSRT\Settings\Settings')) return;
$invite_cfg = \AKSRT\Settings\Settings::get_invite_reward_settings();
if (empty($invite_cfg['enabled'])) return;
+1 -1
View File
@@ -82,7 +82,7 @@ class PointsFree {
* Whether free points system can run (credits enabled).
*/
public static function enabled(): bool {
return class_exists('\AKSRT\Settings\Settings') && \AKSRT\Settings\Settings::credits_enabled() && class_exists('Credits');
return class_exists('\AKSRT\Settings\Settings') && \AKSRT\Settings\Settings::credits_enabled() && class_exists('AKSRT\\Credits\\Credits');
}
/**
+4 -4
View File
@@ -127,16 +127,16 @@ class Signin {
do_action('aksrt_user_signed_in', $user_id);
if ($reward > 0) {
if (class_exists('PointsFree')) {
if (class_exists('AKSRT\\Credits\\PointsFree')) {
$granted = PointsFree::grant_amount($user_id, $reward, 'sign_in', ['type' => 'user', 'id' => $user_id]);
if (is_wp_error($granted)) {
if (class_exists('Credits')) {
if (class_exists('AKSRT\\Credits\\Credits')) {
Credits::add($user_id, $reward, 'signin', ['type' => 'user', 'id' => $user_id]);
}
} else {
$reward = (int) $granted;
}
} elseif (class_exists('Credits')) {
} elseif (class_exists('AKSRT\\Credits\\Credits')) {
Credits::add($user_id, $reward, 'signin', ['type' => 'user', 'id' => $user_id]);
}
}
@@ -145,7 +145,7 @@ class Signin {
'success' => true,
'streak' => $new_streak,
'reward' => $reward,
'balance' => class_exists('Credits') ? Credits::balance($user_id) : 0,
'balance' => class_exists('AKSRT\\Credits\\Credits') ? Credits::balance($user_id) : 0,
], 200);
}