5 Useful Hacks and Code Snippets for BuddyPress and WPMU

November 4, 2009  | 
6 Comments

Hacks- we all need them from time to time. A hack is a way to unleash the power of your WordPress core until such time as your enhancement is added into a new release. What’s the difference between a hack and a plugin you might ask? Not a lot. Plugins make it easier to upgrade your installation without losing your “hacks.” There is a warning in the WordPress codex: “Hacks are not officially supported by WordPress. Use at your own risk. “ In ancient items before WordPress 1.5, hacks were the only way to modify WordPress. Hacks have a bad connotation but there’s nothing wrong with using them to solve an issue that is preventing your install from working the way you want it to. Here are some of our favorites:

Show List of Recently Created Blogs:

Include this snippet in your functions.php file:

<?php
/*Fetch an array of $number_blogs most recently created blogs
**@number_blogs :The number of most recently created blogs you want to show.
*/
function get_recent_blogs($number_blogs=5)
{
  global $wpdb;
  $blog_table=$wpdb->blogs;
/*fetch blog_id,domain,path from wp_blogs table ,where the blog is not spam,deleted or archived order by the date and time of registration */
  $query="select blog_id,domain,path from $blog_table where public='1' and archived='0' and spam='0' and deleted='0' order by registered desc limit 0,$number_blogs";
 
  $recent_blogs=$wpdb->get_results($wpdb->prepare($query));
 
return $recent_blogs;
 
 }
?>

Then you can get its output with the following:

<ul class="recent-blogs">
<?php $recent_blogs=get_recent_blogs(5);
	foreach($recent_blogs as $recent_blog):
		$blog_url="";
		if( defined( "VHOST" ) && constant( "VHOST" ) == 'yes' )
			$blog_url="http://".$recent_blog->domain.$recent_blog->path;
		else
		$blog_url="http://".$recent_blog->domain.$recent_blog->path;
	$blog_name=get_blog_option($recent_blog->blog_id,"blogname");
	?>
<li>
<h3><a href="<?php echo $blog_url;?>"> </a></h3>
<span><?php echo $blog_name?></span>
</li>
<?php endforeach;?>
</ul>

newblogs

Or grab the plugin here. These snippets are courtesy of thinkinginwordpress.com

Hide Selected Profile Feeds:

This hack will hide feeds of profiles that you select in phpmyadmin. It might be helpful if you want to hide the admin user’s actions or some behind-the-scenes moderators, or perhaps a particularly irritating user. ;)

First locate the file:
/bp-themes/buddypress-member/profile/profile-loop.php

Then find this:

<?php if ( bp_field_has_data()) : ?>

Change it to read:

<?php if ( bp_field_has_data() && bp_field_has_public_data()) : ?>

Use phpmyadmin and go into the table bp_xprofile_fields and change all the profile field records that are parent fields and have ’0′ in the column ‘is_public’ to ’1′ for the fields you want to show on the profile and ’0′ for the fields you don’t want to show. Parent fields are the ones that have a ’0′ in the ‘parent_id’ column.
Credits: BuddyPress Forum.

Hide Default BuddyPress Menu:

menubar

This is a quick one. BuddyPress gives you options for hiding its menu if the user is not logged in. This little addition to your wpconfig.php file will hide your menu bar, whether the user is logged in or logged out:
define( ‘BP_DISABLE_ADMIN_BAR’, true );

Replace Who’s Online with Recently Active Widget:

membersWhen you’ve got a site with a smaller membership, the “Who’s Online” widget can make your site look a little bit naked. With this quick hack you can make sure that member avatars are there all the time. They will change dynamically based on the users’ recent activity. (It is coupled with the widget below.)

Exploded Groups:

This widget removes the ajax “popular|active|newest” links for the group widget and simply shows three different group displays, one for each: popular, active and newest. Ajax is like candy to me, so I would be hard-pressed to find an instance where this is needed. ;) However, if you want to bring more prominence to these displays, this might be your ticket.

These widgets were developed by the folks over at iqcuties.com. Download these widgets and then replace these files with the ones you downloaded:

bp-core/bp-core-widgets.php
bp-groups/bp-groups-widgets.php

Remember that these are hacks, so they will get overwritten when you upgrade. You’ll need to make a list of your hacks if you want to keep that functionality after upgrading. Do you have a favorite hack you’d like to share?

Featured Plugin - Turn any WordPress page into a fully featured wiki!

To get a wiki up and running you used to need to install Mediawiki and toil away for days configuring it... not any more! This plugin gives you *all* the functionality you want from a wiki, in WordPress!!!
Find out more

Featured Plugin - Host sites, get paid, just like WordPress.com

If you've ever wondered how you could offer a paid site management and hosting service, then this is the plugin for you. Offer a freemium or paid service, for any niche you like, it's powered Edublogs.org to success already!
Find out more

Featured Plugin - Add bottom corner (or anywhere else) chat to your site

No javascript required, no third part chat engine, just fully featured chat right in your own database on your own WP sites - couldn't be easier.
Find out more

Featured Plugin - Easily integrate your WordPress site with Facebook

Would you like to add Facebook comments, registration, 'Like' buttons and autoposting to your WP site? Well, The Ultimate Facebook plugin has got that all covered!
Find out more

Featured Plugin - Start Your Own Powerful Membership Site

If you're thinking about starting a paid, or just private, membership site then this is truly the plugin you've been looking for. Easy to use, massively configurable and ready to go out of the box!
Find out more

Featured Plugin - Open an Online Store with MarketPress

Out of all the WordPress ecommerce plugins available, this has got to be the winner - easy to configure, powerful functionality, multiple gateways and more. A simply brilliant plugin!
Find out more

Featured Plugin - Start your own Quora / StackOverflow / Yahoo Q&A site

It's now incredibly easy to start your own Q&A site using nothing more than WordPress - The Q&A plugin simply and brilliantly transforms any site, or page, into a perfect support or Q&A environment.
Find out more

Featured Plugin - WordPress + Google Maps = Perfect

Simply insert google maps into posts, sidebars and pages - show directions, streetview, provide image overlays and do it all from a simple button and comprehensive widget.
Find out more

Featured Plugin - Send beautiful html email newsletters, from WordPress!

Now there's no need to pay for a third party service to sign up, manage and send beautiful email newsletters to your subscriber base - this plugin has got the lot.
Find out more

6 Responses to 5 Useful Hacks and Code Snippets for BuddyPress and WPMU

  1. Hello, How can I display featured members of websites? i tried using Author avatar list but I was not able to use buddypress functions over there.. I need to display xproflie fields. If you have any suggestions please share with me…
    Thank you

  2. Hmm, I just downloaded/installed the 2 replacement widgets and they triggered a fatal error. WPMU 2.8.5.2 and BP 1.1.2. I liked the idea of the post, maybe it’s a compatibility issue?

  3. It’s probably a compatibility issue- what was the error it returned?

  4. It installed and activated normally, but after adding the widgets to the front page the page wouldn’t load stating that bp-core-widgets.php triggered a fatal error. I didn’t take note exactly which line in the code since I quickly reinstalled the original widgets on my live community.

  5. I love these hacks, especially that of Recently Active Members. The only problem I am having is getting the icons to be lined in as tiles (multiple columns instead of just one long column running down.

    Thanks for any help :)

Click on a tab to select how you'd like to leave your comment

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Subscribe without commenting