bp_dd_import_forums_in_groups()
Import Forums in Groups
Description
Source
File: bp-core/bp-core-tools-default-data.php
function bp_dd_import_forums_in_groups() { $topics = array(); $replies = array(); $forum_ids = array(); $topics_ids = array(); $reply_ids = array(); $groups_ids = array(); if ( ! bp_is_active( 'forums' ) || ! bp_is_active( 'groups' ) ) { return $groups_ids; } $users = bp_dd_get_random_users_ids( 0 ); $groups_ids = bp_dd_get_forums_enable_groups_ids( 8 ); foreach ( $groups_ids as $groups_id ) { // Get the group $group = groups_get_group( $groups_id ); if ( ! empty( $group ) ) { $forum['name'] = $group->name; $forum['description'] = sprintf( __( 'Default Forum for %s Group', 'buddyboss' ), $group->name ); $forum['visibility'] = 'publish'; $forum['status'] = 'open'; $forum_id = bp_dd_create_forums( $forum, $users ); if ( $forum_id ) { bbp_add_forum_id_to_group( $groups_id, $forum_id ); bbp_add_group_id_to_forum( $forum_id, $groups_id ); $forum_ids[] = $forum_id; // Set forum enabled status $group->enable_forum = 1; // Save the group $group->save(); } } bp_update_option( 'bp_dd_imported_forum_ids', array_merge( $forum_ids, bp_get_option( 'bp_dd_imported_forum_ids', array() ) ) ); } require( BP_DEFAULT_DATA_DIR . 'data/forums_topics.php' ); foreach ( $forum_ids as $forum_id ) { $topic = (array) array_rand( $topics, absint( rand( 2, count( $topics ) ) ) ); foreach ( $topic as $topic_key ) { $topic_data = $topics[ $topic_key ]; // Create the initial topic $topic_id = bp_dd_create_forums_topics( $topic_data, $forum_id, $users ); if ( ! empty( $topic_id ) ) { $topics_ids[] = $topic_id; } } } bp_update_option( 'bp_dd_imported_topic_ids', array_merge( $topics_ids, bp_get_option( 'bp_dd_imported_topic_ids', array() ) ) ); require( BP_DEFAULT_DATA_DIR . 'data/forums_replies.php' ); foreach ( $topics_ids as $topic_id ) { $reply = (array) array_rand( $replies, absint( rand( 1, 7 ) ) ); foreach ( $reply as $reply_key ) { $reply_data = $replies[ $reply_key ]; $reply_id = bp_dd_create_forums_topics_replies( $reply_data, $topic_id, $users ); if ( ! empty( $reply_id ) ) { $reply_ids[] = $reply_id; } } } bp_update_option( 'bp_dd_imported_reply_ids', array_merge( $reply_ids, bp_get_option( 'bp_dd_imported_reply_ids', array() ) ) ); return $groups_ids; }
Changelog
Version | Description |
---|---|
BuddyBoss 1.0.0 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.