我想在一个地方讨论每个用户。是否可以为每个用户自动分配一个唯一的bbPress线程,并在BuddyPress配置文件中有一个指向该线程的链接?
我目前的尝试是将以下代码添加到functions.php:
function automatic_user_forum( $user_id ) {
if( !$user_id ) return false;
$post = array(
‘post_title’ => ‘My forum’,
‘post_content’ => ‘This is a forum.’,
‘post_name’ => ‘my-forum’,
‘post_status’ => ‘publish’,
‘post_type’ => ‘forum’,
);
$post_id = wp_insert_post($post);
}
add_action( ‘bp_core_activated_user’, ‘automatic_user_forum’ );
然而,它不起作用,网站崩溃。有什么帮助吗?
或者我尝试了以下不崩溃但也没有创建任何论坛。怎么了?
<?php
function bbp_insert_girl_forum() {
$forum_data = array(
'post_parent' => 0, // forum ID
'post_content' => 'Nullam est felis, tempor luctus consequat a, aliquam ut dolor. Proin euismod aliquam ante accumsan cursus. Morbi ornare eros magna, eget sollicitudin turpis fringilla quis. Proin vitae vehicula felis. Fusce non lacus consequat, faucibus nisl sed, consequat dolor.',
'post_title' => 'Test Forum: Loads of Topics for topic Pagination',
);
if(function_exists('bbp_insert_forum')) {
$forum_id = bbp_insert_forum( $forum_data );
}else {
print "insert forum not defined";
}
$topic_data = array(
'post_parent' => $forum_id, // forum ID
'post_content' => 'Proin euismod aliquam ante accumsan cursus. Morbi ornare eros magna, eget sollicitudin turpis fringilla quis. Proin vitae vehicula felis. Fusce non lacus consequat, faucibus nisl sed, consequat dolor.',
'post_title' => 'Gravida facilisis eleifend',
);
if(function_exists('bbp_insert_topic')) {
$topic_id = bbp_insert_topic( $topic_data );
}
else {
print "insert topic not defined";
}
}
add_action( ‘bp_core_activated_user’, ‘bbp_insert_girl_forum’ );
?>
答案 0 :(得分:0)
function bbp_insert_girl_forum() {
$forum_data = array(
'post_parent' => 0, // forum ID
'post_content' => 'Nullam ...',
'post_title' => 'Test Forum',
);
if(function_exists('bbp_insert_forum')) {
$forum_id = bbp_insert_forum( $forum_data );
}
}
add_action( 'bp_core_activated_user', 'bbp_insert_girl_forum' );