Support » Plugin: punBB Latest Topics Widget » [Plugin: punBB Latest Topics Widget] Here is a version that works with wp3.1 and buddypress

  • I just kludged this together. Basically took out the wp database connect stuff and replaced it with standard wpdb calls. Also changed the sql to match the bbpress forum tables. Watch out because I hard coded the bb names to be the default if you let buddypress install the forum. Maybe someone wants to improve this to get these table names from options or wherever they’re stored.


    Plugin Name: bbpress Latest Topics
    Plugin URI:
    Version: v2.0
    Author: Erik Adelson
    Description: A plugin to list the latest topics in your bbpress forum.
    Copyright 2007 Erik Adelson  (email : erik [a t ] erikadelson DOT com)
        This program is free software; you can redistribute it and/or modify
        it under the terms of the GNU General Public License as published by
        the Free Software Foundation; either version 2 of the License, or
        (at your option) any later version.
        This program is distributed in the hope that it will be useful,
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        GNU General Public License for more details.
        You should have received a copy of the GNU General Public License
        along with this program; if not, write to the Free Software
        Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    Modified by Karen Chun to work with bbpress
    if (!class_exists("bbpresslatestPlugin")) {
    	class bbpresslatestPlugin {
    		function bbpresslatestPlugin() { //constructor
    		function init() {
    		function findLatestPosts() {
    			$bbpressltoutput = '';
    			global $wpdb;		
    			$sql = 'SELECT * FROM <code>wp_bb_posts</code> ORDER BY <code>wp_bb_posts</code>.<code>post_time</code> DESC LIMIT  6';
    			$result = $wpdb->get_results($sql );
    			foreach ($result as $p) {
    			    $sql='SELECT * FROM <code>wp_bb_topics</code> WHERE <code>topic_id</code> = '.$p->topic_id;
    				$t= $wpdb->get_row($sql, ARRAY_A, 0);
    				$sql='SELECT * FROM <code>wp_bb_forums</code> WHERE <code>forum_id</code> = '.$p->forum_id;
    				$f= $wpdb->get_row($sql, ARRAY_A, 0);
    				$sql= 'SELECT * FROM <code>wp_users</code> WHERE <code>ID</code> = '.$p->poster_id;
    				$u= $wpdb->get_row($sql, ARRAY_A, 0);
    				$bbpressltoutput .= $user.' posted in<br><a href="/groups/'.$f['forum_slug'].'/forum/topic/'.$t['topic_slug'].'/">'.$topic_name.'</a><br><br>';   
    			//Get options for the widget text
    			$options = get_option('widget_bbpresslt2');
    			$options['text'] = "<br>".$bbpressltoutput;
    			//Update widget text with Forum Latest Topics
    			update_option('widget_bbpresslt2', $options);
    		function getTopic ($postID) {
    			$topics = '';
    			$table = $db_prefix.'topics';
    			$sql2 = 'SELECT <code>poster</code> , <code>subject</code> FROM '.$table.' WHERE <code>last_post_id</code> = '.$postID.' ';
    			$result = $wpdb->get_results($sql2 );
    			foreach ($result as $p) {
    				$topics .= '<a href="/viewtopic.php?pid='.$postID.'">'.$p->subject.'</a><br>Last Post By: '.$p->poster.'<br />'; 
    			return $topics;
    		function db_close($link) {
    } //End Class bbpresslatestPlugin
    if (class_exists("bbpresslatestPlugin")) {
    	$ea_bbpresslatestPlugin = new bbpresslatestPlugin();
    //Initialize the admin panel
    if (!function_exists("bbpresslatestPlugin_ap")) {
    	function bbpresslatestPlugin_ap() {
    		global $ea_bbpresslatestPlugin;
    		if (!isset($ea_bbpresslatestPlugin)) {
    //Actions and Filters	
    if (isset($ea_bbpresslatestPlugin)) {
    	add_action('bbpress_latest_topics.php',  array(&$ea_bbpresslatestPlugin, 'init'));
    function widget_bbpresslt2_init() {
    	// Check to see required Widget API functions are defined...
    	if ( !function_exists('register_sidebar_widget') || !function_exists('register_widget_control') )
    		return; // ...and if not, exit gracefully from the script.
    	// This function prints the sidebar widget--the cool stuff!
    	function widget_bbpresslt2($args) {
    		// $args is an array of strings which help your widget
    		// conform to the active theme: before_widget, before_title,
    		// after_widget, and after_title are the array keys.
    		// Collect our widget's options, or define their defaults.
    		$options = get_option('widget_bbpresslt2');
    		$title = empty($options['title']) ? 'Forum Latest Topics' : $options['title'];
    		$text = empty($options['text']) ? '' : $options['text'];
     		// It's important to use the $before_widget, $before_title,
     		// $after_title and $after_widget variables in your output.
     		echo $before_widget;
    		echo $before_title . $title . $after_title;
    		echo $text;
    		echo $after_widget;
    	function widget_bbpresslt2_control() {
    		// Get widget's options.
    		$options = get_option('widget_bbpresslt2');
    		// handle control form submission.
    		if ( $_POST['bbpresslt-submit'] ) {
    			// Clean up control form submission options
    			$newoptions['title'] = strip_tags(stripslashes($_POST['bbpresslt-title']));
    			$newoptions['text'] = strip_tags(stripslashes($_POST['bbpresslt-text']));
    		// If original widget options do not match control form
    		// submission options, update them.
    		if ( $options != $newoptions ) {
    			$options = $newoptions;
    			update_option('widget_bbpresslt2', $options);
    		// Format options as valid HTML. 
    		$title = htmlspecialchars($options['title'], ENT_QUOTES);
    		$text = htmlspecialchars($options['text'], ENT_QUOTES);
    // The HTML below is the control form for editing options.
    		<label for="bbpresslt-title" style="line-height:35px;display:block;">Title: <input type="text" id="bbpresslt-title" name="bbpresslt-title" value="<?php echo $title; ?>" /></label>
    		<input type="hidden" name="bbpresslt-submit" id="bbpresslt-submit" value="1" />
    	// end of widget_bbpresslt2_control()
    	register_sidebar_widget('bbpress Latest', 'widget_bbpresslt2');
    	register_widget_control('bbpress Latest', 'widget_bbpresslt2_control');
    add_action('plugins_loaded', 'widget_bbpresslt2_init');

    You can see it in action on the front page of

  • The topic ‘[Plugin: punBB Latest Topics Widget] Here is a version that works with wp3.1 and buddypress’ is closed to new replies.