From 1e21911b036910ea57f50ccd509aa269811e3511 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 17 Jul 2026 15:12:14 +0800 Subject: [PATCH] fix(ns): root-qualify WP_* classes after PSR-4 move Bare WP_REST_Server etc. resolve under AKSRT\* namespaces; prefix with \ for Balance REST and other type hints / constructors. --- src/AKSRT/Admin/CommentController.php | 10 +++++----- .../Admin/UserControllerReportOperations.php | 2 +- src/AKSRT/Auth/Moderation.php | 2 +- src/AKSRT/Auth/ModerationPart1.php | 2 +- src/AKSRT/Credits/BalanceServiceRest.php | 18 +++++++++--------- src/AKSRT/Credits/Credits.php | 2 +- src/AKSRT/Credits/Earn.php | 8 ++++---- src/AKSRT/Forum/CommentService.php | 4 ++-- .../Settings/CategoryIntegrationGroups.php | 6 +++--- 9 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/AKSRT/Admin/CommentController.php b/src/AKSRT/Admin/CommentController.php index 3e211b92..34156798 100644 --- a/src/AKSRT/Admin/CommentController.php +++ b/src/AKSRT/Admin/CommentController.php @@ -124,7 +124,7 @@ class CommentController extends ControllerBase { $args['search'] = $search; } - $query = new WP_Comment_Query($args); + $query = new \WP_Comment_Query($args); // Batch prefetch to avoid N+1 queries $user_ids = array_unique(array_filter(array_map(fn($c) => (int) $c->user_id, $query->comments))); @@ -151,7 +151,7 @@ class CommentController extends ControllerBase { $count_args = $args; unset($count_args['number'], $count_args['offset'], $count_args['orderby'], $count_args['order']); $count_args['count'] = true; - $total = (int) (new WP_Comment_Query($count_args))->get_comments('count'); + $total = (int) (new \WP_Comment_Query($count_args))->get_comments('count'); return $this->success([ 'data' => $comments, @@ -341,7 +341,7 @@ class CommentController extends ControllerBase { 'hierarchical' => 'threaded', ]; - $query = new WP_Comment_Query($args); + $query = new \WP_Comment_Query($args); // Batch prefetch users $user_ids = array_unique(array_filter(array_map(fn($c) => (int) $c->user_id, $query->comments))); @@ -374,7 +374,7 @@ class CommentController extends ControllerBase { /** * Format comment for admin views. */ - private function format_comment(WP_Comment $comment, array $users_map = [], array $posts_map = []): array { + private function format_comment(\WP_Comment $comment, array $users_map = [], array $posts_map = []): array { $uid = (int) $comment->user_id; $pid = (int) $comment->comment_post_ID; $user = $users_map[$uid] ?? ($uid ? get_userdata($uid) : null); @@ -398,7 +398,7 @@ class CommentController extends ControllerBase { /** * Format comment for public views (no email/IP). */ - private function format_comment_public(WP_Comment $comment, array $users_map = []): array { + private function format_comment_public(\WP_Comment $comment, array $users_map = []): array { $uid = (int) $comment->user_id; $user = $users_map[$uid] ?? ($uid ? get_userdata($uid) : null); return [ diff --git a/src/AKSRT/Admin/UserControllerReportOperations.php b/src/AKSRT/Admin/UserControllerReportOperations.php index e6d5608a..f1477d55 100644 --- a/src/AKSRT/Admin/UserControllerReportOperations.php +++ b/src/AKSRT/Admin/UserControllerReportOperations.php @@ -331,7 +331,7 @@ trait UserControllerReportOperations { } } elseif ($target_type === 'comment') { $comment = get_comment($target_id); - if ($comment instanceof WP_Comment) { + if ($comment instanceof \WP_Comment) { $summary['display_name'] = (string) $comment->comment_author; $summary['excerpt'] = wp_trim_words(wp_strip_all_tags((string) $comment->comment_content), 24); $summary['status'] = $comment->comment_approved === '1' ? 'approved' : (string) $comment->comment_approved; diff --git a/src/AKSRT/Auth/Moderation.php b/src/AKSRT/Auth/Moderation.php index 69bfd53e..25ae140c 100644 --- a/src/AKSRT/Auth/Moderation.php +++ b/src/AKSRT/Auth/Moderation.php @@ -261,7 +261,7 @@ class Moderation { */ public function after_post(int $comment_id, $comment_approved, array $commentdata = []): void { $comment = get_comment($comment_id); - if (!$comment instanceof WP_Comment) { + if (!$comment instanceof \WP_Comment) { return; } diff --git a/src/AKSRT/Auth/ModerationPart1.php b/src/AKSRT/Auth/ModerationPart1.php index f690c5e2..e7c2d6c8 100644 --- a/src/AKSRT/Auth/ModerationPart1.php +++ b/src/AKSRT/Auth/ModerationPart1.php @@ -130,7 +130,7 @@ trait ModerationPart1 { } } - private function resolve_result_from_runtime_or_default(array $commentdata, WP_Comment $comment): array { + private function resolve_result_from_runtime_or_default(array $commentdata, \WP_Comment $comment): array { $fp_data = $this->comment_fingerprint($commentdata); if ($fp_data !== '' && isset($this->moderation_result_map[$fp_data])) { return $this->moderation_result_map[$fp_data]; diff --git a/src/AKSRT/Credits/BalanceServiceRest.php b/src/AKSRT/Credits/BalanceServiceRest.php index ff989b45..69e686c3 100644 --- a/src/AKSRT/Credits/BalanceServiceRest.php +++ b/src/AKSRT/Credits/BalanceServiceRest.php @@ -14,14 +14,14 @@ trait BalanceServiceRest { public function register_routes(): void { register_rest_route('aksrt/v1', '/pay/balance/charge', [ [ - 'methods' => WP_REST_Server::READABLE, + 'methods' => \WP_REST_Server::READABLE, 'callback' => [$this, 'rest_charge_options'], 'permission_callback' => static function () { return is_user_logged_in(); }, ], [ - 'methods' => WP_REST_Server::CREATABLE, + 'methods' => \WP_REST_Server::CREATABLE, 'callback' => [$this, 'rest_charge_create'], 'permission_callback' => static function () { return is_user_logged_in(); @@ -31,7 +31,7 @@ trait BalanceServiceRest { register_rest_route('aksrt/v1', '/pay/transfer', [ [ - 'methods' => WP_REST_Server::CREATABLE, + 'methods' => \WP_REST_Server::CREATABLE, 'callback' => [$this, 'rest_transfer'], 'permission_callback' => static function () { return is_user_logged_in(); @@ -41,7 +41,7 @@ trait BalanceServiceRest { register_rest_route('aksrt/v1', '/pay/transfer/search', [ [ - 'methods' => WP_REST_Server::READABLE, + 'methods' => \WP_REST_Server::READABLE, 'callback' => [$this, 'rest_transfer_search'], 'permission_callback' => static function () { return is_user_logged_in(); @@ -51,7 +51,7 @@ trait BalanceServiceRest { register_rest_route('aksrt/v1', '/pay/balance/exchange', [ [ - 'methods' => WP_REST_Server::CREATABLE, + 'methods' => \WP_REST_Server::CREATABLE, 'callback' => [$this, 'rest_exchange_from_credits'], 'permission_callback' => static function () { return is_user_logged_in(); @@ -61,14 +61,14 @@ trait BalanceServiceRest { register_rest_route('aksrt/v1', '/pay/points/buy', [ [ - 'methods' => WP_REST_Server::READABLE, + 'methods' => \WP_REST_Server::READABLE, 'callback' => [$this, 'rest_points_buy_options'], 'permission_callback' => static function () { return is_user_logged_in(); }, ], [ - 'methods' => WP_REST_Server::CREATABLE, + 'methods' => \WP_REST_Server::CREATABLE, 'callback' => [$this, 'rest_points_buy_create'], 'permission_callback' => static function () { return is_user_logged_in(); @@ -78,7 +78,7 @@ trait BalanceServiceRest { register_rest_route('aksrt/v1', '/pay/balance/withdraw', [ [ - 'methods' => WP_REST_Server::CREATABLE, + 'methods' => \WP_REST_Server::CREATABLE, 'callback' => [$this, 'rest_balance_withdraw'], 'permission_callback' => static function () { return is_user_logged_in(); @@ -261,7 +261,7 @@ trait BalanceServiceRest { return rest_ensure_response(['success' => true, 'data' => ['users' => []]]); } $exclude = [get_current_user_id()]; - $q = new WP_User_Query([ + $q = new \WP_User_Query([ 'search' => '*' . $s . '*', 'search_columns' => ['user_login', 'user_nicename', 'display_name', 'user_email'], 'exclude' => $exclude, diff --git a/src/AKSRT/Credits/Credits.php b/src/AKSRT/Credits/Credits.php index 26ff3adc..6638135d 100644 --- a/src/AKSRT/Credits/Credits.php +++ b/src/AKSRT/Credits/Credits.php @@ -263,7 +263,7 @@ class Credits { $q['search'] = '*' . esc_attr((string) $args['search']) . '*'; $q['search_columns'] = ['user_login', 'user_email', 'display_name', 'user_nicename']; } - $user_query = new WP_User_Query($q); + $user_query = new \WP_User_Query($q); $users = $user_query->get_results(); $items = []; foreach ($users as $u) { diff --git a/src/AKSRT/Credits/Earn.php b/src/AKSRT/Credits/Earn.php index 848606ee..94453875 100644 --- a/src/AKSRT/Credits/Earn.php +++ b/src/AKSRT/Credits/Earn.php @@ -101,8 +101,8 @@ class Earn { if ($on_approved) { return; } - $comment = $comment instanceof WP_Comment ? $comment : get_comment($comment_id); - if (!($comment instanceof WP_Comment) || (int) $comment->comment_approved !== 1) { + $comment = $comment instanceof \WP_Comment ? $comment : get_comment($comment_id); + if (!($comment instanceof \WP_Comment) || (int) $comment->comment_approved !== 1) { return; } $this->reward_comment($comment); @@ -110,13 +110,13 @@ class Earn { public function on_comment_transition($new_status, $old_status, $comment): void { unset($old_status); - if ($new_status !== 'approved' || !($comment instanceof WP_Comment)) { + if ($new_status !== 'approved' || !($comment instanceof \WP_Comment)) { return; } $this->reward_comment($comment); } - private function reward_comment(WP_Comment $comment): void { + private function reward_comment(\WP_Comment $comment): void { $user_id = (int) $comment->user_id; if ($user_id <= 0 || !class_exists('PointsFree')) { return; diff --git a/src/AKSRT/Forum/CommentService.php b/src/AKSRT/Forum/CommentService.php index 9d6d2312..eacae583 100644 --- a/src/AKSRT/Forum/CommentService.php +++ b/src/AKSRT/Forum/CommentService.php @@ -109,7 +109,7 @@ class CommentService { /** * Render forum comments HTML for AJAX and initial load. * - * @param WP_Comment[] $comments Comments (parents + children mixed). + * @param \WP_Comment[] $comments Comments (parents + children mixed). * @param int $topic_id Topic post ID. * @param int $adopted_id Adopted comment ID (0 if none). */ @@ -366,7 +366,7 @@ class CommentService { * @param bool $author_only Only show post-author replies. * @param int $page Page number. * @param int $per_page Items per page. - * @return array{comments:WP_Comment[],total:int,max_pages:int,page:int,adopted_id:int} + * @return array{comments:\WP_Comment[],total:int,max_pages:int,page:int,adopted_id:int} */ public function get_forum_comments(int $topic_id, string $sort = 'newest', bool $author_only = false, int $page = 1, int $per_page = 30): array { $post = get_post($topic_id); diff --git a/src/AKSRT/Settings/CategoryIntegrationGroups.php b/src/AKSRT/Settings/CategoryIntegrationGroups.php index 76a08381..016716c5 100644 --- a/src/AKSRT/Settings/CategoryIntegrationGroups.php +++ b/src/AKSRT/Settings/CategoryIntegrationGroups.php @@ -124,7 +124,7 @@ trait CategoryIntegrationGroups { /** * Customizer 注册(可选) */ - public function customizer(WP_Customize_Manager $wp_customize): void { + public function customizer(\WP_Customize_Manager $wp_customize): void { $wp_customize->add_setting('blogname', ['default' => get_bloginfo('name'), 'type' => 'option']); $wp_customize->add_setting('aksrt_logo', [ @@ -132,7 +132,7 @@ trait CategoryIntegrationGroups { 'sanitize_callback' => 'esc_url_raw', 'transport' => 'postMessage', ]); - $wp_customize->add_control(new WP_Customize_Image_Control( + $wp_customize->add_control(new \WP_Customize_Image_Control( $wp_customize, 'aksrt_logo', ['label' => __('Logo', 'aksrt'), 'section' => 'title_tagline'] @@ -143,7 +143,7 @@ trait CategoryIntegrationGroups { 'sanitize_callback' => 'esc_url_raw', 'transport' => 'postMessage', ]); - $wp_customize->add_control(new WP_Customize_Upload_Control( + $wp_customize->add_control(new \WP_Customize_Upload_Control( $wp_customize, 'aksrt_favicon', ['label' => __('Favicon', 'aksrt'), 'section' => 'title_tagline']