• Aug
    • 28
    • 2012

BBPress 2.0 Analytics Plugin

As promised in this post, I was finally able to upload the BBPress Analytics plugin to

BBPress analytics menu image

WordPress plugin directory, BBPress Analytics plugin, all you have to do is copy it to the wp-content/plugins folder, see that BBPress plugin is enabled and enable the plugin.

To see the analytics of your BBPress forum, go into the BBPress analytics tab on your WordPress dashboard section, there you can find total number of topics, number of replies, replies and topics per day, unanswered topics and posts and topics per user.

Currently there is no configuration page for the plugin and all changes should be done in the code itself on the bbpressAnalytics.php file.

BBPress Analytics page image

Behind the scenes

The code itself is fairly straight forward, you can see there is always a ‘get’ function that gets the data from the DB and a ‘show’ function that visualizes the data into the tables.

BBPress uses the wp-posts table to add it’s posts and replies and the main difference is that those are typed with the respective values. To get all the topics from the DB all that we need to do is run this query: SELECT * FROM wp_posts WHERE post_type = ‘topic’, to get the replies just replace the post_type from ‘topic’ to ‘reply’.

You can see the rest of the queries in the plugin itself and use those.

You can also add new queries by simply taking this code sample and add it to the bbpressAnalytics.php file inside the plugin.

Code sample:

/**
* Your custom query
**/
function getYourQuery()
{
global $wpdb;

//Select 2 values to be shown on the table. (table currentlly supports 2 values)
$qry = “select value1, value2 from wp_posts where addYourLogicHere = ‘true’;”;
$rows = $wpdb->get_results( $qry, ‘ARRAY_A’);

return $rows;
}

/**
/* Shows your query on the 2 columns table.
**/
function showYourQuery(){
bbpressAnalytics::printBeforeTable(“Table Name”, “Value 1″, “Value2″);

$yourQueryResults = bbpressAnalytics::getYourQuery();
$totalTopics = 0;
foreach ($yourQueryResults as $yourQueryResult)
{
$totalTopics++;
$value1 = $topPoster['value1'];
$value2 = $topPoster['value2'];
echo “<tr><td>$value1</td><td class=”n”>’ . $value2 . ‘</td>’;
}
bbpressAnalytics::printAfterTable($totalTopics);
}

Now just add: bbpressAnalytics::showYourQuery(); to the showAnalytics function.

That’s it,

Please comment bellow if you liked the plugin, have questions or issues using it.

About the author  ⁄ Roni Cohen

One Comment

Leave a Comment

Current day month ye@r *