bbp_create_initial_content( array $args = array() )

Create a default forum, topic, and reply


Description Description


Parameters Parameters

$args

(Optional) Array of arguments to override default values

Default value: array()


Top ↑

Source Source

File: includes/core/update.php

function bbp_create_initial_content( $args = array() ) {

	// Cannot use bbp_get_current_user_id() during activation process
	$user_id = get_current_user_id();

	// Parse arguments against default values
	$r = bbp_parse_args( $args, array(
		'forum_author'  => $user_id,
		'forum_parent'  => 0,
		'forum_status'  => 'publish',
		'forum_title'   => esc_html__( 'General',            'bbpress' ),
		'forum_content' => esc_html__( 'General Discussion', 'bbpress' ),

		'topic_author'  => $user_id,
		'topic_title'   => esc_html__( 'Hello World!',                                  'bbpress' ),
		'topic_content' => esc_html__( 'This is the very first topic in these forums.', 'bbpress' ),

		'reply_author'  => $user_id,
		'reply_content' => esc_html__( 'And this is the very first reply.', 'bbpress' ),
	), 'create_initial_content' );

	// Use the same time for each post
	$current_time = time();
	$forum_time   = date( 'Y-m-d H:i:s', $current_time - 60 * 60 * 80 );
	$topic_time   = date( 'Y-m-d H:i:s', $current_time - 60 * 60 * 60 );
	$reply_time   = date( 'Y-m-d H:i:s', $current_time - 60 * 60 * 40 );

	// Create the initial forum
	$forum_id = bbp_insert_forum( array(
		'post_author'  => $r['forum_author'],
		'post_parent'  => $r['forum_parent'],
		'post_status'  => $r['forum_status'],
		'post_title'   => $r['forum_title'],
		'post_content' => $r['forum_content'],
		'post_date'    => $forum_time
	) );

	// Create the initial topic
	$topic_id = bbp_insert_topic(
		array(
			'post_author'  => $r['topic_author'],
			'post_parent'  => $forum_id,
			'post_title'   => $r['topic_title'],
			'post_content' => $r['topic_content'],
			'post_date'    => $topic_time,
		),
		array(
			'forum_id'     => $forum_id
		)
	);

	// Create the initial reply
	$reply_id = bbp_insert_reply(
		array(
			'post_author'  => $r['reply_author'],
			'post_parent'  => $topic_id,
			'post_content' => $r['reply_content'],
			'post_date'    => $reply_time
		),
		array(
			'forum_id'     => $forum_id,
			'topic_id'     => $topic_id
		)
	);

	return array(
		'forum_id' => $forum_id,
		'topic_id' => $topic_id,
		'reply_id' => $reply_id
	);
}

Top ↑

Changelog Changelog

Changelog
Version Description
2.1.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.