bbp_move_topic_handler (inttopic_id美元,intold_forum_id美元,intnew_forum_id美元)
处理一个主题从一个论坛转移到另一个论坛。这包括遍历旧的和新的分支并更新计数。
描述
参数
- topic_id美元
-
(int)(必需)主题id
- old_forum_id美元
-
(int)(必需)老论坛id
- new_forum_id美元
-
(int)(必需)新论坛id
源
function bbp_move_topic_handler($topic_id, $old_forum_id, $new_forum_id){//验证参数$topic_id = bbp_get_topic_id($topic_id);$old_forum_id = bbp_get_forum_id($old_forum_id);$new_forum_id = bbp_get_forum_id($new_forum_id);//更新主题论坛的ID bbp_update_topic_forum_id($topic_id, $new_forum_id);/ * *便条纸 **************************************************************/ // 获得论坛便条纸old_stickies = bbp_get_stickies美元($ old_forum_id);$updated_stickies = array(); //定义本地变量$updated_stickies = array();foreach ((array) $old_stickies as $sticky_topic_id) {if ($topic_id !== $sticky_topic_id) {$updated_stickies[] = $sticky_topic_id; $updated_stickies[] = $sticky_topic_id;$updated_stickies !== $old_stickies){//没有更多的stickies所以删除meta If (empty($updated_stickies)) {delete_post_meta($old_forum_id, ' _bbp_stick_topics ');} else {update_post_meta($old_forum_id, '_bbp_sticky_topics', $updated_stickies);bbp_stick_topic($topic_id); //主题是粘性的,所以在新论坛中保持粘性 } } /** Topic Replies *********************************************************/ // Get the topics replies $replies = bbp_get_all_child_ids( $topic_id, bbp_get_reply_post_type() ); // Update the forum_id of all replies in the topic foreach ( $replies as $reply_id ) { bbp_update_reply_forum_id( $reply_id, $new_forum_id ); } /** Old forum_id **********************************************************/ // Get topic ancestors $old_forum_ancestors = array_values( array_unique( array_merge( array( $old_forum_id ), (array) get_post_ancestors( $old_forum_id ) ) ) ); // Loop through ancestors and update them if ( !empty( $old_forum_ancestors ) ) { foreach ( $old_forum_ancestors as $ancestor ) { if ( bbp_is_forum( $ancestor ) ) { bbp_update_forum( array( 'forum_id' => $ancestor, ) ); } } } /** New forum_id **********************************************************/ // Make sure we're not walking twice if ( !in_array( $new_forum_id, $old_forum_ancestors ) ) { // Get topic ancestors $new_forum_ancestors = array_values( array_unique( array_merge( array( $new_forum_id ), (array) get_post_ancestors( $new_forum_id ) ) ) ); // Make sure we're not walking twice $new_forum_ancestors = array_diff( $new_forum_ancestors, $old_forum_ancestors ); // Loop through ancestors and update them if ( !empty( $new_forum_ancestors ) ) { foreach ( $new_forum_ancestors as $ancestor ) { if ( bbp_is_forum( $ancestor ) ) { bbp_update_forum( array( 'forum_id' => $ancestor, ) ); } } } } }