• Stay in touch. Sign up for the 9seeds newsletter.
  • Inserting yourself as admin into WordPress

    On quite a few occasions I’ve had clients send me a complete backup of their site during the discovery period. Usually this is because they don’t have a Release Candidate / Quality Assurance / Staging / Development version(s) of their site where changes can be made, and approved, without affecting the live site.

    Without standing on my soapbox too long – if your website lacks a staging site, version control for custom code, or backups – you should address them immediately.

    In this case, I was glad the client had at least one backup (the one that was provided to me) which I could turn into a local WordPress installation to begin development. Since the client didn’t provide a WordPress Admin user and password, I just decided to insert myself into WordPress.
    [Read more...]

    Moving forums from SimplePress to BBPress

    I was recently asked by a member of our local WordPress meetup group which forum software I would suggest using. I mentioned that I had been using SimplePress for a while, but wasn’t in love with it. I had used BBPress quite a while ago, before it got the major revamp and if I had to choose which to use for a new site, I would go with BBPress. Then, with a stroke of great timing, the BBPress 2.3 beta was released the following day. Since it was fresh in my mind, I installed the beta to test it out. In short, BBPress has come a LONG way in the past year. So much so that we decided it was time to move our support forums off of SimplePress. That process would prove to be tricky.

    To follow are the steps I took to convert our forums from SimplePress version 4.4.0 to BBPress version 2.3

    Step 0

    Backup All The Things

    Seriously. Just do it.

    I went one step further than just backing everything up. Instead, I exported the database and set up a separate WordPress install just to run the conversion. This way, if everything broke I could simple delete it and start again. And now the actual conversion process.

    Step 1: Upgrade SimplePress

    When figuring out what it would take to do the conversion, I found that BBPress could convert SimplePress version 5 forums right from the tools menu. So in order to do the conversion, I first needed to upgrade SimplePress. Unfortunately, their upgrade only works with version 4.5.x. After reading this page, I took these steps:

    - Deactivate the SimplePress plugin (Do Not uninstall it, just deactivate it)
    - Remove the /plugins/simple-forum/ folder from your server
    - Download the latest version of SimplePress
    - Upload simple-press folder to /plugins/simple-press/ on your server
    - Activate the plugin

    Once the plugin is activated, you’ll have the “Forums” item added back to your menu which will link you to an upgrade process. Start the upgrade process and let it run. For our small forum this process took 3-4 minutes. I’m assuming for a larger forum, this process could take a bit longer. Be patient.

    After I ran the update, poking around the forums admin area, everything looked fine. I then checked the actual forums and found this message:

    SP error

    I was concerned that I had lost all my data, but the forum stats displaying below gave me some comfort.

    Forum Stats

     

    Step 2: Install BBPress

    Not wanting BBPress and SimplePress to colide, I started by deactivating SimplePress. I then uploaded the BBPress 2.3 beta to /plugins/bbpress/ and activated it from the plugins menu.

    Yeah, that part was pretty simple.

    Step 3: Import SimplePress forums

    Just a quick note. At the time of this writing BBPress 2.3 beta 2 has a bug related to importing of data. I posted a ticket about it in Trac and I’m sure it will be fixed soon. To get around the bug, I ran a search and replace on the database to remove any instance of   as it causes the post to be truncated upon import.

    Start by going to Tools -> Forums in the WordPress admin area, then click the Import Forums tab at the top. From the dropdown select SimplePress 5 and then fill in the database information. Just under that you’ll see a few options. The most important of which is the Convert Users option.

    The first time I ran the import, I was installing BBPress on the same WordPress installation that SimplePress had previously been installed on. This meant that all my user accounts already existed and their posts were all connected to them. I clicked the convert users tab prior to running the import, and all the posts, once converted, were once again attached to their rightful owners as part of BBPress.

    I then decided that I wanted to move my forum to a different WordPress install on a different domain. When doing so, I accidentally forgot to click the Convert Users checkbox. The results were less than optimal. All of the posts DID come over to the new installation, but they were all attached to a single user account. Oops.

    I can’t think of a reason (although, I’m sure there is one or this wouldn’t be an option) why you would ever want to NOT click the Convert Users checkbox. So before you click Start, make sure it’s checked.

    Step 4: Repair Forums

    After running the conversion in step 3, I was reviewing the forums and noticed that all the data appeared to be in place and the posts were all attached to the proper people, but, all of the counts were off. Anywhere where it said how many posts or replies were on a post or topic was all displaying zero. Back to the admin area we go. This time to Tools -> Forums and click the Repair Forums tab where you will find the following options:

    Repair Forums

    Taking the advice along the top, I clicked the first item in the list and then clicked Repair Items. It took a matter of seconds to complete. I then went through each item on the list, one at a time, and checked the box and ran the repair. When I was done I went back to the forums to find that all the counts had been updated and my forums were working perfectly.

    Once you know all the pieces, the process isn’t actually all that difficult. But hopefully I just saved you some trial and error time.

    Done Done. (as Chris Lema would say)

     

    Including templates inside a plugin

    This past week I was working on a project for a client who needed a custom post type to manage events on his site. Normally for a project like this I would build the CPTs and push a couple templates in to the active theme folder. But in this instance, the client was working on a new theme that would be going live in a few weeks. Rather than making the client jump through hoops and move template files around, I wanted to provide the easiest solution possible. That meant, including all the templates as part of the plugin. Thanks to a very handy filter in WordPress, this wasn’t a problem. Here’s how it ended up.

    Here’s the makeup of the plugin:

    Plugin Layout

    The plugin itself is very standard. One thing I like to do is define the custom post types as separate files to keep the function file clean. I then include the CPTs and the custom metabox library like so:

    /** Add custom CPTs and Metaboxes */
    require_once( 'cpt-events.php' );
    require_once( 'cpt-locations.php' );
    require_once( 'metabox/init.php' );

    I store the stylesheet in a separate folder for cleanliness as well and encode it like this:

    /** Enqueue CSS */
    add_action( 'wp_enqueue_scripts', 'prefix_add_my_stylesheet' );
     
    function prefix_add_my_stylesheet() {
    	wp_register_style( 'cpt-style', plugins_url( 'css/style.css', __FILE__) );
    	wp_enqueue_style( 'cpt-style' );
    }

    And now the real meat of it. You can see the single-events.php and archive-events.php that make up the two template files I want to use on the front end. What I’m going to do is create a function that tells WordPress to use my templates for the archive and single pages for the event CPT. That code looks like this:

    // force use of templates from plugin folder
    function cpte_force_template( $template )
    {	
        if( is_archive( 'events' ) ) {
            $template = WP_PLUGIN_DIR .'/'. plugin_basename( dirname(__FILE__) ) .'/archive-events.php';
    	}
     
    	if( is_singular( 'events' ) ) {
            $template = WP_PLUGIN_DIR .'/'. plugin_basename( dirname(__FILE__) ) .'/single-events.php';
    	}
     
        return $template;
    }
    add_filter( 'template_include', 'cpte_force_template' );

    As you can see, I’ve set up a filter for template_include. I pass in the $template variable and check to see if the page is either an archive or singular event. If so, I override the default template location with the full path and file name of the file inside my plugin folder.

    The end result is a fully encapsulated plugin that takes care of the functionality, templates and stylesheet formatting the client requested all in one easy to manage package. Simply install the plugin and activate it and you’re ready to go!

    Stealing math from Wikipedia

    WordPress + Jetpack + LaTeX = Awesome

    On my personal WordPress website I wrote about an Arduino device I built to help brew beer.  Being my first foray into electronics, I wanted to document my experiences.  One of my difficulties centered around turning electrical values (voltage, resistance) into real-world values (temperature) using math.

    As part of my documentation, I wanted to re-create some equations that I had found on a Wikipedia page about thermistors.  While in the process of grabbing their images and putting them into the media library, I remembered something…

    One time while on the main Jetpack screen in the WordPress dashboard, I noticed a tile that advertised “Beautiful Math.”  So I looked into it.  Jetpack has a LaTeX module that can accomplish this.  LaTeX is a rather old-school markup/typesetting language that has been very popular in academia, especially in regards to math.

    So Jetpack and LaTeX can do math, but I didn’t really want to learn a new markup language, I just wanted to quickly copy & paste the equations into my post.

    Good Authors Borrow, Great Authors Steal

    So then I wondered how Wikipedia is storing the images or if they’re doing something similar.  Guess what?!?  They use LaTeX too!  Putting the same equation into WordPress is as easy as clicking “Edit” on the Wikipedia page and copying the text between <math> and </math> and pasting it in-between [latex] and [/latex] in WordPress.

    Native vs. Shortcode formatting Tricks

    Jetpack supports using the $latex $ native format instead of the shortcode, but there are a few noted (and undocumented) differences between using the two methods. For instance, if you want to increase the size of your rendered LaTeX text, you can use the s (size) parameter in your LaTeX equation as such:

    $latex \LaTeX&s=4$

    Where size in this example is “4.”  However if you try to do this using the shortcode as such:

    [latex] \LaTeX&s=4[/latex]

    it will render as:  \LaTeX&s=4 – Not exactly what you’d expect :( The trick is that the following LaTeX parameters need to be fed in as shortcode parameters:

    So if you want to have “LaTeX” rendered as:

    \LaTeX

    You can either do:

    $latex \LaTeX&bg=ffcccc&fg=cc00ff&s=4$

    or  move the size & color parameters into the shortcode tag like this:

    [latex bg=ffcccc fg=cc00ff s=4]\LaTeX[/latex]

    Some handy tools from the Community Summit

    A few weeks back I had the great privilege of attending the WordPress Community Summit. Rather than renting a hotel room by myself, instead I rented a house with 4 other Community Summit attendees; Ryan Imel, Brad Williams, Brandon Dove and Dre Armeda. Not exactly bad company to keep. We figured staying in the same house would help keep costs down and would also be a lot of fun. What we hadn’t really planned on was some of the great knowledge sharing that took place.

    One afternoon while we were hanging out in the house, we started talking about some of the handy tools we all use. As the conversation went on, Ryan had the quick sense to open up a Google doc and start taking notes. Below is the list of handy tools we came up with.

    Keep in mind, these lists are definitely not all inclusive. We know there are many other text editors and cool apps out there. But these are the ones that are top of mind that day.

    Text editors

    Mac Apps

    • Alfred – Easily launch applications, sites and perform several other tricks
    • CoBook – Amazingly easy and simple CRM tool
    • Spirited Away – Hides apps after a set amount of idle time
    • Hazel – Simple automation tool for dealing with files
    • Total Terminal – Formally called Visor, a system wide hotkey for terminal
    • Droplr – Easy screenshot/text file uploader for sharing
    • TypeIt4Me – Text expander

    Custom Searches for Alfred

    • http://wordpress.org/extend/plugins/search.php?q={query}
      Search the WordPress plugin repo
    • http://wordpress.org/search/_Reference+{query}
      Search wordpress.org for functions, actions, filters, etc
    • http://demo.studiopress.com/{query}
      Quickly load any StudioPress theme demo site

    If you’ve got another tool to add to the list, drop it in the comments.