that only looked like one request !! ??
function rew_add_private_group ($user_id) {
/*** FIRST ADD A NEW GROUP ***/
//get user and set up username
$user = get_userdata($user_id) ;
$username = $user->user_login;
$fullname = $user->first_name.$user->last_name;
//count the number of current user groups and increment by 1
$options = get_option('rpg_groups');
$count=count ($options)+1 ;
//set the group up and called it the $fullname
$options['group'.$count] = $fullname;
//Update the database
update_option('rpg_groups', $options);
/*** THEN CREATE A NEW FORUM ***/
$forum_data = apply_filters( 'rew_new_forum_pre_insert', array(
'post_author' => $username,
'post_title' => $username.'\'s Journal',
'post_content' => '',
'post_parent' => '',
'post_status' => bbp_get_private_status_id(),
'post_type' => bbp_get_forum_post_type(),
'comment_status' => 'closed'
) );
// Insert forum
$forum_id = wp_insert_post( $forum_data, true );
//and add meta data
update_post_meta ($forum_id , '_bbp_forum_id' , 0 ) ;
update_post_meta ($forum_id , '_bbp_last_topic_id' , 0 ) ;
update_post_meta ($forum_id , '_bbp_last_reply_id' , 0 ) ;
update_post_meta ($forum_id , '_bbp_last_active_id' , 0 ) ;
update_post_meta ($forum_id , '_bbp_last_active_time' , 0 ) ;
update_post_meta ($forum_id , '_bbp_forum_subforum_count' , 0 ) ;
update_post_meta ($forum_id , '_bbp_reply_count' , 0 ) ;
update_post_meta ($forum_id , '_bbp_total_reply_count' , 0 ) ;
update_post_meta ($forum_id , '_bbp_total_reply_count' , 0 ) ;
update_post_meta ($forum_id , '_bbp_topic_count' , 0 ) ;
update_post_meta ($forum_id , '_bbp_topic_count_hidden' , 0 ) ;
update_post_meta ($forum_id , '_bbp_reply_count_hidden' , 0 ) ;
update_post_meta ($forum_id , '_bbp_status' , 'open' ) ;
update_post_meta ($forum_id , '_bbp_forum_type' , 'forum' ) ;
/*** THEN SET THIS FORUM TO JUST HAVE THIS GROUP ***/
update_post_meta ($forum_id , '_private_group' , 'group'.$count) ;
/*** AND FINALLY SET THE USER TO BE IN THIS GROUP ***/
update_user_meta( $user_id, 'private_group', '*group'.$count.'*');
return $count ;
}
so you would call this like this
$group_number = rew_add_private_group ($user_id);
this just returns a number if you want the group, then change the return line to
return 'group'.$count ;