5 Useful Hacks and Code Snippets for BuddyPress and WPMU

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?

Comments (6)

  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. 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.

  3. 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 :)

Participate