fix(forum): accept plate CPT IDs when creating topics
Compose UI and board search already send aksrt_forum_plate post IDs as board_id, but create_topic still validated aksrt_forum_board term IDs and never wrote _aksrt_plate_id — so real plates failed with 版块不存在. Validate/store under the plate model (and fix move_board the same way).
This commit is contained in:
@@ -25,17 +25,29 @@ trait TopicServicePart1 {
|
||||
switch ($action) {
|
||||
case 'move_board':
|
||||
$target_board_id = (int) ($payload['target_board_id'] ?? 0);
|
||||
$target_board = get_term($target_board_id, 'aksrt_forum_board');
|
||||
if (!$target_board || is_wp_error($target_board)) {
|
||||
return new \WP_Error('invalid_board', __('目标版块不存在', 'aksrt'));
|
||||
$target_ok = $this->assert_board($target_board_id, __('目标版块不存在', 'aksrt'));
|
||||
if (is_wp_error($target_ok)) {
|
||||
return $target_ok;
|
||||
}
|
||||
|
||||
$current_board_ids = wp_get_post_terms($topic_id, 'aksrt_forum_board', ['fields' => 'ids']);
|
||||
wp_set_object_terms($topic_id, [$target_board_id], 'aksrt_forum_board');
|
||||
foreach ($current_board_ids as $current_board_id) {
|
||||
$this->forum->sync_board_count((int) $current_board_id);
|
||||
if ($this->forum->is_plate_cpt_active()) {
|
||||
$previous_plate_id = (int) $this->forum->get_topic_plate_id($topic_id);
|
||||
$this->attach_topic_to_board($topic_id, $target_board_id);
|
||||
if ($previous_plate_id > 0 && $previous_plate_id !== $target_board_id) {
|
||||
$this->forum->sync_board_count($previous_plate_id);
|
||||
}
|
||||
$this->forum->sync_board_count($target_board_id);
|
||||
} else {
|
||||
$current_board_ids = wp_get_post_terms($topic_id, 'aksrt_forum_board', ['fields' => 'ids']);
|
||||
if (is_wp_error($current_board_ids)) {
|
||||
$current_board_ids = [];
|
||||
}
|
||||
$this->attach_topic_to_board($topic_id, $target_board_id);
|
||||
foreach ($current_board_ids as $current_board_id) {
|
||||
$this->forum->sync_board_count((int) $current_board_id);
|
||||
}
|
||||
$this->forum->sync_board_count($target_board_id);
|
||||
}
|
||||
$this->forum->sync_board_count($target_board_id);
|
||||
break;
|
||||
|
||||
case 'visibility':
|
||||
|
||||
Reference in New Issue
Block a user