Allow creating shipping records and after-sale tickets from the native order detail page, and show plate moderator/stats columns on the forum plate list table. Source only; no SPA build artifacts.
108 lines
3.9 KiB
PHP
108 lines
3.9 KiB
PHP
<?php
|
|
/**
|
|
* Native list-table columns for aksrt_forum_plate.
|
|
*
|
|
* @package AKSRT
|
|
*/
|
|
|
|
defined('ABSPATH') || exit;
|
|
|
|
class AKSRT_Plate_Admin_List {
|
|
|
|
private static $instance = null;
|
|
|
|
public static function get_instance(): self {
|
|
if (null === self::$instance) {
|
|
self::$instance = new self();
|
|
}
|
|
return self::$instance;
|
|
}
|
|
|
|
public function init(): void {
|
|
if (!is_admin()) {
|
|
return;
|
|
}
|
|
add_filter('manage_edit-aksrt_forum_plate_columns', [$this, 'columns']);
|
|
add_action('manage_aksrt_forum_plate_posts_custom_column', [$this, 'render_column'], 10, 2);
|
|
add_filter('manage_edit-aksrt_forum_plate_sortable_columns', [$this, 'sortable_columns']);
|
|
add_action('pre_get_posts', [$this, 'apply_orderby']);
|
|
}
|
|
|
|
public function columns(array $columns): array {
|
|
$new = [];
|
|
foreach ($columns as $key => $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 '<strong style="color:#b32d2e;">' . esc_html((string) $pending) . '</strong>';
|
|
} 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');
|
|
}
|
|
}
|
|
}
|