$label) { $new[$key] = $label; if ($key === 'title') { $new['aksrt_plate'] = __('版块', 'aksrt'); $new['aksrt_sticky'] = __('置顶', 'aksrt'); $new['aksrt_locked'] = __('锁定', 'aksrt'); $new['aksrt_review'] = __('审核', 'aksrt'); $new['aksrt_bbs_type']= __('类型', 'aksrt'); $new['aksrt_views'] = __('阅读', 'aksrt'); } } return $new; } public function sortable_columns(array $columns): array { $columns['aksrt_sticky'] = 'aksrt_sticky'; $columns['aksrt_views'] = 'aksrt_views'; return $columns; } public function render_column(string $column, int $post_id): void { switch ($column) { case 'aksrt_plate': $plate_id = (int) get_post_meta($post_id, '_aksrt_plate_id', true); if ($plate_id > 0) { $plate = get_post($plate_id); echo $plate ? esc_html(get_the_title($plate)) : esc_html('#' . $plate_id); } else { // fallback board taxonomy $terms = get_the_terms($post_id, 'aksrt_forum_board'); if (is_array($terms) && $terms) { echo esc_html($terms[0]->name); } else { echo '—'; } } break; case 'aksrt_sticky': $sticky = (int) get_post_meta($post_id, '_aksrt_sticky', true); $map = [ 0 => __('否', 'aksrt'), 1 => __('版块', 'aksrt'), 2 => __('超级', 'aksrt'), 3 => __('全局', 'aksrt'), ]; echo esc_html($map[$sticky] ?? (string) $sticky); echo '
'; break; case 'aksrt_locked': $locked = (int) get_post_meta($post_id, '_aksrt_locked', true); echo $locked ? esc_html__('是', 'aksrt') : esc_html__('否', 'aksrt'); break; case 'aksrt_review': $status = (string) get_post_meta($post_id, '_aksrt_review_status', true); if ($status === '') { $status = 'approved'; } $map = [ 'approved' => __('已通过', 'aksrt'), 'pending' => __('待审核', 'aksrt'), 'rejected' => __('已拒绝', 'aksrt'), ]; echo esc_html($map[$status] ?? $status); break; case 'aksrt_bbs_type': $type = (string) (get_post_meta($post_id, '_aksrt_bbs_type', true) ?: 'standard'); echo esc_html($type === 'question' ? __('提问', 'aksrt') : __('标准', 'aksrt')); break; case 'aksrt_views': echo esc_html((string) (int) get_post_meta($post_id, '_aksrt_views', true)); break; } } public function filters(string $post_type): void { if ($post_type !== 'aksrt_forum_topic') { return; } $sticky = isset($_GET['aksrt_sticky']) ? sanitize_key((string) wp_unslash($_GET['aksrt_sticky'])) : ''; $locked = isset($_GET['aksrt_locked']) ? sanitize_key((string) wp_unslash($_GET['aksrt_locked'])) : ''; $review = isset($_GET['aksrt_review']) ? sanitize_key((string) wp_unslash($_GET['aksrt_review'])) : ''; $plate = isset($_GET['aksrt_plate']) ? (int) $_GET['aksrt_plate'] : 0; echo ' '; echo ' '; echo ' '; $plates = get_posts([ 'post_type' => 'aksrt_forum_plate', 'post_status' => 'publish', 'posts_per_page' => 200, 'orderby' => 'title', 'order' => 'ASC', ]); if ($plates) { echo ' '; } } public function apply_filters(WP_Query $query): void { if (!is_admin() || !$query->is_main_query()) { return; } $post_type = $query->get('post_type'); if ($post_type !== 'aksrt_forum_topic') { return; } $meta_query = (array) $query->get('meta_query'); if (isset($_GET['aksrt_sticky']) && $_GET['aksrt_sticky'] !== '') { $meta_query[] = [ 'key' => '_aksrt_sticky', 'value' => (int) $_GET['aksrt_sticky'], ]; } if (isset($_GET['aksrt_locked']) && $_GET['aksrt_locked'] !== '') { $meta_query[] = [ 'key' => '_aksrt_locked', 'value' => (int) $_GET['aksrt_locked'], ]; } if (!empty($_GET['aksrt_review'])) { $review = sanitize_key((string) wp_unslash($_GET['aksrt_review'])); if ($review === 'approved') { $meta_query[] = [ 'relation' => 'OR', [ 'key' => '_aksrt_review_status', 'value' => 'approved', ], [ 'key' => '_aksrt_review_status', 'compare' => 'NOT EXISTS', ], [ 'key' => '_aksrt_review_status', 'value' => '', ], ]; } else { $meta_query[] = [ 'key' => '_aksrt_review_status', 'value' => $review, ]; } } if (!empty($_GET['aksrt_plate'])) { $meta_query[] = [ 'key' => '_aksrt_plate_id', 'value' => (int) $_GET['aksrt_plate'], ]; } if ($meta_query) { $query->set('meta_query', $meta_query); } $orderby = $query->get('orderby'); if ($orderby === 'aksrt_sticky') { $query->set('meta_key', '_aksrt_sticky'); $query->set('orderby', 'meta_value_num'); } elseif ($orderby === 'aksrt_views') { $query->set('meta_key', '_aksrt_views'); $query->set('orderby', 'meta_value_num'); } } public function bulk_actions(array $actions): array { $actions['aksrt_sticky_1'] = __('设为版块置顶', 'aksrt'); $actions['aksrt_sticky_0'] = __('取消置顶', 'aksrt'); $actions['aksrt_lock'] = __('锁定', 'aksrt'); $actions['aksrt_unlock'] = __('解锁', 'aksrt'); $actions['aksrt_approve'] = __('审核通过', 'aksrt'); $actions['aksrt_reject'] = __('审核拒绝', 'aksrt'); return $actions; } public function handle_bulk_actions(string $redirect_to, string $action, array $post_ids): string { $count = 0; foreach ($post_ids as $post_id) { $post_id = (int) $post_id; if ($post_id <= 0 || get_post_type($post_id) !== 'aksrt_forum_topic') { continue; } switch ($action) { case 'aksrt_sticky_1': update_post_meta($post_id, '_aksrt_sticky', 1); $count++; break; case 'aksrt_sticky_0': update_post_meta($post_id, '_aksrt_sticky', 0); $count++; break; case 'aksrt_lock': update_post_meta($post_id, '_aksrt_locked', 1); $count++; break; case 'aksrt_unlock': update_post_meta($post_id, '_aksrt_locked', 0); $count++; break; case 'aksrt_approve': update_post_meta($post_id, '_aksrt_review_status', 'approved'); $count++; break; case 'aksrt_reject': update_post_meta($post_id, '_aksrt_review_status', 'rejected'); $count++; break; } } return add_query_arg('aksrt_topic_bulk', $count, $redirect_to); } public function bulk_notices(): void { if (empty($_GET['aksrt_topic_bulk'])) { return; } $count = (int) $_GET['aksrt_topic_bulk']; echo '' . esc_html(sprintf( /* translators: %d count */ __('已更新 %d 个帖子。', 'aksrt'), $count )) . '