WordPress Designers and Developers in Minneapolis, MN

bp-custom.php vs. functions.php

Up until today I did not know the difference between bp-custom.php and functions.php within a BuddyPress installation. It turns out that bp-custom.php is basically a functions file that is theme-independent. What that means is that if you have a function that you want to run irrespective of whatever theme is active, you put it in bp-functions.php.

Pretty nifty!

iPad and iPhone Adding Extra CSS Margin to Right Side of Window

<rant>I feel like I am starting from scratch every time I load a website I am building on the iPhone or iPad. Standards or no, there are some funky things that happen on those devices.</rant>

Most recently, I have been wrestling with the fact that the iPad and iPhone seem to randomly add margins to the right of my content. After all sorts of late nights and code hacking, I finally discovered that I can define the width of the browser (as viewed by iPad and iPhone). Just add something like the following to the head of your html document (or WordPress theme):

<meta name="viewport" content="width=1000px">

Onward and upward…hopefully…

CSS Body Class for BuddyPress Group Moderators and Admins

I tend to use CSS to hide all sorts of things within the BuddyPress interface rather than unhooking functions. I find that it more quickly and flexibly accommodates my clients’ changing desires.

Today I needed to add a css body class for group moderators and admins. The goal was to hide the “Admin” button for moderators but display it for admins.

To pull it off, I added the following to my functions.php file:

// Add "bp-group-moderator" to body_class function if we are on a BuddyPress-generated page
add_filter('body_class','add_bp_group_moderator_body_classes');
function add_bp_group_moderator_body_classes($classes) {
 
	if ( bp_group_is_mod() ):
 
	// add 'bp-group-moderator' to the $classes array
	$classes[] = 'bp-group-moderator';
	// return the $classes array
	return $classes;
 
	else :
 
		// do nothing
		$classes[] = '';
		// return the $classes array
		return $classes;
 
	endif;
 
}
 
// Add "bp-group-admin" to body_class function if we are on a BuddyPress-generated page
add_filter('body_class','add_bp_group_admin_body_classes');
function add_bp_group_admin_body_classes($classes) {
 
	if ( bp_group_is_admin() ):
 
	// add 'bp-group-admin' to the $classes array
	$classes[] = 'bp-group-admin';
	// return the $classes array
	return $classes;
 
	else :
 
		// do nothing
		$classes[] = '';
		// return the $classes array
		return $classes;
 
	endif;
 
}

It works nicely!

I plan to release it as a plugin. Perhaps some day this will be in core. In general, I can never have too many body classes. :)

More BuddyPress Conditional Tags

Today I needed to create a BuddyPress conditional statement but none of the “normal” conditional tags suited my needs. Specifically, I needed to determine whether or not a user was a group moderator or admin role. The boolean that helps determine that can be found on the BuddyPress Function Reference page.

There is lots of neat stuff there.

Also on a somewhat related note, check out this list of BuddyPress global variables. You never know when you might need to display a BuddyPress user’s info within a conditional! :)