WordPress Designers and Developers in Minneapolis, MN

How to Add, Remove, and Change the Order Of BuddyPress Component Menu

Today I needed to change three things in a BuddyPress installation:

  1. Change the title of “Groups” to “My Conversations” in the BuddyPress component menu.
  2. Remove the “Forums” menu item from the BuddyPress component menu.
  3. Change the order of the BuddyPress component menu such that the “Messages” link is in a different place.

To accomplish these three things, I added the following to my theme’s functions.php file:

 
// Setup the navigation
// Props to http://wordpress.stackexchange.com/questions/16223/add-buddypress-profile-menu-item for helping me figure this out
// http://themekraft.com/customize-profile-and-group-menus-in-buddypress/
function my_setup_nav() {
      global $bp;
 
      // Change the order of menu items
      $bp->bp_nav['messages']['position'] = 100;
 
      // Remove a menu item
      $bp->bp_nav['conversations'] = false;
 
      // Change name of menu item
      $bp->bp_nav['communities']['name'] = 'My Conversations';
}
 
add_action( 'bp_setup_nav', 'my_setup_nav', 1000 );

Pretty nifty, eh?

By the way, if you want to see all of your options for editing the components menu, just throw the following into functions.php:

 
function bp_dump() {
    global $bp;
 
    foreach ( (array)$bp as $key => $value ) {
        echo '<div>';
        echo '<strong>' . $key . ': </strong><br />;';
        print_r( $value );
        echo '</div>';
    }
    die;
}

(Thanks ThemeKraft!)

How to Add a New Menu Item to the BuddyPress Component Menu

Today I needed to add a new menu item to the BuddyPress components menu (the menu under the profile with “Settings”, “Groups”, “Forums”, “Profile”, etc.).

In my example below, the menu item will be called, “My Conversations”, and it will link to the “Groups” template.

<?php
// Setup the navigation
// Props to http://wordpress.stackexchange.com/questions/16223/add-buddypress-profile-menu-item for helping me figure this out
// and http://themekraft.com/customize-profile-and-group-menus-in-buddypress/
function my_setup_nav() {
      global $bp;
 
      bp_core_new_nav_item( array( 
            'name' => __( 'My Conversations', 'buddypress' ), 
            'slug' => 'my-all-conversations', 
            'position' => 75,
            'screen_function' => 'my_all_conversations_link',
	    'show_for_displayed_user' => true,
	    'default_subnav_slug' => 'my-all-conversations',
	    'item_css_id' => 'my-all-conversations'
      ) );
}
 
add_action( 'bp_setup_nav', 'my_setup_nav', 1000 );
 
function my_all_conversations_title() {
	echo 'My Conversations';
}
 
function my_all_conversations_content() {
	?>
	<div id="groups-dir-list" class="groups dir-list">
		<?php locate_template( array( 'groups/groups-loop.php' ), true ) ?>
	</div><!-- #groups-dir-list -->
    <?php
}
 
function my_all_conversations_link () {
	add_action( 'bp_template_title', 'my_all_conversations_title' );
	add_action( 'bp_template_content', 'my_all_conversations_content' );
	bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
}
 
?>

That’s it! Enjoy!

How to Add a Special Class to Every BuddyPress Page

Sometimes I need to style everything that BuddyPress creates differently than regular WordPress stuff. For example, I might need to style all groups, forums, profile pages, etc. a certain way and have different styling for blogs and WordPress multi-site home pages.

My solution is to tap into the body_class() function and add a special class called, “buddypress” to all BuddyPress pages. Just add the following to your theme’s functions.php file:

// Add "buddypress" to body_class function if we are on a BuddyPress-generated page
add_filter('body_class','add_buddypress_body_classes');
function add_buddypress_body_classes($classes, $class) {
    if (!bp_is_blog_page()) :
 
        // add 'my-class' to the $classes array
	$classes[] = 'buddypress';
	// return the $classes array
	return $classes;
 
    endif;
}

Or if you need to target specific BuddyPress components, you can do it this way:

// Add "buddypress" to body_class function if we are on a BuddyPress-generated page
add_filter('body_class','add_buddypress_body_classes');
function add_buddypress_body_classes($classes, $class) {
 
	if ( 
	bp_is_profile_component() ||
	bp_is_activity_component() ||
	bp_is_blogs_component() ||
	bp_is_messages_component() ||
	bp_is_friends_component() ||
	bp_is_groups_component() ||
	bp_is_settings_component() ) : 
 
	// add 'my-class' to the $classes array
	$classes[] = 'buddypress';
	// return the $classes array
	return $classes;
 
	endif;
 
}

Hooray!

(Thanks to this thread for making me aware of the bp_is_blog_page function.)

How to Zip a Folder Using Terminal or Command Line

I have been having fun with the command line the last couple of days.  Being a command line noob, I am starting to see why all my geeky friends love working in it.  I used to play around with BASIC back in the day, and the command line has a certain nostalgia about it in addition to being powerfully efficient in many ways.  On to the fun…

I have a rather large BuddyPress + WordPress Multi-site installation that BackupBuddy has been choking on.  All of my uploads total around 600MB, which is more than my server can zip up in one sitting.

So, I decided to try out the command line’s zip functionality, and it worked swimmingly!  Below are the steps I took to zip up my blogs.dir directory (the folder that has all my uploads in it).

Step 1: SSH into your website root via Terminal (on Mac) or your command line tool of choice.

Step 2: Navigate to the parent folder of the folder that you want to zip up using the “cd” command.

Step 3: Use the following command:   zip -r mynewfilename.zip foldertozip/   or   tar -pvczf BackUpDirectory.tar.gz /path/to/directory  for gzip compression
In my case, I typed zip -r blogs.dir.zip blogs.dir/ 

That’s it!

 

How to Update php.ini Via Terminal (Command Line)

Today I needed to increase the file upload limit in a WordPress multi-site + BuddyPress installation.  The limit was set by php.ini on the server, so there was no way to increase the limit within WordPress.

The solution is a bit complex if you are a command line noob like me, and it does require a basic understanding of command line stuff as well as root access to your server.  That said, with some guidance from someone like Dave, you can be rolling on the command line in no time!

Step 1: SSH into your website root via Terminal (on Mac) or your command line tool of choice.

Step 2: Find your php.ini file by typing something like this - grep -i php.ini

Step 3: Make sure you are in the same directory as your php.ini file and then edit your php.ini file by typing nano php.ini

Step 4: Edit the upload_max_filesize, post_max_size, and memory_limit properties in your php.ini file

Step 5: Save php.ini by exiting Nano

Step 6: Restart Apache by typing the following into Terminal:  /etc/init.d/httpd restart

 

That’s it!

Many thanks to Dave for his help!