Merge pull request 'fix(ns): root-qualify WP_* classes after PSR-4 move' (#198) from fix/ns-root-wp-classes into main
Reviewed-on: CYL/wordpress-theme-aksrt#198
This commit is contained in:
commit
e5b5e57bdd
9 files changed
+27
-27
No files matched your search
@@ -124,7 +124,7 @@ class CommentController extends ControllerBase {
|
|||||||
$args['search'] = $search;
|
$args['search'] = $search;
|
||||||
}
|
}
|
||||||
|
|
||||||
$query = new WP_Comment_Query($args);
|
$query = new \WP_Comment_Query($args);
|
||||||
|
|
||||||
// Batch prefetch to avoid N+1 queries
|
// Batch prefetch to avoid N+1 queries
|
||||||
$user_ids = array_unique(array_filter(array_map(fn($c) => (int) $c->user_id, $query->comments)));
|
$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;
|
$count_args = $args;
|
||||||
unset($count_args['number'], $count_args['offset'], $count_args['orderby'], $count_args['order']);
|
unset($count_args['number'], $count_args['offset'], $count_args['orderby'], $count_args['order']);
|
||||||
$count_args['count'] = true;
|
$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([
|
return $this->success([
|
||||||
'data' => $comments,
|
'data' => $comments,
|
||||||
@@ -341,7 +341,7 @@ class CommentController extends ControllerBase {
|
|||||||
'hierarchical' => 'threaded',
|
'hierarchical' => 'threaded',
|
||||||
];
|
];
|
||||||
|
|
||||||
$query = new WP_Comment_Query($args);
|
$query = new \WP_Comment_Query($args);
|
||||||
|
|
||||||
// Batch prefetch users
|
// Batch prefetch users
|
||||||
$user_ids = array_unique(array_filter(array_map(fn($c) => (int) $c->user_id, $query->comments)));
|
$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.
|
* 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;
|
$uid = (int) $comment->user_id;
|
||||||
$pid = (int) $comment->comment_post_ID;
|
$pid = (int) $comment->comment_post_ID;
|
||||||
$user = $users_map[$uid] ?? ($uid ? get_userdata($uid) : null);
|
$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).
|
* 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;
|
$uid = (int) $comment->user_id;
|
||||||
$user = $users_map[$uid] ?? ($uid ? get_userdata($uid) : null);
|
$user = $users_map[$uid] ?? ($uid ? get_userdata($uid) : null);
|
||||||
return [
|
return [
|
||||||
|
|||||||
@@ -331,7 +331,7 @@ trait UserControllerReportOperations {
|
|||||||
}
|
}
|
||||||
} elseif ($target_type === 'comment') {
|
} elseif ($target_type === 'comment') {
|
||||||
$comment = get_comment($target_id);
|
$comment = get_comment($target_id);
|
||||||
if ($comment instanceof WP_Comment) {
|
if ($comment instanceof \WP_Comment) {
|
||||||
$summary['display_name'] = (string) $comment->comment_author;
|
$summary['display_name'] = (string) $comment->comment_author;
|
||||||
$summary['excerpt'] = wp_trim_words(wp_strip_all_tags((string) $comment->comment_content), 24);
|
$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;
|
$summary['status'] = $comment->comment_approved === '1' ? 'approved' : (string) $comment->comment_approved;
|
||||||
|
|||||||
@@ -261,7 +261,7 @@ class Moderation {
|
|||||||
*/
|
*/
|
||||||
public function after_post(int $comment_id, $comment_approved, array $commentdata = []): void {
|
public function after_post(int $comment_id, $comment_approved, array $commentdata = []): void {
|
||||||
$comment = get_comment($comment_id);
|
$comment = get_comment($comment_id);
|
||||||
if (!$comment instanceof WP_Comment) {
|
if (!$comment instanceof \WP_Comment) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
$fp_data = $this->comment_fingerprint($commentdata);
|
||||||
if ($fp_data !== '' && isset($this->moderation_result_map[$fp_data])) {
|
if ($fp_data !== '' && isset($this->moderation_result_map[$fp_data])) {
|
||||||
return $this->moderation_result_map[$fp_data];
|
return $this->moderation_result_map[$fp_data];
|
||||||
|
|||||||
@@ -14,14 +14,14 @@ trait BalanceServiceRest {
|
|||||||
public function register_routes(): void {
|
public function register_routes(): void {
|
||||||
register_rest_route('aksrt/v1', '/pay/balance/charge', [
|
register_rest_route('aksrt/v1', '/pay/balance/charge', [
|
||||||
[
|
[
|
||||||
'methods' => WP_REST_Server::READABLE,
|
'methods' => \WP_REST_Server::READABLE,
|
||||||
'callback' => [$this, 'rest_charge_options'],
|
'callback' => [$this, 'rest_charge_options'],
|
||||||
'permission_callback' => static function () {
|
'permission_callback' => static function () {
|
||||||
return is_user_logged_in();
|
return is_user_logged_in();
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'methods' => WP_REST_Server::CREATABLE,
|
'methods' => \WP_REST_Server::CREATABLE,
|
||||||
'callback' => [$this, 'rest_charge_create'],
|
'callback' => [$this, 'rest_charge_create'],
|
||||||
'permission_callback' => static function () {
|
'permission_callback' => static function () {
|
||||||
return is_user_logged_in();
|
return is_user_logged_in();
|
||||||
@@ -31,7 +31,7 @@ trait BalanceServiceRest {
|
|||||||
|
|
||||||
register_rest_route('aksrt/v1', '/pay/transfer', [
|
register_rest_route('aksrt/v1', '/pay/transfer', [
|
||||||
[
|
[
|
||||||
'methods' => WP_REST_Server::CREATABLE,
|
'methods' => \WP_REST_Server::CREATABLE,
|
||||||
'callback' => [$this, 'rest_transfer'],
|
'callback' => [$this, 'rest_transfer'],
|
||||||
'permission_callback' => static function () {
|
'permission_callback' => static function () {
|
||||||
return is_user_logged_in();
|
return is_user_logged_in();
|
||||||
@@ -41,7 +41,7 @@ trait BalanceServiceRest {
|
|||||||
|
|
||||||
register_rest_route('aksrt/v1', '/pay/transfer/search', [
|
register_rest_route('aksrt/v1', '/pay/transfer/search', [
|
||||||
[
|
[
|
||||||
'methods' => WP_REST_Server::READABLE,
|
'methods' => \WP_REST_Server::READABLE,
|
||||||
'callback' => [$this, 'rest_transfer_search'],
|
'callback' => [$this, 'rest_transfer_search'],
|
||||||
'permission_callback' => static function () {
|
'permission_callback' => static function () {
|
||||||
return is_user_logged_in();
|
return is_user_logged_in();
|
||||||
@@ -51,7 +51,7 @@ trait BalanceServiceRest {
|
|||||||
|
|
||||||
register_rest_route('aksrt/v1', '/pay/balance/exchange', [
|
register_rest_route('aksrt/v1', '/pay/balance/exchange', [
|
||||||
[
|
[
|
||||||
'methods' => WP_REST_Server::CREATABLE,
|
'methods' => \WP_REST_Server::CREATABLE,
|
||||||
'callback' => [$this, 'rest_exchange_from_credits'],
|
'callback' => [$this, 'rest_exchange_from_credits'],
|
||||||
'permission_callback' => static function () {
|
'permission_callback' => static function () {
|
||||||
return is_user_logged_in();
|
return is_user_logged_in();
|
||||||
@@ -61,14 +61,14 @@ trait BalanceServiceRest {
|
|||||||
|
|
||||||
register_rest_route('aksrt/v1', '/pay/points/buy', [
|
register_rest_route('aksrt/v1', '/pay/points/buy', [
|
||||||
[
|
[
|
||||||
'methods' => WP_REST_Server::READABLE,
|
'methods' => \WP_REST_Server::READABLE,
|
||||||
'callback' => [$this, 'rest_points_buy_options'],
|
'callback' => [$this, 'rest_points_buy_options'],
|
||||||
'permission_callback' => static function () {
|
'permission_callback' => static function () {
|
||||||
return is_user_logged_in();
|
return is_user_logged_in();
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'methods' => WP_REST_Server::CREATABLE,
|
'methods' => \WP_REST_Server::CREATABLE,
|
||||||
'callback' => [$this, 'rest_points_buy_create'],
|
'callback' => [$this, 'rest_points_buy_create'],
|
||||||
'permission_callback' => static function () {
|
'permission_callback' => static function () {
|
||||||
return is_user_logged_in();
|
return is_user_logged_in();
|
||||||
@@ -78,7 +78,7 @@ trait BalanceServiceRest {
|
|||||||
|
|
||||||
register_rest_route('aksrt/v1', '/pay/balance/withdraw', [
|
register_rest_route('aksrt/v1', '/pay/balance/withdraw', [
|
||||||
[
|
[
|
||||||
'methods' => WP_REST_Server::CREATABLE,
|
'methods' => \WP_REST_Server::CREATABLE,
|
||||||
'callback' => [$this, 'rest_balance_withdraw'],
|
'callback' => [$this, 'rest_balance_withdraw'],
|
||||||
'permission_callback' => static function () {
|
'permission_callback' => static function () {
|
||||||
return is_user_logged_in();
|
return is_user_logged_in();
|
||||||
@@ -261,7 +261,7 @@ trait BalanceServiceRest {
|
|||||||
return rest_ensure_response(['success' => true, 'data' => ['users' => []]]);
|
return rest_ensure_response(['success' => true, 'data' => ['users' => []]]);
|
||||||
}
|
}
|
||||||
$exclude = [get_current_user_id()];
|
$exclude = [get_current_user_id()];
|
||||||
$q = new WP_User_Query([
|
$q = new \WP_User_Query([
|
||||||
'search' => '*' . $s . '*',
|
'search' => '*' . $s . '*',
|
||||||
'search_columns' => ['user_login', 'user_nicename', 'display_name', 'user_email'],
|
'search_columns' => ['user_login', 'user_nicename', 'display_name', 'user_email'],
|
||||||
'exclude' => $exclude,
|
'exclude' => $exclude,
|
||||||
|
|||||||
@@ -263,7 +263,7 @@ class Credits {
|
|||||||
$q['search'] = '*' . esc_attr((string) $args['search']) . '*';
|
$q['search'] = '*' . esc_attr((string) $args['search']) . '*';
|
||||||
$q['search_columns'] = ['user_login', 'user_email', 'display_name', 'user_nicename'];
|
$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();
|
$users = $user_query->get_results();
|
||||||
$items = [];
|
$items = [];
|
||||||
foreach ($users as $u) {
|
foreach ($users as $u) {
|
||||||
|
|||||||
@@ -101,8 +101,8 @@ class Earn {
|
|||||||
if ($on_approved) {
|
if ($on_approved) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$comment = $comment instanceof WP_Comment ? $comment : get_comment($comment_id);
|
$comment = $comment instanceof \WP_Comment ? $comment : get_comment($comment_id);
|
||||||
if (!($comment instanceof WP_Comment) || (int) $comment->comment_approved !== 1) {
|
if (!($comment instanceof \WP_Comment) || (int) $comment->comment_approved !== 1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$this->reward_comment($comment);
|
$this->reward_comment($comment);
|
||||||
@@ -110,13 +110,13 @@ class Earn {
|
|||||||
|
|
||||||
public function on_comment_transition($new_status, $old_status, $comment): void {
|
public function on_comment_transition($new_status, $old_status, $comment): void {
|
||||||
unset($old_status);
|
unset($old_status);
|
||||||
if ($new_status !== 'approved' || !($comment instanceof WP_Comment)) {
|
if ($new_status !== 'approved' || !($comment instanceof \WP_Comment)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$this->reward_comment($comment);
|
$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;
|
$user_id = (int) $comment->user_id;
|
||||||
if ($user_id <= 0 || !class_exists('PointsFree')) {
|
if ($user_id <= 0 || !class_exists('PointsFree')) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ class CommentService {
|
|||||||
/**
|
/**
|
||||||
* Render forum comments HTML for AJAX and initial load.
|
* 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 $topic_id Topic post ID.
|
||||||
* @param int $adopted_id Adopted comment ID (0 if none).
|
* @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 bool $author_only Only show post-author replies.
|
||||||
* @param int $page Page number.
|
* @param int $page Page number.
|
||||||
* @param int $per_page Items per page.
|
* @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 {
|
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);
|
$post = get_post($topic_id);
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ trait CategoryIntegrationGroups {
|
|||||||
/**
|
/**
|
||||||
* Customizer 注册(可选)
|
* 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('blogname', ['default' => get_bloginfo('name'), 'type' => 'option']);
|
||||||
|
|
||||||
$wp_customize->add_setting('aksrt_logo', [
|
$wp_customize->add_setting('aksrt_logo', [
|
||||||
@@ -132,7 +132,7 @@ trait CategoryIntegrationGroups {
|
|||||||
'sanitize_callback' => 'esc_url_raw',
|
'sanitize_callback' => 'esc_url_raw',
|
||||||
'transport' => 'postMessage',
|
'transport' => 'postMessage',
|
||||||
]);
|
]);
|
||||||
$wp_customize->add_control(new WP_Customize_Image_Control(
|
$wp_customize->add_control(new \WP_Customize_Image_Control(
|
||||||
$wp_customize,
|
$wp_customize,
|
||||||
'aksrt_logo',
|
'aksrt_logo',
|
||||||
['label' => __('Logo', 'aksrt'), 'section' => 'title_tagline']
|
['label' => __('Logo', 'aksrt'), 'section' => 'title_tagline']
|
||||||
@@ -143,7 +143,7 @@ trait CategoryIntegrationGroups {
|
|||||||
'sanitize_callback' => 'esc_url_raw',
|
'sanitize_callback' => 'esc_url_raw',
|
||||||
'transport' => 'postMessage',
|
'transport' => 'postMessage',
|
||||||
]);
|
]);
|
||||||
$wp_customize->add_control(new WP_Customize_Upload_Control(
|
$wp_customize->add_control(new \WP_Customize_Upload_Control(
|
||||||
$wp_customize,
|
$wp_customize,
|
||||||
'aksrt_favicon',
|
'aksrt_favicon',
|
||||||
['label' => __('Favicon', 'aksrt'), 'section' => 'title_tagline']
|
['label' => __('Favicon', 'aksrt'), 'section' => 'title_tagline']
|
||||||
|
|||||||
Reference in new issue
Block a user