Seamless WordPress bbPress Integration

If you’ve ever installed bbPress you know that it supports several different levels of integration with an existing WordPress blog. By default you can integrate cookies, users, and even have access to WordPress functions. After all of this, however, the user will still experience two independent applications. Most likely the themes you are using were not made with each other in mind. This doesn’t have to be the case, and if you’re willing to get your hands dirty you can get your bbPress installation to look and feel as if it is entirely a part of WordPress. Here is an example of what this looks like: Example.

To begin, you will need to install (or modify) bbPress with full WordPress integration. This means cookie, database, and functional integration (add require_once(‘path/to/wp-blog-header.php’); to your bb-config.php for functional integration). I did this with WordPress 2.7.1 and bbPress 1.0 alpha, however, if you prefer to use the stable version of bbPress, you can find information on how to do this Here.

Once everything is installed its time to get your hands dirty. To go further we’re going to have to make a few changes to the code. Locate your theme directory. I used the default Kakumei theme. Keep in mind that a large portion of your bbPress theme is going to be stripped out (header, footer, sidebar) so don’t spend to much time selecting a theme. After you locate the directory of your current theme, you’ll need to do a search and replace through every .php file in your theme. There are several files so I suggest you use a program to do this for you; Notepad++ allows you to search and replace across multiple files.

You’ll need to do two searches:

Find:

bb_get_header();

Replace with:

global $is_bb; $is_bb = true; get_header();

get_header(); will cause bbPress to use WordPress’ header as opposed to its own. I added the additional code global $is_bb; $is_bb = true; you’ll see why later. You’ll need to do the same thing for the footer as well.

Find:

bb_get_footer();

Replace with:

get_footer();

Now that that’s done, upload the files and take a look at your forum. You should see the body of your forum embedded inside your wordpress theme. You should also notice that your forum looks pretty terrible. Don’t worry we’ll fix this in the next step.

What we need to do next is tell your wordpress theme to use your bbPress stylesheet if we are viewing the forum. This is where that additional code I added comes in. In your WordPress theme’s header file add the following lines before the first stylesheet is linked (ie before the first <link rel=”stylesheet”…):

<?php global $is_bb; if($is_bb) : ?>
	<link rel="stylesheet" href="[path to bbPress theme stylesheet]" type="text/css" media="screen" />
	//add additional stylesheets if needed
<?php endif; ?>

Make sure to replace [path to bbPress theme stylesheet] with the path to your current bbPress theme’s stylesheet.

If you look at your forum now, you’ll probably see a terrible mess. This is because your WordPress style sheets and your bbPress style sheets conflict. If you didn’t use the default theme you’re on your own for altering your bbPress stylesheet. Make sure you remove any elements that are directly conflicting with those in your WordPress theme (ie header, sidebar, footer elements). You’ll also want to look out for any position, and float attributes. You may also need to remove the width attribute for your forum body.

If you did use the default theme or the blue version of the default theme, you can use the stylesheets that I’ve already altered. I don’t promise that they are bug free, but they’re working well for me so far.

Kakumei
Kakumei Blue

Make sure to rename them to style.css.

Now that you’ve altered your stylesheet, everything should look good. You arn’t done yet, however. Most likely all of your bbPress navigation (ie login, admin panel, logout) buttons are gone. If you correctly integrated WordPress cookies login and logout shouldn’t be a problem. To replace any links that were lost, code them directly into your WordPress theme, using the $is_bb variable to only display them on the forum.

Good Luck!

Update:

There is an issue with slashes being added to edited posts in bbpress. I think this is being caused by both wordpress and bbpress escaping content and then only bbpress unescaping it. In any case this is how I fixed it (its a bit of a hack) in bbpress 1.0.2:

  • You’ll need to edit the file bb-includes/functions.bb-template.php (I think in earlier versions its called template-functions.php).
  • Locate the function definition get_post_text. In bbpress 1.0.2 it looks like this:
    function get_post_text( $post_id = 0 ) {
    	$bb_post = bb_get_post( get_post_id( $post_id ) );
    	return apply_filters( 'get_post_text', $bb_post->post_text, $bb_post->post_id );
    }
    
  • Change it to:
    function get_post_text( $post_id = 0 ) {
    	$bb_post = bb_get_post( get_post_id( $post_id ) );
    	return stripslashes(apply_filters( 'get_post_text', $bb_post->post_text, $bb_post->post_id ));
    }
    

I’ve also heard of an alternative solution. All you need to do is comment out the following line in wp-settings.php:

$_POST   = add_magic_quotes($_POST  );
In wordpress 2.9.2 it is on line 632. I personally have not tried this solution and I'm a little weary of it; it might have some unexpected side effects (namely POST data not being escaped, possibly exposing you to SQL injections).

If anyone has a solution that does not involve editing core files I would be very interested in hearing about it.

Feedback

After the release of SimpleMail I immediately experienced a problem that I imagine is shared by many developers: lack of feedback. Though I greatly appreciate all of the comments, suggestions, and bug reports (especially the bug reports) I know that for every one person that experienced a problem and reported it, five people experienced a problem, uninstalled the plugin and never thought about it again.

I found myself constantly worried about the bug reports I was not receiving, and in fact there were bugs that had existed since the original version that went unreported until recently. This was a learning experience of course and I have since taken steps to ensure that any application I release in the future is more robust. In addition to this I think that having experienced all of this I am must more likely to report issues I am having with any piece of software. I strongly encourage anyone reading this to do the same.

As I mentioned this was a learning experience, so I’ll offer some tips to developers so they don’t make the same mistakes I did:

  • Test your applications in multiple environments
  • Maintain portability in your code
    • Read the documentation for whatever feature, function or library you are using to ensure that it will work on whatever platform you expect it to
    • Don’t use language features that are not necessarily enabled or available to all users (ie PHP short tags)
  • Make providing feedback easy
    • Add a link, button, or form to your application that either directs the user somewhere where they can provide feedback or allows them to send feedback from the application itself

WordPress Plugins: Using Subversion

This article is meant to supplement WordPress’ Using Subversion Guide. Whenever I mention the guide I am referring to this.

So you’ve written a WordPress plugin and its now time to upload it to the WordPress plugin repository. Your first step will be requesting that your plugin be hosted on WordPress’ Plugin Directory. Sometime later your request will be accepted (provided it doesn’t drop all of the tables in the database or something like that) and you’ll be given access to the Subversion Repository.

If this is your first time making a WordPress plugin you might have no clue what subversion is, much less how to use it. WordPress provides some good Documentation on this subject, but I think there are a few things they left out that could be useful to someone using doing this for the first time.

Reading through WordPress’ Using Subversion guide will probably give you a pretty good idea of what subversion is, but by the time they get to actually using subversion you might be a little lost. I’ll pick up at the point I think it begins to get a little fuzzy:

Task 1: Starting from scratch with your brand new plugin repository

This section begins with a short overview of what you will be doing:

  1. Check out the blank repository.
  2. Add your files to the trunk/ directory of your local copy of the repository.
  3. Check in those files back to the central repository.

Then they toss a blob of text at you.

# Create a local directory on your machine to house
# a copy of the repository.
$ mkdir my-local-dir
# Check out the repository
$ svn co http://svn.wp-plugins.org/your-plugin-name my-local-dir
> A	my-local-dir/trunk
> A	my-local-dir/branches
> A	my-local-dir/tags
> Checked out revision 11325.
# As you can see, subversion has added ( "A" for "add" )
# all of the directories from the central repository to
# your local copy.
# Copy the plugin files to the local copy.
# Put everything in the trunk/ directory for now.
$ cd my-local-dir/
my-local-dir/$ cp ~/my-plugin.php trunk/my-plugin.php
my-local-dir/$ cp ~/readme.txt trunk/readme.txt
# Let subversion know you want to add those new files
# back into the central repository.
my-local-dir/$ svn add trunk/*
> A	trunk/my-plugin.php
> A	trunk/readme.txt
# Now check in the changes back to the central repository.
# Give a message to the check in.
my-local-dir/$ svn ci -m 'Adding first version of my plugin'
> Adding	trunk/my-plugin.php
> Adding	trunk/readme.txt
> Transmitting file data .
> Committed revision 11326.
# All done!

There are a few things you should know about the commands above. To begin, these commands should be entered on a unix shell. If you are familiar with unix you already know that text following the # symbol are comments and the text following the > symbol are the shell’s response to the commands. The commands themselves are not preceded by any symbol.

Another thing you should know is that the writers assume that you already have subversion (svn) installed. If you don’t like the idea of using a command line to access and modify the repository, there are a lot of GUI programs out there. You can find a listing of third party clients on the Subversion Website From this point on, however, I (and the writers of the guide I am referring to) will assume you have access to a unix command line with subversion installed.

If you are a windows user and don’t have access to a unix shell, I suggest using cygwin. SVN is part of the cygwin package, but you must explicitly specify that it be downloaded and installed. Read the cygwin documentation for more information. To test whether or not SVN is installed, type svn help in the shell.

Now that you have access to UNIX with SVN installed you should have no trouble running the commands in the guide.

Task 2: Editing a file that is already in the repository

Once you’ve uploaded your initial version, you will almost certainly need to make changes to those files sometime in the future. The guide is pretty clear on how to do this, so I will just provide a brief summary of the commands you will use for this.

svn stat shows you a list of files that differ from those in the repository.

svn ci -m "my message" updates the files in the repository with your local copies. It does not automatically add new files or remove old files. If you have added a new file that did not exist before you will have to use the svn add command to manually add this file. Likewise you will have to remove a file manually with the svn remove command. Documentation on any command can be obtained by using the svn help [command] command, where [command] is replaced by whatever command (ie add, remove, stat) you need documentation on.

Notice that the first command issued before updating any files is cd my-local-dir. It is very important that you are in you plugin directory when using any of these commands.

Task 3: “Tagging” a new version

Tagging refers to assigning a version to your plugin. Whenever you create a new version of your plugin you will need to tag that version. As the guide mentions, you do this by using the svn cp. It is important that you use the svn cp and not the normal cp command to do this. svn cp just doesn’t copy the files, it also adds the files as you would using the add command.

It is important to note that the command svn cp trunk tags/0.1 assumes that the folder 0.1 does not exist in the tags folder. You won’t get the desired result if it already exists.

As the guide mentions, it is important that the readme.txt file in your trunk folder is updated with the proper stable tag BEFORE copying the files.

Some Important Notes

Do not add, remove, move, or copy files with the normal commands (or through a GUI). To do these things you must use the svn [command] (ie svn add, svn move).

Stick to one application for managing your repository. It is not a good idea to use one program to add and remove files and then another to attempt to update the repository.

You can use whatever editor you want to modify your files. The example in the guide is nano trunk/my-plugin.php, but you don’t have to do everything from command line. Personally I use notepad++ to make changes to my files, just refrain from doing anything other than editing from your GUI or third party app.

Core Dumps

Today I noticed that my disk space usage on my web host was much higher than what it should have been. As soon as I opened my ftp program to browse through my files I found the problem. In my home directory there were tons of core.##### files (where # is some number). Each one was roughly 45MB and in total they were eating up about 2GB of space. I don’t know why they were generated, but I do know how. Core dumps occur when some program crashes. The core files are more or less an image of what was in memory at the time of the crash. These files are generated mostly for debugging purposes and (should be) safe to delete. If you are unsure of whether or not you can delete them, try renaming them and wait to see if anything explodes.

If these files are continuously being generated, its most likely a signal that something is crashing on a regular basis, but otherwise it may just be a rare occurrence. I’ve read that these files can be caused by WordPress and Drupal so if it becomes a problem you may want to look into that.

Follow Up: MS Vs. EU

Prior to my absence (which was related to me being deathly ill for a week and then having midterms + projects for the subsequent weeks) I wrote about Microsoft’s latest EU troubles, this time relating to Internet Explorer.

In short the EU doesn’t like the fact that IE is the defualt browser on every installation of Windows. The complaint was initially submitted by Opera Software.

It seems now that the EU has decided that Microsoft must offer some other browsers along side IE as well as offer users a choice of which is to be the default. The decision isn’t final, as MS still has a chance for an appeal.

Personally I’m interested to see how Microsoft reacts to this. Ultimately the decision of which alternative browsers(s) to include may fall to the vendors, which may or may not be a good thing. All of the viable alternatives to IE are open source browsers so this decision as very strong implications or the open source community and the companies backing this software, at least for now. My only fear is that, in the case that the decision of which to incorporate falls to the vendors, is that in a few years time there will be a dozen new proprietary browsers generated by the vendors. There’s something unsettling to me about a Dell browsers pre-installed on thousands of computers.

Of course I’m in the US so I won’t be able to witness the effects of this first-hand.

EU wants MS to take IE out of Windows

Word is getting around the the EU anti-trust agency is once again taking a stance against Microsoft. This time the target is Internet Explorer. The EU claims that IE is protected from competition by being bundled with Windows.

BBC Coverage

My thoughts:

IE is by far the dominate browser when it comes to number of users. It is the definition ubiquitous. At this same time it is easily the most critisized browser, even with respect to its market share. It seems to me that these two things should not go together. Microsoft has maintained this lead not through the quality of its software but by the precident of its use.

Personally my browser of choice is Opera, the developers of which were the ones to file the initial complaint that triggered the EU’s response. I do, however, still have IE and occasionally use it when it is necessary. This is probably the case with the majority of us who prefer an alternative to IE. So many sites and apps are coded with IE in mind, that giving up on IE entirely is all but impossible. Instead of being coded to the standards these sites are designed to work with IE, even if that means the function poorly or not at all in other browsers. Does this mean that it is impossible to code an application that works in all of the major browsers? Not at all. You can’t blame Microsoft for lazy developers, but you can blame them for not complying with standards. You may be wondering “If Microsoft is to blame for their lack of standards compliance, and that lack of compliance makes it harder to code apps that work in all browsers, isn’t Microsoft to blame for the lack of apps that work in all browsers?”. In my opinion the answer is no. If developers don’t like having to tweak their code to work with IE then don’t. Just make sure it works in Firefox, Opera, Safari, Chrome, or whatever browser you crazy Linux people are using today, and then stick a link on your footer that says “Best viewed in ANYTHING BUT Internet Explorer” and goes to a list of alternative browsers. If this became common practice IE would be up to standards by now.

That beings said, what about the EU and their stance against Microsoft? Should Microsoft have to remove IE from their operating system? In my opinion the answer is it doesn’t matter. The first thing I do when I install a fresh copy of Windows is go to Opera.com, download the browser, and stop using IE from that point on. Clearly, however, this is not the case with the majority of users today. Why? Some of us might think its because people are sheep who don’t know any better and in that case need the EU’s protection. Others would say that it is because IE isn’t that bad and switching to an unfamiliar browser isn’t worth it. I think the answer is that it works. IE works. It works not because Microsoft makes it works. It works because we make it work. We being developers who are willing to bend over backward just so their site looks pristine in IE. For this reason, even if the EU forces Microsoft to offer a version of Windows not bundled with IE, the majority of users will opt to have the version with IE. Even those that don’t will at some point download it because they ran into a site that is coded to not allow users with alternative browsers to view their content.

My point is: Don’t count on the EU to fix all of the problems you have with IE. If you are a developer who is afraid to publish a site that is compliant  to the standards, looks good in all of the alternative browsers, but for whatever reason isn’t quite right in IE then you are to blame. Stop worrying about your adsense revenue (you don’t make that much anyways :P ) and realize that if you act like sheep then Microsoft has no problem herding you. Worse yet, if you are a developer who prevents users who are not using IE from view their site, or happily notifies its users that “this site is bested viewed in Internet Explorer” then you should know that you embody all that is wrong with the world today.

Failure to launch…

If you haven’t heard about Windows 7 yet it is time to take note. 7 is the next iteration of windows and it appears that, unlike vista, its going to be a worthy replacement for XP. Those of you who have had to down(up?)grade from vista to xp are probably skeptical, but personally, from what I’ve read I think its going to be the next XP (in the sense that it will be a success, not the sense that it will be around for a decade before something better comes along… I hope).

You don’t have to take my word for it though. So long as you sign up before January 24th (exactly 2,647 days since the release of XP) you can try out the beta of Microsoft’s next OS:

Windows 7 Beta Information and Download

Be Warned! You’ll read on the website that it is not such a great idea to install 7 on your primary machine. I brushed off this warning without much thought and happily decided to install 7 alongside XP. And so begins the (notso) epic tale of how my Windows 7 beta test failed to get off the ground…

Downloading the installation DVD took me just over an hour, which for me is not bad for 2-3.5 GB depending on which flavor of 7 you decide to download. As soon as the dvd was done burning I quickly made a roughly 40GB primary NTFS partition on my hard drive and launched the installer. Unlike XP, which requires you to install by booting from cd (ie furiously tapping F8), 7 is smart enough to begin the install from XP while you sit back and enjoy the progress bar. Law and Order happened to be on TV at the time (There’s a 23/24 chance of that occuring as you are aware if you have basic cable) so I left the room.

A while later my progress-bar-nearly-full sense kicked in and I sprinted into my room to check the install. I caught the computer in the middle of a reboot. After the (new and shiny) load screen every step except was complete except for the very vauge “Completing Install…” step. I sat and watched the trailing dots come and go (. .. … .) until yet another reboot. Thinking its competely done now I watched the boot manager flash by, displaying “Windows 7″ and “Earlier version of Windows”. It defaulted to windows 7 and the low res but still new and shiny background appeared. Distracted, it took me a moment to notice the text “Installation was not successful”.

After this I made my critical error. I rebooted into XP and formatted my testing partition, then rebooted to try another install. If you haven’t realized I missed a step you will soon. After the install (and more Law and Order) I recieve the same message. This is, however, not the problem. Another reboot reveals the options “Earlier version of Windows” , “Windows 7″ , and… “Windows 7″. Thinking Oops I try to boot back into XP (forgetting that Vista and 7 don’t use the boot.ini) to fix the problem. This usually takes about 45 seconds. Three minutes later the screen was still black and I was thinking about the warning on the download page:

“Don’t install the Beta on your primary home or work computer. Microsoft is not responsible for downtime stemming from the Windows 7 Beta.”

A full day of debugging later I managed to get back into XP (thank you bcdedit).

That’s my story. For those of you who still want to do a side by side install here’s a link to a guide on how to do it:
You’ve been warned.
My old laptop is most likely going to be my new test subject. I’ll write again when I have have some first hand experience to share.