Getting Started With BackPress

This summer I took the opportunity to write my first BackPress application.  It was an educational experience that came with a number of surprises. I thought I would share my experience with you, along with some tips to get you out of the gates with a BackPress project of your own.

My Project

In 2008, the comedic duo Rhett and Link created a YouTube contest called SuperNote. I created a PHP app to support this project. It created its own user database, collected videos from YouTube via the API and allowed users to login to and review the video and record, among other things, how long the video’s creator was able to hold a vocal note without interruption. It also allowed different levels of user interaction with different fields visible for each user role.  Everything about this project was written from scratch, with the exception of using WordPress 2.6’s wp-db.php for database access.  It worked alright. I used sessions for logging in and that was always somewhat flakey.

In 2010, the guys decided this project would be a bi-annual event. Since we would roll out this code every two years, it was worth an investment in its stability.  Enter BackPress,  stage right.  Because the code in BackPress makes up the core of projects such as BuddyPress and in some ways WordPress itself, I knew it would have undergone much more rigorous testing than my own home brewed code had.

Additionally the project was expanding in scope.  We wanted to have the project integrated the WordPress blog, which was in turn integrated with Ning and the same password could be used on each.  A requirement was that only active members of the community could have access to the tool and that this access was granted or denied via the WordPress user interface.

 

What BackPress IS and what it ISN’T.

When I started this project, I was thinking of BackPress as a very small white labeled WordPress.  I expected that I could put BackPress on a website and it would do SOMETHING. I wasn’t expecting anything pretty, but I was expecting to at least be able to visit the site and get a mostly blank “Hello World” screen created by BackPress.  I expected to be able to login and maybe see a profile page with my login info and nothing more.

I was expecting WAAAAAAAY too much.

Here is what the BackPress.org website says:

BackPress is a PHP library of core functionality for web applications. It grew out of the immensely popular WordPress project, and is also the core of the bbPress and GlotPress sister-projects.

It includes a variety of the foundations you need to build robust, scalable web applications including (amongst other things):

  • Logging,
  • User Roles and Capabilities (Permission systems),
  • Database connections (across multiple servers and multiple datacenters),
  • HTTP Transactions,
  • XML-RPC Server and Client,
  • Object caching,
  • Formatting,
  • XSS and SQL injection protection, including a variety of powerful escaping functions,
  • Taxonomies and
  • Options management

And the best part? It’s all licensed under a generous GPL2 license, so you can use it in your own free or commercial projects.

That is all completely true, but the word that should be underscored, bolded and blink tagged is “LIBRARY”. (Ok so I couldn’t bring myself to <blink> it…).

You need to think of BackPress like a C library.  You won’t have a working program of any kind until you write it.  In BackPress, there is no UI for any of the code.  If you want to have your users login, you need to write that.  If you want to actually display something to the screen via index.php, you have to build it and integrate the parts of BackPress you need.  BackPress does EVERYTHING listed on the .org site, but only provides the frameworks.

One of the things that surprised me the most was the basic nature of both the Option and Role management APIs.  For example, you can set options, retrieve options and all of that across a single WordPress “session” or visit.  It all works great – but if you want the values to be persistent and the options to be available the next time the site is visited, you will need to include a storage mechanism.  You could use a database or memcache or flat files, but without connecting your options and roles system to SOMETHING, everything you set goes away.

Plan Ahead

Because I’d written a large amount of my project in 2008, I was able to do a conversion to BackPress in one all night coding session and other than the surprise of no persistent storage of options, it all worked.  However, you should plan on doing a full UX design and data structure design for your project.

You should have answers to the following – not necessarily in any order:

  • Are you creating a single use project or do you need to consider other installations?  This will help you decide whether or not you need routines to create the database tables and default options, or if you want to hand create them and just have your BackPress site use them.
  • Do you need to store options? How will you store them?
  • Do you need to check user roles and if so what do you want them to be? Where/how will you store them?
  • If you are connecting with WordPress, will your tables, used to store options, users and etc, be located in the same WordPress database? If so, will your tables have a unique prefix or will you use pre-existing WordPress tables? Or if not will you access your tables from your own database?  Where will the database access information be stored?
  • Do you need to provide profile editing?
  • Do you need a link to login from the home page? Or do you want to only display a login prompt only when the user is not logged in?
  • Do you need a log out link?
  • Do you need a UI to allow administration of the site itself?  Do you have a role for that?
  • etc etc etc

How to get started

The best thing that you can do to get started is to look at an existing project.  There aren’t a lot of them out there.  Because so much of the code is custom purposed, not everyone thinks their code is ready to be shared.  Additionally, you want to protect the client’s IP and still release a working project. Since I’ve not yet shared the SuperNote code, I’m going to give you the link that I found that provided the most useful launch point.  

SupportPress: https://supportpress.svn.wordpress.org/trunk/

Browsing the code of SupportPress, I was finally able to realize what BackPress was and what it wasn’t.  SupportPress is a neat project that has only been released via SVN (and maybe even that much of a release is Google’s fault as I only found reference to it in search results.).  I don’t think it is yet code complete, but it has all the basic functionality you would need and can help guide you as to what you will need to create.  It also contains code from BuddyPress (which also can be examined for how BuddyPress used BackPress) and you may not want to use the same solutions that SupportPress chose.  So I would advise using it as a guide only.

When I release the source code for the SuperNote Review Tool (Hmmm “SNoRT” I like it!!!!) I will include a link here:

I hope this helps.  I’ll do my best to answer any questions raised in the comments.  Also if there is interest I’ll create some posts with code examples from my project.  It’s been a few months since it was written and it is all getting to be a bit fuzzy in my memory. So, if you want more articles on the subject, let me know soon!

3 Comments

Add a Comment

Your email address will not be published. Required fields are marked *