bp_dd_create_forums( $forum, array $users = array() )

Create forums

Description

Parameters

$forum

(Required)

$users

(Optional)

Default value: array()

Return

(bool|int|WP_Error)

Source

File: bp-core/bp-core-tools-default-data.php

function bp_dd_create_forums( $forum, $users = array() ) {
	if ( empty( $users ) ) {
		$users = bp_dd_get_random_users_ids( 0 );
	}

	$creator_id = is_object( $users[ array_rand( $users ) ] ) ? $users[ array_rand( $users ) ]->ID : $users[ array_rand( $users ) ];

	$args = array(
		'post_title'   => $forum['name'],
		'post_content' => $forum['description'],
		'post_status'  => $forum['visibility'],
		'post_author'  => $creator_id,
	);

	$forum_id = bbp_insert_forum( $args );

	if ( ! empty( $forum_id ) && isset( $forum['status'] ) ) {
		update_post_meta( $forum_id, '_bbp_status', $forum['status'] );
	}

	return $forum_id;
}

Changelog

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.