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:
+12
-12
@@ -227,29 +227,33 @@ class FrontSubmit {
|
||||
}
|
||||
return [
|
||||
'enabled' => true,
|
||||
'btn_text' => '发布文章',
|
||||
'title_min' => 5,
|
||||
'title_max' => 30,
|
||||
'title_placeholder' => '请输入标题',
|
||||
'content_placeholder' => '请输入内容',
|
||||
'allowed_cat_ids' => [],
|
||||
'default_user_id' => 0,
|
||||
'guest_enabled' => false,
|
||||
'allow_category' => true,
|
||||
'default_user_id' => 1,
|
||||
'allow_tags' => true,
|
||||
'allow_cover' => true,
|
||||
'custom_filter_s' => true,
|
||||
'review_mode' => 'pending',
|
||||
'pay_free_s' => true,
|
||||
'pay_price_min' => 0,
|
||||
'pay_price_max' => 100,
|
||||
'pay_price_max' => 0,
|
||||
'pay_points_min' => 0,
|
||||
'pay_points_max' => 0,
|
||||
'pay_vip_price_s' => true,
|
||||
'pay_vip_1_enabled' => false,
|
||||
'pay_vip_2_enabled' => false,
|
||||
'pay_vip_1_discount' => 80,
|
||||
'pay_vip_2_discount' => 50,
|
||||
'pay_vip_1_discount' => 100,
|
||||
'pay_vip_2_discount' => 100,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the user (or guest) may open / create a submission.
|
||||
*
|
||||
* Guest submission is granted through the capability matrix ("all" column
|
||||
* of new_post_add), mirroring the reference theme.
|
||||
*/
|
||||
public function can_submit(?int $user_id = null): bool {
|
||||
$settings = $this->settings();
|
||||
@@ -261,10 +265,6 @@ class FrontSubmit {
|
||||
$user_id = get_current_user_id();
|
||||
}
|
||||
|
||||
if ($user_id <= 0) {
|
||||
return !empty($settings['guest_enabled']) && (int) ($settings['default_user_id'] ?? 0) > 0;
|
||||
}
|
||||
|
||||
return $this->user_can_cap('new_post_add', $user_id);
|
||||
}
|
||||
|
||||
|
||||
@@ -73,8 +73,8 @@ trait FrontSubmitPay {
|
||||
|
||||
if ($pay_modo === 'points') {
|
||||
$points = $this->parse_front_points($raw['points_price'] ?? $data['points_price'] ?? null);
|
||||
$min = $this->parse_front_points_limit($settings['pay_price_min'] ?? '0.00');
|
||||
$max = $this->parse_front_points_limit($settings['pay_price_max'] ?? '0.00');
|
||||
$min = max(0, (int) ($settings['pay_points_min'] ?? 0));
|
||||
$max = max(0, (int) ($settings['pay_points_max'] ?? 0));
|
||||
if ($points === null) {
|
||||
return ['success' => false, 'message' => __('请设置正确的积分价格', 'aksrt')];
|
||||
}
|
||||
@@ -119,8 +119,10 @@ trait FrontSubmitPay {
|
||||
$meta['vip2_price'] = '0.00';
|
||||
} else {
|
||||
$price_minor = $this->parse_front_cash_minor($raw['price'] ?? null);
|
||||
$min_minor = $this->parse_front_cash_minor($settings['pay_price_min'] ?? '0') ?? 0;
|
||||
$max_minor = $this->parse_front_cash_minor($settings['pay_price_max'] ?? '0') ?? 0;
|
||||
$min_yuan = max(0, (int) ($settings['pay_price_min'] ?? 0));
|
||||
$max_yuan = max(0, (int) ($settings['pay_price_max'] ?? 0));
|
||||
$min_minor = $min_yuan > 0 ? \AKSRT\Ledger\AssetAmount::balance((string) $min_yuan)->minor() : 0;
|
||||
$max_minor = $max_yuan > 0 ? \AKSRT\Ledger\AssetAmount::balance((string) $max_yuan)->minor() : 0;
|
||||
if ($price_minor === null) {
|
||||
return ['success' => false, 'message' => __('请设置正确的价格', 'aksrt')];
|
||||
}
|
||||
@@ -199,13 +201,6 @@ trait FrontSubmitPay {
|
||||
}
|
||||
}
|
||||
|
||||
private function parse_front_points_limit($value): int {
|
||||
if (!is_string($value) || !preg_match('/^(0|[1-9]\d*)(?:\.00)?$/', trim($value), $matches)) {
|
||||
return 0;
|
||||
}
|
||||
return $this->parse_front_points((string) $matches[1]) ?? 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $meta
|
||||
*/
|
||||
|
||||
@@ -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';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user