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 Import PodPress Audio URLs

I ran into a real bugger of a problem tonight when attempting to import a WordPress site using the Importer plugin. The problem arose, because the importer does not get all of the data out of the “wp_postmeta” table. In fact, it misses or messes up the audio urls that PodPress uses.

The solution I found was the following:

  1. MAKE A BACKUP OF BOTH YOUR OLD SITE’S AND NEW SITE’S DATABASES!!! (Following the steps below can seriously and permanently mess up your site. Call a WordPress pro if this message scares you. Seriously.)
  2. Go into the old site’s phpMyAdmin and export the “wp_postmeta” and “wp_posts” tables.
  3. Go into the new site’s phpMyAdmin and import the “wp_postmeta” and “wp_posts” tables that you just saved in step 1 above. (Note: If your target installation uses the same “wp_” prefix, then you will need to change the title of the tables before importing them.)
  4. In the new site’s phpMyAdmin, run the following query:

    REPLACE
    INTO wp_posts
    SELECT *
    FROM wp_ww_posts
    ;

  5. That did it for me. How about you?

    (Thanks, FCW and NTM!)

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 Force WordPress Multi-Site to Use Subdirectories Instead of Subdomains

I was trying to run WordPress multi-site from a subdomain today and ran into an issue where WordPress wants to force me to use subdomains for my url structure.  So, my sites would look like “site1.subdomain.maindomain.com” rather than my preference of “subdomain.maindomain.com/site1″.

To fix this, I implimented the fix found here.

Specifically, in wp-config.php I needed to change

define( 'SUBDOMAIN_INSTALL', true );

to

define( 'SUBDOMAIN_INSTALL', false );

and replace my .htaccess file’s content with the following:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
 
# uploaded files
RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) wp-includes/ms-files.php?file=$2 [L]
 
# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
 
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule  ^[_0-9a-zA-Z-]+/(wp-(content|admin|includes).*) $1 [L]
RewriteRule  ^[_0-9a-zA-Z-]+/(.*\.php)$ $1 [L]
RewriteRule . index.php [L]
</IfModule>
# END WordPress

Pretty nifty!

p.s. You might need to update your permalinks after making the changes above.