fix(admin): replicate reference front-submit settings page 1:1

- Rewrite post_list/submit schema (PHP + JS) with the reference theme's
  field set, order, defaults and dependencies; topics fields excluded
- Map PostDisplay::get_submit_settings() and the FrontSubmit runtime to
  the new keys without legacy fallback
- Guest submission follows the capability matrix; category required on
  submit; pay limits read from the cash/points fieldset
- Drop dead front_submit_* settings, template branches and JS config
- Add submit settings reference contract test
This commit is contained in:
2026-09-24 12:29:19 +08:00
parent ed71314986
commit 264f2c51b2
14 changed files with 354 additions and 292 deletions
+10 -18
View File
@@ -32,7 +32,7 @@ trait FrontSubmitSave {
}
if ($is_guest) {
if (empty($settings['guest_enabled']) || (int) $settings['default_user_id'] <= 0) {
if ((int) $settings['default_user_id'] <= 0) {
return ['success' => false, 'message' => __('请先登录', 'aksrt')];
}
if ($is_draft) {
@@ -93,19 +93,16 @@ trait FrontSubmitSave {
if ($this->text_length(wp_strip_all_tags($content)) < 10) {
return ['success' => false, 'message' => __('文章内容过少', 'aksrt')];
}
if (!empty($settings['allow_category']) && empty($categories)) {
if (empty($categories)) {
return ['success' => false, 'message' => __('请选择文章分类', 'aksrt')];
}
if (!empty($settings['cover_required']) && empty($data['featured_data']) && empty($data['thumbnail'])) {
return ['success' => false, 'message' => __('请设置封面图', 'aksrt')];
}
}
// Allowed category whitelist.
$allowed = $settings['allowed_cat_ids'] ?? [];
if (!empty($allowed) && !empty($categories)) {
$categories = array_values(array_intersect($categories, $allowed));
if (!$is_draft && empty($categories) && !empty($settings['allow_category'])) {
if (!$is_draft && empty($categories)) {
return ['success' => false, 'message' => __('所选分类不可用', 'aksrt')];
}
}
@@ -126,7 +123,7 @@ trait FrontSubmitSave {
$status = 'draft';
if (!$is_draft) {
$status = $this->resolve_publish_status($user_id, $settings);
$status = $this->resolve_publish_status($user_id);
}
$can_iframe = $this->user_can_cap('new_post_iframe_video', $user_id);
@@ -173,7 +170,7 @@ trait FrontSubmitSave {
}
// Re-apply categories when empty update should clear (logged-in only).
if (!empty($settings['allow_category']) && isset($data['category'])) {
if (isset($data['category'])) {
wp_set_post_categories((int) $in_id, $categories);
}
if (!empty($settings['allow_tags']) && array_key_exists('tags', $data) && $tags_raw === '') {
@@ -233,17 +230,12 @@ trait FrontSubmitSave {
}
/**
* @param array<string, mixed> $settings
* Publish status for a non-draft submission.
*
* Mirrors the reference theme: pending unless the user holds the
* "publish without review" capability.
*/
private function resolve_publish_status(int $user_id, array $settings): string {
$mode = (string) ($settings['review_mode'] ?? 'pending');
if ($mode === 'draft') {
return 'draft';
}
if ($mode === 'publish') {
return 'publish';
}
// pending mode: skip audit when capability grants it.
private function resolve_publish_status(int $user_id): string {
if ($this->user_can_cap('new_post_audit_no', $user_id)) {
return 'publish';
}