$label) { $new[$key] = $label; if ($key === 'title') { $new['aksrt_plate_mods'] = __('版主数', 'aksrt'); $new['aksrt_plate_posts'] = __('帖子数', 'aksrt'); $new['aksrt_plate_reply'] = __('回复数', 'aksrt'); $new['aksrt_plate_views'] = __('浏览', 'aksrt'); $new['aksrt_plate_follow'] = __('关注', 'aksrt'); $new['aksrt_plate_pending_apps'] = __('待审申请', 'aksrt'); } } return $new; } public function sortable_columns(array $columns): array { $columns['aksrt_plate_posts'] = 'aksrt_posts_count'; $columns['aksrt_plate_views'] = 'aksrt_plate_views'; return $columns; } public function render_column(string $column, int $post_id): void { switch ($column) { case 'aksrt_plate_mods': $mods = get_post_meta($post_id, '_aksrt_moderators', true); $count = is_array($mods) ? count(array_filter(array_map('intval', $mods))) : 0; echo esc_html((string) $count); break; case 'aksrt_plate_posts': echo esc_html((string) (int) get_post_meta($post_id, '_aksrt_posts_count', true)); break; case 'aksrt_plate_reply': echo esc_html((string) (int) get_post_meta($post_id, '_aksrt_reply_count', true)); break; case 'aksrt_plate_views': echo esc_html((string) (int) get_post_meta($post_id, '_aksrt_plate_views', true)); break; case 'aksrt_plate_follow': echo esc_html((string) (int) get_post_meta($post_id, '_aksrt_follow_count', true)); break; case 'aksrt_plate_pending_apps': $apps = get_post_meta($post_id, '_aksrt_moderator_applications', true); $pending = 0; if (is_array($apps)) { foreach ($apps as $app) { if (is_array($app) && (($app['status'] ?? '') === 'pending')) { $pending++; } } } if ($pending > 0) { echo '' . esc_html((string) $pending) . ''; } else { echo '0'; } break; } } public function apply_orderby(WP_Query $query): void { if (!is_admin() || !$query->is_main_query()) { return; } if ($query->get('post_type') !== 'aksrt_forum_plate') { return; } $orderby = $query->get('orderby'); if ($orderby === 'aksrt_posts_count') { $query->set('meta_key', '_aksrt_posts_count'); $query->set('orderby', 'meta_value_num'); } elseif ($orderby === 'aksrt_plate_views') { $query->set('meta_key', '_aksrt_plate_views'); $query->set('orderby', 'meta_value_num'); } } }