refactor(admin): split pay menus modules; plate icon/sort fields

This commit is contained in:
kate522 committed 2026-07-15 09:52:29 +08:00
1 parent deee48245f
commit 22dfed5977
8 files changed
+1304 -963

No files matched your search

@@ -87,8 +87,11 @@ class AKSRT_Plate_Meta_Box {
$add_roles = get_post_meta($plate_id, '_aksrt_add_limit_roles', true);
$add_roles = is_array($add_roles) ? array_map('sanitize_key', $add_roles) : [];
$wp_roles = $this->wp_role_options();
$icon = (string) get_post_meta($plate_id, '_aksrt_icon', true);
$sort_order = (int) get_post_meta($plate_id, '_aksrt_sort_order', true);
$this->render_access_fields($allow_view, $add_limit, $view_roles, $add_roles, $wp_roles);
$this->render_display_fields($icon, $sort_order);
$this->render_moderator_fields($moderator_ids, $roles_map, $author_id);
$this->render_applications($applications);
}
@@ -148,6 +151,22 @@ class AKSRT_Plate_Meta_Box {
<?php
}
private function render_display_fields(string $icon, int $sort_order): void {
?>
<p>
<label for="aksrt_plate_icon"><strong><?php esc_html_e('图标', 'aksrt'); ?></strong></label>
<input type="text" id="aksrt_plate_icon" name="aksrt_plate_icon" class="widefat" value="<?php echo esc_attr($icon); ?>" placeholder="fa-comments / dashicons-admin-site" />
<span class="description"><?php esc_html_e('图标 class 或标识,保存即重写。', 'aksrt'); ?></span>
</p>
<p>
<label for="aksrt_plate_sort_order"><strong><?php esc_html_e('排序', 'aksrt'); ?></strong></label>
<input type="number" id="aksrt_plate_sort_order" name="aksrt_plate_sort_order" class="widefat" value="<?php echo esc_attr((string) $sort_order); ?>" step="1" />
<span class="description"><?php esc_html_e('数字越小越靠前。', 'aksrt'); ?></span>
</p>
<hr>
<?php
}
/**
* @param list<int> $moderator_ids
* @param array<int|string,string> $roles_map
@@ -261,10 +280,23 @@ class AKSRT_Plate_Meta_Box {
}
$this->save_access_meta($post_id);
$this->save_display_meta($post_id);
$this->save_moderators($post_id, (int) $post->post_author);
$this->save_applications();
}
private function save_display_meta(int $post_id): void {
$icon = isset($_POST['aksrt_plate_icon'])
? sanitize_text_field((string) wp_unslash($_POST['aksrt_plate_icon']))
: '';
update_post_meta($post_id, '_aksrt_icon', $icon);
$sort = isset($_POST['aksrt_plate_sort_order'])
? (int) wp_unslash($_POST['aksrt_plate_sort_order'])
: 0;
update_post_meta($post_id, '_aksrt_sort_order', $sort);
}
private function save_access_meta(int $post_id): void {
$allow_view = isset($_POST['aksrt_plate_allow_view']) ? sanitize_key((string) wp_unslash($_POST['aksrt_plate_allow_view'])) : 'public';
if (!in_array($allow_view, self::ALLOW_VIEW, true)) {