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

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!