Hack: bb replies as wp comments; using bb API?
-
Wanting to integrate bb and wp more, I hacked up wp’s
comments.phptemplate to get replies in the forum to show up below posts in the wp section of the site too.This currently requires the bbPress Post plugin.
Fairly simple job: find the corresponding topic, get the replies, and output them. My solution should work for you, too, if you have bbPress post installed and activated as a wp plugin. Code’s below.
I want to make it possible to reply to the topic from the wp section of the site if you’re logged in. Obviously I could make queries to insert the post into the database, but I’d like to use the bb API so it can be validated correctly, hooks are called etc. Not sure how I would go about making it accessible. Currently calling any bb functions returns the “undefined function” error; how can I make them available for use?
Paste this in front of the rest of your wp
comments.phptemplate:<?php
function felblogtotopicid( $felpostID ) {
global $table_prefix, $wpdb;
$posts_table = $table_prefix . "bbpress_post_posts";
$topic_id = $wpdb->get_var("SELECT topic_id FROM <code.>$posts_table</.code> WHERE <.code>post_id</.code> = $felpostID LIMIT 1;");
return $topic_id;
}
global $post, $wpdb;
if( $forumtopic = felblogtotopicid( $post->ID ) ) {
$bbprefix = get_option( 'wpbb_bbprefix' );
$replies = $wpdb->get_results( '
SELECT poster_id, post_text, post_time
FROM ' . $bbprefix . 'posts
WHERE topic_id = ' . $forumtopic
);
array_shift( $replies ); //takes off first entry, ie. starting post, and moves the rest back one
//$replies = array of object( poster_id, post_text, post_time ) for each post I think
echo "<ol>n"; //start of list
foreach( $replies as $reply ) {
$poster = get_userdata( $reply->poster_id );
$poster = $poster->user_login;
echo '<li class="thread">' . "n"
. '<div class="reply">' . "n"
. '<div class="poster">' . "n"
. "<strong>" . $poster . "</strong>n"
. "<span> @ " . $reply->post_time . "</span>n"
. "</div>n"
. '<div class="post">' . "n"
. $reply->post_text
. "</div>n"
. "</div>n"
. "</li>n";
}
echo "</ol>n"; //end of list
//$replylink = bb_add_replies_to_topic_link( $forumtopic );
$replylink = get_option( 'wpbb_path' );
echo '<h3><a href="' . $replylink . '">Reply!</a></h3>' . "n";
} else { ?>and paste this at the very back:
<?php } //end else conditional for corresponding topic to blogpost ?>Example here
You must be logged in to reply to this topic.
xampphtdocsforumsbb-includesfunctions.php on line 1224