Merge pull request 'Fix/forum create topic plate id' (#206) from fix/forum-create-topic-plate-id into main
Reviewed-on: CYL/wordpress-theme-aksrt#206
This commit is contained in:
commit
d48cdac28c
3 files changed
+90
-29
No files matched your search
+15
-14
@@ -171,21 +171,22 @@ class Admin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function register_rest_routes(): void {
|
public function register_rest_routes(): void {
|
||||||
|
// FQCN required after PSR-4 move into AKSRT\Admin (unqualified class_exists skips all routes).
|
||||||
$controllers = [
|
$controllers = [
|
||||||
'GlobalController',
|
GlobalController::class,
|
||||||
'PageDisplayController',
|
PageDisplayController::class,
|
||||||
'PostListController',
|
PostListController::class,
|
||||||
'PermissionsController',
|
PermissionsController::class,
|
||||||
'UserController',
|
UserController::class,
|
||||||
'PaymentController',
|
PaymentController::class,
|
||||||
'ToolsController',
|
ToolsController::class,
|
||||||
'ImportExportController',
|
ImportExportController::class,
|
||||||
'ShopController',
|
ShopController::class,
|
||||||
'ForumController',
|
ForumController::class,
|
||||||
'ExtensionController',
|
ExtensionController::class,
|
||||||
'CommentController',
|
CommentController::class,
|
||||||
'MessageController',
|
MessageController::class,
|
||||||
'AIController',
|
AIController::class,
|
||||||
];
|
];
|
||||||
|
|
||||||
foreach ($controllers as $class_name) {
|
foreach ($controllers as $class_name) {
|
||||||
|
|||||||
@@ -100,9 +100,9 @@ class TopicService {
|
|||||||
// §7.3: Strip unauthorized media from content based on compose capabilities
|
// §7.3: Strip unauthorized media from content based on compose capabilities
|
||||||
$content = $this->sanitize_topic_content($user_id, $content);
|
$content = $this->sanitize_topic_content($user_id, $content);
|
||||||
|
|
||||||
$board = get_term($board_id, 'aksrt_forum_board');
|
$board_ok = $this->assert_board($board_id);
|
||||||
if (!$board || is_wp_error($board)) {
|
if (is_wp_error($board_ok)) {
|
||||||
return new \WP_Error('invalid_board', __('版块不存在', 'aksrt'));
|
return $board_ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($this->get_visibility_map()[$visibility])) {
|
if (!isset($this->get_visibility_map()[$visibility])) {
|
||||||
@@ -125,7 +125,7 @@ class TopicService {
|
|||||||
return $post_id;
|
return $post_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
wp_set_object_terms($post_id, [$board_id], 'aksrt_forum_board');
|
$this->attach_topic_to_board((int) $post_id, $board_id);
|
||||||
|
|
||||||
$clean_tags = array_values(array_filter(array_map('sanitize_text_field', $tags)));
|
$clean_tags = array_values(array_filter(array_map('sanitize_text_field', $tags)));
|
||||||
if (count($clean_tags) > 5) {
|
if (count($clean_tags) > 5) {
|
||||||
@@ -198,12 +198,60 @@ class TopicService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ================================================================
|
// ================================================================
|
||||||
// Topic moderation
|
// Board / plate attachment helpers
|
||||||
// ================================================================
|
// ================================================================
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Moderate topic.
|
* Validate board_id as plate CPT post ID when plate is active, else taxonomy term.
|
||||||
*
|
*
|
||||||
* @return array<string,mixed>|\WP_Error
|
* @return true|\WP_Error
|
||||||
*/
|
*/
|
||||||
|
private function assert_board(int $board_id, string $error_message = '') {
|
||||||
|
if ($error_message === '') {
|
||||||
|
$error_message = __('版块不存在', 'aksrt');
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($board_id <= 0) {
|
||||||
|
return new \WP_Error('invalid_board', $error_message);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->forum->is_plate_cpt_active()) {
|
||||||
|
$post = get_post($board_id);
|
||||||
|
if (!$post || $post->post_type !== 'aksrt_forum_plate' || $post->post_status !== 'publish') {
|
||||||
|
return new \WP_Error('invalid_board', $error_message);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$board = get_term($board_id, 'aksrt_forum_board');
|
||||||
|
if (!$board || is_wp_error($board)) {
|
||||||
|
return new \WP_Error('invalid_board', $error_message);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attach a topic to a board.
|
||||||
|
* Plate CPT active: store `_aksrt_plate_id` only (native association).
|
||||||
|
* Otherwise: taxonomy term on aksrt_forum_board.
|
||||||
|
*/
|
||||||
|
private function attach_topic_to_board(int $topic_id, int $board_id): void {
|
||||||
|
if ($topic_id <= 0 || $board_id <= 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->forum->is_plate_cpt_active()) {
|
||||||
|
update_post_meta($topic_id, '_aksrt_plate_id', $board_id);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (taxonomy_exists('aksrt_forum_board')) {
|
||||||
|
wp_set_object_terms($topic_id, [$board_id], 'aksrt_forum_board');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ================================================================
|
||||||
|
// Topic moderation
|
||||||
|
// ================================================================
|
||||||
}
|
}
|
||||||
@@ -25,17 +25,29 @@ trait TopicServicePart1 {
|
|||||||
switch ($action) {
|
switch ($action) {
|
||||||
case 'move_board':
|
case 'move_board':
|
||||||
$target_board_id = (int) ($payload['target_board_id'] ?? 0);
|
$target_board_id = (int) ($payload['target_board_id'] ?? 0);
|
||||||
$target_board = get_term($target_board_id, 'aksrt_forum_board');
|
$target_ok = $this->assert_board($target_board_id, __('目标版块不存在', 'aksrt'));
|
||||||
if (!$target_board || is_wp_error($target_board)) {
|
if (is_wp_error($target_ok)) {
|
||||||
return new \WP_Error('invalid_board', __('目标版块不存在', 'aksrt'));
|
return $target_ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
$current_board_ids = wp_get_post_terms($topic_id, 'aksrt_forum_board', ['fields' => 'ids']);
|
if ($this->forum->is_plate_cpt_active()) {
|
||||||
wp_set_object_terms($topic_id, [$target_board_id], 'aksrt_forum_board');
|
$previous_plate_id = (int) $this->forum->get_topic_plate_id($topic_id);
|
||||||
foreach ($current_board_ids as $current_board_id) {
|
$this->attach_topic_to_board($topic_id, $target_board_id);
|
||||||
$this->forum->sync_board_count((int) $current_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;
|
break;
|
||||||
|
|
||||||
case 'visibility':
|
case 'visibility':
|
||||||
|
|||||||
Reference in new issue
Block a user